mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00

committed by
Adam Bradley

parent
66bbd24d8d
commit
68eb1b7cb5
@ -270,7 +270,10 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
const leavingView = this.getActive();
|
||||
const enteringView = this._getEnteringView(ti, leavingView);
|
||||
|
||||
assert(leavingView || enteringView, 'both leavingView and enteringView are null');
|
||||
if (!leavingView && !enteringView) {
|
||||
ti.reject('leavingView and enteringView are null. stack is already empty');
|
||||
return false;
|
||||
}
|
||||
|
||||
// set that this nav is actively transitioning
|
||||
this.setTransitioning(true);
|
||||
@ -423,7 +426,7 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
this._zone.run(() => {
|
||||
for (i = 0; i < destroyQueue.length; i++) {
|
||||
view = destroyQueue[i];
|
||||
this._willLeave(view);
|
||||
this._willLeave(view, true);
|
||||
this._didLeave(view);
|
||||
this._willUnload(view);
|
||||
}
|
||||
@ -682,7 +685,7 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
if (enteringView || leavingView) {
|
||||
this._zone.run(() => {
|
||||
// Here, the order is important. WillLeave must called before WillEnter.
|
||||
leavingView && this._willLeave(leavingView);
|
||||
leavingView && this._willLeave(leavingView, !enteringView);
|
||||
enteringView && this._willEnter(enteringView);
|
||||
});
|
||||
}
|
||||
@ -856,11 +859,11 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
this._app.viewDidEnter.emit(view);
|
||||
}
|
||||
|
||||
_willLeave(view: ViewController) {
|
||||
_willLeave(view: ViewController, willUnload: boolean) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
assert(NgZone.isInAngularZone(), 'callback should be zoned');
|
||||
|
||||
view._willLeave();
|
||||
view._willLeave(willUnload);
|
||||
this.viewWillLeave.emit(view);
|
||||
this._app.viewWillLeave.emit(view);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ describe('ViewController', () => {
|
||||
});
|
||||
|
||||
// act
|
||||
viewController._willLeave();
|
||||
viewController._willLeave(false);
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
@ -92,6 +92,7 @@ describe('ViewController', () => {
|
||||
// arrange
|
||||
let viewController = mockView();
|
||||
let navControllerBase = mockNavController();
|
||||
navControllerBase._isPortal = true;
|
||||
mockViews(navControllerBase, [viewController]);
|
||||
|
||||
viewController.onWillDismiss((data: any) => {
|
||||
|
@ -38,6 +38,8 @@ export class ViewController {
|
||||
private _nb: Navbar;
|
||||
private _onDidDismiss: Function;
|
||||
private _onWillDismiss: Function;
|
||||
private _dismissData: any;
|
||||
private _dismissRole: any;
|
||||
private _detached: boolean;
|
||||
|
||||
/**
|
||||
@ -164,20 +166,16 @@ export class ViewController {
|
||||
* @param {any} [role ]
|
||||
* @param {NavOptions} NavOptions Options for the dismiss navigation.
|
||||
* @returns {any} data Returns the data passed in, if any.
|
||||
*
|
||||
*/
|
||||
dismiss(data?: any, role?: any, navOptions: NavOptions = {}): Promise<any> {
|
||||
if (!this._nav) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
this._dismissData = data;
|
||||
this._dismissRole = role;
|
||||
|
||||
let options = assign({}, this._leavingOpts, navOptions);
|
||||
this._onWillDismiss && this._onWillDismiss(data, role);
|
||||
return this._nav.removeView(this, options).then(() => {
|
||||
this._onDidDismiss && this._onDidDismiss(data, role);
|
||||
this._onDidDismiss = null;
|
||||
return data;
|
||||
});
|
||||
const options = assign({}, this._leavingOpts, navOptions);
|
||||
return this._nav.removeView(this, options).then(() => data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -489,9 +487,14 @@ export class ViewController {
|
||||
* @private
|
||||
* The view has is about to leave and no longer be the active view.
|
||||
*/
|
||||
_willLeave() {
|
||||
_willLeave(willUnload: boolean) {
|
||||
this.willLeave.emit(null);
|
||||
this._lifecycle('WillLeave');
|
||||
|
||||
if (willUnload && this._onWillDismiss) {
|
||||
this._onWillDismiss(this._dismissData, this._dismissRole);
|
||||
this._onWillDismiss = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -517,6 +520,11 @@ export class ViewController {
|
||||
_willUnload() {
|
||||
this.willUnload.emit(null);
|
||||
this._lifecycle('WillUnload');
|
||||
|
||||
this._onDidDismiss && this._onDidDismiss(this._dismissData, this._dismissRole);
|
||||
this._onDidDismiss = null;
|
||||
this._dismissData = null;
|
||||
this._dismissRole = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -537,7 +545,7 @@ export class ViewController {
|
||||
this._cmp.destroy();
|
||||
}
|
||||
|
||||
this._nav = this._cmp = this.instance = this._cntDir = this._cntRef = this._hdrDir = this._ftrDir = this._nb = this._onWillDismiss = null;
|
||||
this._nav = this._cmp = this.instance = this._cntDir = this._cntRef = this._hdrDir = this._ftrDir = this._nb = this._onDidDismiss = this._onWillDismiss = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user