mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(app): restructure app component to separate modules, move from enum to constants
restructure app component to separate modules, move from enum to constants
This commit is contained in:
4
src/components/app/app-constants.ts
Normal file
4
src/components/app/app-constants.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const PORTAL_DEFAULT = 1;
|
||||
export const PORTAL_MODAL = 2;
|
||||
export const PORTAL_LOADING = 3;
|
||||
export const PORTAL_TOAST = 4;
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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<any> {
|
||||
present(enteringView: ViewController, opts: NavOptions, appPortal?: number): Promise<any> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user