mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00
fix(app): go back navigation can close menus
This commit is contained in:
@ -118,10 +118,6 @@ export class IonicApp extends Ion implements OnInit {
|
|||||||
_getActivePortal(): OverlayPortal {
|
_getActivePortal(): OverlayPortal {
|
||||||
const defaultPortal = this._overlayPortal;
|
const defaultPortal = this._overlayPortal;
|
||||||
const modalPortal = this._modalPortal;
|
const modalPortal = this._modalPortal;
|
||||||
|
|
||||||
assert(defaultPortal, 'default must be valid');
|
|
||||||
assert(modalPortal, 'modal must be valid');
|
|
||||||
|
|
||||||
const hasModal = modalPortal.length() > 0;
|
const hasModal = modalPortal.length() > 0;
|
||||||
const hasDefault = defaultPortal.length() > 0;
|
const hasDefault = defaultPortal.length() > 0;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { EventEmitter, Injectable } from '@angular/core';
|
import { EventEmitter, Injectable, Optional } from '@angular/core';
|
||||||
import { Title } from '@angular/platform-browser';
|
import { Title } from '@angular/platform-browser';
|
||||||
|
|
||||||
import { AppPortal, IonicApp } from './app-root';
|
import { AppPortal, IonicApp } from './app-root';
|
||||||
@ -9,7 +9,7 @@ import { isNav, isTabs, NavOptions, DIRECTION_FORWARD, DIRECTION_BACK } from '..
|
|||||||
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';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name App
|
* @name App
|
||||||
@ -67,18 +67,19 @@ export class App {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _config: Config,
|
private _config: Config,
|
||||||
private _platform: Platform
|
private _platform: Platform,
|
||||||
|
@Optional() private _menuCtrl?: MenuController
|
||||||
) {
|
) {
|
||||||
// listen for hardware back button events
|
// listen for hardware back button events
|
||||||
// register this back button action with a default priority
|
// register this back button action with a default priority
|
||||||
_platform.registerBackButtonAction(this.navPop.bind(this));
|
_platform.registerBackButtonAction(this.goBack.bind(this));
|
||||||
this._disableScrollAssist = _config.getBoolean('disableScrollAssist', false);
|
this._disableScrollAssist = _config.getBoolean('disableScrollAssist', false);
|
||||||
|
|
||||||
runInDev(() => {
|
runInDev(() => {
|
||||||
// During developement, navPop can be triggered by calling
|
// During developement, navPop can be triggered by calling
|
||||||
// window.ClickBackButton();
|
// window.ClickBackButton();
|
||||||
if (!window['HWBackButton']) {
|
if (!window['HWBackButton']) {
|
||||||
window['HWBackButton'] = this.navPop.bind(this);
|
window['HWBackButton'] = this.goBack.bind(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -233,6 +234,23 @@ export class App {
|
|||||||
return portal.insertPages(-1, [enteringView], opts);
|
return portal.insertPages(-1, [enteringView], opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goBack(): Promise<any> {
|
||||||
|
if (this._menuCtrl && this._menuCtrl.isOpen()) {
|
||||||
|
return this._menuCtrl.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
let navPromise = this.navPop();
|
||||||
|
if (navPromise === null) {
|
||||||
|
// no views to go back to
|
||||||
|
// let's exit the app
|
||||||
|
if (this._config.getBoolean('navExitApp', true)) {
|
||||||
|
console.debug('app, goBack exitApp');
|
||||||
|
this._platform.exitApp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return navPromise;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@ -275,7 +293,7 @@ export class App {
|
|||||||
const portal = this._appRoot._getActivePortal();
|
const portal = this._appRoot._getActivePortal();
|
||||||
|
|
||||||
// first check if the root navigation has any overlays
|
// first check if the root navigation has any overlays
|
||||||
// opened in it's portal, like alert/actionsheet/popup
|
// opened in it's portal, like alert/actionsheet/popup/modals
|
||||||
if (portal) {
|
if (portal) {
|
||||||
// there is an overlay view in the portal
|
// there is an overlay view in the portal
|
||||||
// let's pop this one off to go back
|
// let's pop this one off to go back
|
||||||
@ -285,17 +303,7 @@ export class App {
|
|||||||
|
|
||||||
// next get the active nav, check itself and climb up all
|
// next get the active nav, check itself and climb up all
|
||||||
// of its parent navs until it finds a nav that can pop
|
// of its parent navs until it finds a nav that can pop
|
||||||
let navPromise = navPop(this.getActiveNav());
|
return navPop(this.getActiveNav());
|
||||||
if (navPromise === null) {
|
|
||||||
// no views to go back to
|
|
||||||
// let's exit the app
|
|
||||||
if (this._config.getBoolean('navExitApp', true)) {
|
|
||||||
console.debug('app, goBack exitApp');
|
|
||||||
this._platform.exitApp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return navPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -211,12 +211,17 @@ export class MenuController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} [menuId] Optionally get the menu by its id, or side.
|
* @param {string} [menuId] Optionally get the menu by its id, or side.
|
||||||
* @return {boolean} Returns true if the menu is currently open, otherwise false.
|
* @return {boolean} Returns true if the specified menu is currently open, otherwise false.
|
||||||
|
* If the menuId is not specified, it returns true if ANY menu is currenly open.
|
||||||
*/
|
*/
|
||||||
isOpen(menuId?: string): boolean {
|
isOpen(menuId?: string): boolean {
|
||||||
let menu = this.get(menuId);
|
if (menuId) {
|
||||||
return menu && menu.isOpen || false;
|
var menu = this.get(menuId);
|
||||||
|
return menu && menu.isOpen || false;
|
||||||
|
} else {
|
||||||
|
return !!this.getOpen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,7 @@ import { DeepLinker } from '../../navigation/deep-linker';
|
|||||||
import { GestureController } from '../../gestures/gesture-controller';
|
import { GestureController } from '../../gestures/gesture-controller';
|
||||||
import { isTrueProperty } from '../../util/util';
|
import { isTrueProperty } from '../../util/util';
|
||||||
import { Keyboard } from '../../util/keyboard';
|
import { Keyboard } from '../../util/keyboard';
|
||||||
|
import { NavController } from '../../navigation/nav-controller';
|
||||||
import { NavControllerBase } from '../../navigation/nav-controller-base';
|
import { NavControllerBase } from '../../navigation/nav-controller-base';
|
||||||
import { NavOptions } from '../../navigation/nav-util';
|
import { NavOptions } from '../../navigation/nav-util';
|
||||||
import { TransitionController } from '../../transitions/transition-controller';
|
import { TransitionController } from '../../transitions/transition-controller';
|
||||||
@ -57,7 +58,7 @@ export class Nav extends NavControllerBase implements AfterViewInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Optional() viewCtrl: ViewController,
|
@Optional() viewCtrl: ViewController,
|
||||||
@Optional() parent: NavControllerBase,
|
@Optional() parent: NavController,
|
||||||
app: App,
|
app: App,
|
||||||
config: Config,
|
config: Config,
|
||||||
keyboard: Keyboard,
|
keyboard: Keyboard,
|
||||||
|
@ -25,7 +25,7 @@ import { DomController } from '../util/dom-controller';
|
|||||||
*/
|
*/
|
||||||
export class NavControllerBase extends Ion implements NavController {
|
export class NavControllerBase extends Ion implements NavController {
|
||||||
|
|
||||||
_children: any[] = [];
|
_children: NavController[] = [];
|
||||||
_ids: number = -1;
|
_ids: number = -1;
|
||||||
_init = false;
|
_init = false;
|
||||||
_isPortal: boolean;
|
_isPortal: boolean;
|
||||||
@ -883,15 +883,15 @@ export class NavControllerBase extends Ion implements NavController {
|
|||||||
this._app.viewWillUnload.emit(view);
|
this._app.viewWillUnload.emit(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveChildNav(): any {
|
getActiveChildNav(): NavController {
|
||||||
return this._children[this._children.length - 1];
|
return this._children[this._children.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
registerChildNav(nav: any) {
|
registerChildNav(nav: NavController) {
|
||||||
this._children.push(nav);
|
this._children.push(nav);
|
||||||
}
|
}
|
||||||
|
|
||||||
unregisterChildNav(nav: any) {
|
unregisterChildNav(nav: NavController) {
|
||||||
removeArrayItem(this._children, nav);
|
removeArrayItem(this._children, nav);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,4 +597,8 @@ export abstract class NavController {
|
|||||||
*/
|
*/
|
||||||
abstract canGoBack(): boolean;
|
abstract canGoBack(): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
abstract registerChildNav(nav: NavController);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user