mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 22:17:40 +08:00
@ -178,7 +178,7 @@ export class IonicApp extends Ion implements OnInit {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AppPortal {
|
export const enum AppPortal {
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
MODAL,
|
MODAL,
|
||||||
LOADING,
|
LOADING,
|
||||||
|
@ -5,12 +5,13 @@ import { AppPortal, IonicApp } from './app-root';
|
|||||||
import { ClickBlock } from '../../util/click-block';
|
import { ClickBlock } from '../../util/click-block';
|
||||||
import { runInDev } from '../../util/util';
|
import { runInDev } from '../../util/util';
|
||||||
import { Config } from '../../config/config';
|
import { Config } from '../../config/config';
|
||||||
import { isNav, isTabs, NavOptions, DIRECTION_FORWARD, DIRECTION_BACK } from '../../navigation/nav-util';
|
import { isNav, NavOptions, DIRECTION_FORWARD, DIRECTION_BACK } from '../../navigation/nav-util';
|
||||||
import { NavController } from '../../navigation/nav-controller';
|
import { NavController } from '../../navigation/nav-controller';
|
||||||
import { Platform } from '../../platform/platform';
|
import { Platform } from '../../platform/platform';
|
||||||
import { ViewController } from '../../navigation/view-controller';
|
import { ViewController } from '../../navigation/view-controller';
|
||||||
import { MenuController } from '../menu/menu-controller';
|
import { MenuController } from '../menu/menu-controller';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name App
|
* @name App
|
||||||
* @description
|
* @description
|
||||||
@ -181,18 +182,11 @@ export class App {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
getActiveNav(): NavController {
|
getActiveNav(): NavController {
|
||||||
var nav = this._rootNav || null;
|
const portal = this._appRoot._getPortal(MODAL);
|
||||||
var activeChildNav: any;
|
if (portal.length() > 0) {
|
||||||
|
return findTopNav(portal);
|
||||||
while (nav) {
|
|
||||||
activeChildNav = nav.getActiveChildNav();
|
|
||||||
if (!activeChildNav) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
nav = activeChildNav;
|
return findTopNav(this._rootNav || null);
|
||||||
}
|
|
||||||
|
|
||||||
return nav;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,47 +253,50 @@ export class App {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// function used to climb up all parent nav controllers
|
// If there are any alert/actionsheet open, let's do nothing
|
||||||
function navPop(nav: any): Promise<any> {
|
const portal = this._appRoot._getPortal(DEFAULT);
|
||||||
if (nav) {
|
if (portal.length() > 0) {
|
||||||
if (isTabs(nav)) {
|
return Promise.resolve();
|
||||||
// FYI, using "nav instanceof Tabs" throws a Promise runtime error for whatever reason, idk
|
}
|
||||||
// on tabs, we do nothing. see issue #7611
|
// next get the active nav, check itself and climb up all
|
||||||
|
// of its parent navs until it finds a nav that can pop
|
||||||
|
return recursivePop(this.getActiveNav());
|
||||||
|
}
|
||||||
|
|
||||||
} else if (isNav(nav) && nav.length() > 1) {
|
}
|
||||||
|
|
||||||
|
function recursivePop(nav: any): Promise<any> {
|
||||||
|
if (!nav) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isNav(nav)) {
|
||||||
|
var len = nav.length();
|
||||||
|
if (len > 1 || (nav._isPortal && len > 0)) {
|
||||||
// this nav controller has more than one view
|
// this nav controller has more than one view
|
||||||
// pop the current view on this nav and we're done here
|
// pop the current view on this nav and we're done here
|
||||||
console.debug('app, goBack pop nav');
|
console.debug('app, goBack pop nav');
|
||||||
return nav.pop();
|
return nav.pop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// try again using the parent nav (if there is one)
|
// try again using the parent nav (if there is one)
|
||||||
return navPop(nav.parent);
|
return recursivePop(nav.parent);
|
||||||
}
|
|
||||||
|
|
||||||
// nerp, never found nav that could pop off a view
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// app must be enabled and there must be a
|
|
||||||
// root nav controller for go back to work
|
|
||||||
const portal = this._appRoot._getActivePortal();
|
|
||||||
|
|
||||||
// first check if the root navigation has any overlays
|
|
||||||
// opened in it's portal, like alert/actionsheet/popup/modals
|
|
||||||
if (portal) {
|
|
||||||
// there is an overlay view in the portal
|
|
||||||
// let's pop this one off to go back
|
|
||||||
console.debug('app, goBack pop overlay');
|
|
||||||
return portal.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
// next get the active nav, check itself and climb up all
|
|
||||||
// of its parent navs until it finds a nav that can pop
|
|
||||||
return navPop(this.getActiveNav());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findTopNav(nav: NavController) {
|
||||||
|
var activeChildNav: any;
|
||||||
|
|
||||||
|
while (nav) {
|
||||||
|
activeChildNav = nav.getActiveChildNav();
|
||||||
|
if (!activeChildNav) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nav = activeChildNav;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nav;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT = 0; // AppPortal.DEFAULT
|
||||||
|
const MODAL = 1; // AppPortal.MODAL
|
||||||
const ACTIVE_SCROLLING_TIME = 100;
|
const ACTIVE_SCROLLING_TIME = 100;
|
||||||
const CLICK_BLOCK_BUFFER_IN_MILLIS = 64;
|
const CLICK_BLOCK_BUFFER_IN_MILLIS = 64;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { App } from '../app';
|
import { App } from '../app';
|
||||||
|
import { AppPortal } from '../app-root';
|
||||||
import { Config } from '../../../config/config';
|
import { Config } from '../../../config/config';
|
||||||
import { mockApp, mockConfig, mockNavController, mockPlatform, mockTab, mockTabs, mockView, mockViews } from '../../../util/mock-providers';
|
import { mockApp, mockConfig, mockNavController, mockPlatform, mockTab, mockTabs, mockView, mockViews } from '../../../util/mock-providers';
|
||||||
import { OverlayPortal } from '../../nav/overlay-portal';
|
import { OverlayPortal } from '../../nav/overlay-portal';
|
||||||
@ -432,7 +433,7 @@ describe('App', () => {
|
|||||||
config = mockConfig();
|
config = mockConfig();
|
||||||
platform = mockPlatform();
|
platform = mockPlatform();
|
||||||
app = mockApp(config, platform);
|
app = mockApp(config, platform);
|
||||||
portal = app._appRoot._getPortal();
|
portal = app._appRoot._getPortal(AppPortal.MODAL);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user