From 6d787553a39993fd6ee186d7fb4852269b2d7f26 Mon Sep 17 00:00:00 2001 From: Dan Bucholtz Date: Thu, 2 Mar 2017 14:43:46 -0600 Subject: [PATCH] refactor(app): restructure app component to separate modules, move from enum to constants restructure app component to separate modules, move from enum to constants --- src/components/app/app-constants.ts | 4 ++++ src/components/app/app-root.ts | 19 ++++++++----------- src/components/app/app.ts | 20 +++++++++++++------- 3 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 src/components/app/app-constants.ts diff --git a/src/components/app/app-constants.ts b/src/components/app/app-constants.ts new file mode 100644 index 0000000000..17b552f3c4 --- /dev/null +++ b/src/components/app/app-constants.ts @@ -0,0 +1,4 @@ +export const PORTAL_DEFAULT = 1; +export const PORTAL_MODAL = 2; +export const PORTAL_LOADING = 3; +export const PORTAL_TOAST = 4; diff --git a/src/components/app/app-root.ts b/src/components/app/app-root.ts index 18c2de899c..1cc152f1e5 100644 --- a/src/components/app/app-root.ts +++ b/src/components/app/app-root.ts @@ -6,6 +6,7 @@ import { Config } from '../../config/config'; import { Ion } from '../ion'; import { OverlayPortal } from '../nav/overlay-portal'; import { Platform } from '../../platform/platform'; +import * as Constants from './app-constants'; export const AppRootToken = new OpaqueToken('USERROOT'); @@ -89,16 +90,19 @@ export class IonicApp extends Ion implements OnInit { this._plt.prepareReady(); } - _getPortal(portal?: AppPortal): OverlayPortal { - if (portal === AppPortal.LOADING) { + /** + * @private + */ + _getPortal(portal?: number): OverlayPortal { + if (portal === Constants.PORTAL_LOADING) { return this._loadingPortal; } - if (portal === AppPortal.TOAST) { + if (portal === Constants.PORTAL_TOAST) { return this._toastPortal; } // Modals need their own overlay becuase we don't want an ActionSheet // or Alert to trigger lifecycle events inside a modal - if (portal === AppPortal.MODAL) { + if (portal === Constants.PORTAL_MODAL) { return this._modalPortal; } return this._overlayPortal; @@ -162,10 +166,3 @@ export class IonicApp extends Ion implements OnInit { } } - -export const enum AppPortal { - DEFAULT, - MODAL, - LOADING, - TOAST -}; diff --git a/src/components/app/app.ts b/src/components/app/app.ts index 90a3332ec1..11dbc8be28 100644 --- a/src/components/app/app.ts +++ b/src/components/app/app.ts @@ -1,15 +1,19 @@ import { EventEmitter, Injectable, Optional } from '@angular/core'; import { Title } from '@angular/platform-browser'; -import { AppPortal, IonicApp } from './app-root'; +import { IonicApp } from './app-root'; +import * as Constants from './app-constants'; import { ClickBlock } from '../../util/click-block'; import { runInDev } from '../../util/util'; import { Config } from '../../config/config'; import { isNav, NavOptions, DIRECTION_FORWARD, DIRECTION_BACK } from '../../navigation/nav-util'; +import { MenuController } from '../menu/menu-controller'; import { NavController } from '../../navigation/nav-controller'; import { Platform } from '../../platform/platform'; import { ViewController } from '../../navigation/view-controller'; -import { MenuController } from '../menu/menu-controller'; +import { IOSTransition } from '../../transitions/transition-ios'; +import { MDTransition } from '../../transitions/transition-md'; +import { WPTransition } from '../../transitions/transition-wp'; /** @@ -93,6 +97,10 @@ export class App { }; } }); + + _config.setTransition('ios-transition', IOSTransition); + _config.setTransition('md-transition', MDTransition); + _config.setTransition('wp-transition', WPTransition); } /** @@ -192,7 +200,7 @@ export class App { * @return {NavController} Returns the active NavController. Using this method is preferred when we need access to the top-level navigation controller while on the outside views and handlers like `registerBackButtonAction()` */ getActiveNav(): NavController { - const portal = this._appRoot._getPortal(MODAL); + const portal = this._appRoot._getPortal(Constants.PORTAL_MODAL); if (portal.length() > 0) { return findTopNav(portal); } @@ -216,7 +224,7 @@ export class App { /** * @private */ - present(enteringView: ViewController, opts: NavOptions, appPortal?: AppPortal): Promise { + present(enteringView: ViewController, opts: NavOptions, appPortal?: number): Promise { const portal = this._appRoot._getPortal(appPortal); enteringView._setNav(portal); @@ -267,7 +275,7 @@ export class App { } // If there are any alert/actionsheet open, let's do nothing - const portal = this._appRoot._getPortal(DEFAULT); + const portal = this._appRoot._getPortal(Constants.PORTAL_DEFAULT); if (portal.length() > 0) { return Promise.resolve(); } @@ -309,7 +317,5 @@ function findTopNav(nav: NavController) { return nav; } -const DEFAULT = 0; // AppPortal.DEFAULT -const MODAL = 1; // AppPortal.MODAL const ACTIVE_SCROLLING_TIME = 100; const CLICK_BLOCK_BUFFER_IN_MILLIS = 64;