From 6bac56bd38d6be408b829599c83b33b1c818ed5f Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 24 Nov 2015 15:44:01 -0600 Subject: [PATCH] fix(tabs): load tab pages before tabs ready callback --- ionic/components/nav/nav-controller.ts | 32 ++++++++++++++++---------- ionic/components/tabs/tabs.ts | 12 ++++++---- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 4ef667e18b..e0b0363dd2 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -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); } /** diff --git a/ionic/components/tabs/tabs.ts b/ionic/components/tabs/tabs.ts index 1bd0c9b714..4d234118eb 100644 --- a/ionic/components/tabs/tabs.ts +++ b/ionic/components/tabs/tabs.ts @@ -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); });