fix(NavController): fire onPageWillUnload/DidUnload

Fixes #5507
This commit is contained in:
Adam Bradley
2016-02-18 11:05:45 -06:00
parent 7e3eb23345
commit 8f0b88b7e4
3 changed files with 45 additions and 21 deletions

View File

@ -802,6 +802,7 @@ export class NavController extends Ion {
// set that it is the init leaving view
// the first view to be removed, it should init leave
view.state = STATE_INIT_LEAVE;
view.willUnload();
// from the index of the leaving view, go backwards and
// find the first view that is inactive so it can be the entering
@ -836,7 +837,6 @@ export class NavController extends Ion {
this._views.filter(v => v.state === STATE_REMOVE).forEach(view => {
view.willLeave();
view.didLeave();
view.didUnload();
this._views.splice(this.indexOf(view), 1);
view.destroy();
});

View File

@ -271,7 +271,9 @@ class AnotherPage {
constructor(
private nav: NavController,
private viewCtrl: ViewController
) {}
) {
console.log('Page, AnotherPage, constructor', this.viewCtrl.id);
}
pushFullPage() {
this.nav.push(FullPage);
@ -304,6 +306,34 @@ class AnotherPage {
this.viewCtrl.setBackButtonText(backButtonText);
++this.bbCount;
}
onPageWillEnter() {
console.log('Page, AnotherPage, onPageWillEnter', this.viewCtrl.id);
}
onPageDidEnter() {
console.log('Page, AnotherPage, onPageDidEnter', this.viewCtrl.id);
}
onPageWillLeave() {
console.log('Page, AnotherPage, onPageWillLeave', this.viewCtrl.id);
}
onPageDidLeave() {
console.log('Page, AnotherPage, onPageDidLeave', this.viewCtrl.id);
}
onPageWillUnload() {
console.log('Page, AnotherPage, onPageWillUnload', this.viewCtrl.id);
}
onPageDidUnload() {
console.log('Page, AnotherPage, onPageDidUnload', this.viewCtrl.id);
}
ngOnDestroy() {
console.log('Page, AnotherPage, ngOnDestroy', this.viewCtrl.id);
}
}

View File

@ -183,23 +183,6 @@ export class ViewController {
return (this.index === 0);
}
/**
* @private
*/
addDestroy(destroyFn: Function) {
this._destroys.push(destroyFn);
}
/**
* @private
*/
destroy() {
for (var i = 0; i < this._destroys.length; i++) {
this._destroys[i]();
}
this._destroys = [];
}
/**
* @private
*/
@ -489,10 +472,21 @@ export class ViewController {
/**
* @private
* The view has been destroyed and its elements have been removed.
*/
didUnload() {
addDestroy(destroyFn: Function) {
this._destroys.push(destroyFn);
}
/**
* @private
*/
destroy() {
ctrlFn(this, 'onPageDidUnload');
for (var i = 0; i < this._destroys.length; i++) {
this._destroys[i]();
}
this._destroys = [];
}
}