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