mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-26 08:13:34 +08:00
fix(NavController): setView race condition
This commit is contained in:
@ -186,6 +186,8 @@ export class NavController extends Ion {
|
||||
|
||||
// create a new ViewController
|
||||
let enteringView = new ViewController(this, componentType, params);
|
||||
enteringView.shouldDestroy = false;
|
||||
enteringView.shouldCache = false;
|
||||
|
||||
// add the view to the stack
|
||||
this._add(enteringView);
|
||||
@ -453,6 +455,11 @@ export class NavController extends Ion {
|
||||
// wait for the new view to complete setup
|
||||
enteringView.stage(() => {
|
||||
|
||||
if (enteringView.shouldDestroy) {
|
||||
// already marked as a view that will be destroyed, don't continue
|
||||
return callback();
|
||||
}
|
||||
|
||||
this._zone.runOutsideAngular(() => {
|
||||
|
||||
enteringView.shouldDestroy = false;
|
||||
|
@ -31,7 +31,7 @@ export class ViewController {
|
||||
stage(done) {
|
||||
let navCtrl = this.navCtrl;
|
||||
|
||||
if (this.instance || !navCtrl) {
|
||||
if (this.instance || !navCtrl || this.shouldDestroy) {
|
||||
// already compiled this view
|
||||
return done();
|
||||
}
|
||||
@ -39,6 +39,8 @@ export class ViewController {
|
||||
// compile the component and create a ProtoViewRef
|
||||
navCtrl.compileView(this.componentType).then(hostProtoViewRef => {
|
||||
|
||||
if (this.shouldDestroy) return done();
|
||||
|
||||
// get the pane the NavController wants to use
|
||||
// the pane is where all this content will be placed into
|
||||
navCtrl.loadContainer(this.componentType, hostProtoViewRef, this, () => {
|
||||
@ -96,13 +98,6 @@ export class ViewController {
|
||||
}
|
||||
|
||||
this.didUnload();
|
||||
|
||||
// just to help prevent any possible memory leaks
|
||||
for (let name in this) {
|
||||
if (this.hasOwnProperty(name)) {
|
||||
this[name] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,15 +212,19 @@ export class ViewController {
|
||||
* recommended method to use when a view becomes active.
|
||||
*/
|
||||
loaded() {
|
||||
if (!this.shouldDestroy) {
|
||||
this.instance && this.instance.onPageLoaded && this.instance.onPageLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The view is about to enter and become the active view.
|
||||
*/
|
||||
willEnter() {
|
||||
if (!this.shouldDestroy) {
|
||||
this.instance && this.instance.onPageWillEnter && this.instance.onPageWillEnter();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The view has fully entered and is now the active view. This
|
||||
|
Reference in New Issue
Block a user