mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(tabs): load tab pages before tabs ready callback
This commit is contained in:
@@ -7,8 +7,8 @@ import {Keyboard} from '../../util/keyboard';
|
||||
import {ViewController} from './view-controller';
|
||||
import {Animation} from '../../animations/animation';
|
||||
import {SwipeBackGesture} from './swipe-back';
|
||||
import * as util from 'ionic/util';
|
||||
import {raf} from '../../util/dom';
|
||||
import {isBoolean, array} from '../../util/util';
|
||||
import {rafFrames} from '../../util/dom';
|
||||
|
||||
/**
|
||||
* _For examples on the basic usage of NavController, check out the [Navigation section](../../../../components/#navigation)
|
||||
@@ -195,7 +195,7 @@ export class NavController extends Ion {
|
||||
|
||||
// the active view is going to be the leaving one (if one exists)
|
||||
let leavingView = this.getActive() || new ViewController();
|
||||
leavingView.shouldCache = (util.isBoolean(opts.cacheLeavingView) ? opts.cacheLeavingView : true);
|
||||
leavingView.shouldCache = (isBoolean(opts.cacheLeavingView) ? opts.cacheLeavingView : true);
|
||||
leavingView.shouldDestroy = !leavingView.shouldCache;
|
||||
if (leavingView.shouldDestroy) {
|
||||
leavingView.willUnload();
|
||||
@@ -253,7 +253,7 @@ export class NavController extends Ion {
|
||||
// get the active view and set that it is staged to be leaving
|
||||
// was probably the one popped from the stack
|
||||
let leavingView = this.getActive() || new ViewController();
|
||||
leavingView.shouldCache = (util.isBoolean(opts.cacheLeavingView) ? opts.cacheLeavingView : false);
|
||||
leavingView.shouldCache = (isBoolean(opts.cacheLeavingView) ? opts.cacheLeavingView : false);
|
||||
leavingView.shouldDestroy = !leavingView.shouldCache;
|
||||
if (leavingView.shouldDestroy) {
|
||||
leavingView.willUnload();
|
||||
@@ -572,18 +572,26 @@ export class NavController extends Ion {
|
||||
return done();
|
||||
}
|
||||
|
||||
// get the pane the NavController wants to use
|
||||
// the pane is where all this content will be placed into
|
||||
this.loadPage(viewCtrl, null, () => {
|
||||
|
||||
function loaded() {
|
||||
// this ViewController instance has finished loading
|
||||
try {
|
||||
viewCtrl.loaded();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
// get the pane the NavController wants to use
|
||||
// the pane is where all this content will be placed into
|
||||
this.loadPage(viewCtrl, null, () => {
|
||||
|
||||
if (viewCtrl.onReady) {
|
||||
viewCtrl.onReady(loaded);
|
||||
} else {
|
||||
loaded();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -629,9 +637,9 @@ export class NavController extends Ion {
|
||||
|
||||
if (this._views.length === 1) {
|
||||
this._zone.runOutsideAngular(() => {
|
||||
setTimeout(() => {
|
||||
rafFrames(38, () => {
|
||||
this.renderer.setElementClass(this.elementRef, 'has-views', true);
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -954,7 +962,7 @@ export class NavController extends Ion {
|
||||
* @private
|
||||
*/
|
||||
_remove(viewOrIndex) {
|
||||
util.array.remove(this._views, viewOrIndex);
|
||||
array.remove(this._views, viewOrIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,6 +118,7 @@ export class Tabs extends Ion {
|
||||
this._tabs = [];
|
||||
this._id = ++tabIds;
|
||||
this._ids = -1;
|
||||
this._onReady = null;
|
||||
|
||||
// Tabs may also be an actual ViewController which was navigated to
|
||||
// if Tabs is static and not navigated to within a NavController
|
||||
@@ -126,10 +127,8 @@ export class Tabs extends Ion {
|
||||
viewCtrl.setContent(this);
|
||||
viewCtrl.setContentRef(elementRef);
|
||||
|
||||
// TODO: improve how this works, probably not use promises here
|
||||
this._readyPromise = new Promise(res => { this._isReady = res; });
|
||||
viewCtrl.onReady = () => {
|
||||
return this._readyPromise;
|
||||
viewCtrl.onReady = (done) => {
|
||||
this._onReady = done;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -201,7 +200,10 @@ export class Tabs extends Ion {
|
||||
selectedPage && selectedPage.didEnter();
|
||||
deselectedPage && deselectedPage.didLeave();
|
||||
|
||||
this._isReady && this._isReady();
|
||||
if (this._onReady) {
|
||||
this._onReady();
|
||||
this._onReady = null;
|
||||
}
|
||||
|
||||
console.timeEnd('select tab ' + selectedTab.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user