Skip to content

Commit 687a17b

Browse files
committed
perf(tabs): render tab navbar at same time of tab content
1 parent e8f1b16 commit 687a17b

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

ionic/components/navbar/navbar.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class ToolbarBackground {
106106
'</div>',
107107
host: {
108108
'[hidden]': '_hidden',
109+
'[class.show-tab-navbar]': '_showNavbar',
109110
'class': 'toolbar'
110111
},
111112
directives: [BackButton, BackButtonText, Icon, ToolbarBackground]
@@ -117,6 +118,7 @@ export class Navbar extends ToolbarBase {
117118
private _bbRef: ElementRef;
118119
private _bbtRef: ElementRef;
119120
private _bgRef: ElementRef;
121+
private _showNavbar: boolean;
120122

121123
/**
122124
* @private
@@ -211,8 +213,14 @@ export class Navbar extends ToolbarBase {
211213
/**
212214
* @private
213215
*/
214-
setHidden(isHidden) {
215-
this._hidden = isHidden
216+
setHidden(isHidden: boolean) {
217+
// used to display none/block the navbar
218+
this._hidden = isHidden;
219+
220+
// on the very first load, the navbar may load quicker than
221+
// the tab content, which looks weird. This makes sure that
222+
// the tab's navbar doesn't show before the tab has fully loaded
223+
this._showNavbar = !isHidden;
216224
}
217225

218226
}

ionic/components/tabs/tab.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export class Tab extends NavController {
184184
preload(wait) {
185185
this._loadTimer = setTimeout(() => {
186186
if (!this._loaded) {
187+
console.debug('Tabs, preload', this.id);
187188
this.load({
188189
animate: false,
189190
preload: true,

ionic/components/tabs/tabs.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ ion-tabs > ion-navbar-section {
3838
order: $flex-order-tabbar-navbar;
3939
}
4040

41+
ion-tabs > ion-navbar-section ion-navbar.toolbar.show-navbar {
42+
// by default, do not show tab navbars when they render
43+
opacity: 0;
44+
}
45+
46+
ion-tabs > ion-navbar-section ion-navbar.toolbar.show-navbar.show-tab-navbar {
47+
// only when the tab content has loaded should it be rendered
48+
opacity: 1;
49+
}
50+
4151
ion-tabbar-section {
4252
position: relative;
4353
order: $flex-order-tabbar-bottom;

ionic/components/tabs/tabs.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {NavController} from '../nav/nav-controller';
1212
import {ViewController} from '../nav/view-controller';
1313
import {Icon} from '../icon/icon';
1414
import {rafFrames} from '../../util/dom';
15-
import {isUndefined} from '../../util/util';
15+
import {isUndefined, isTrueProperty} from '../../util/util';
1616

1717

1818
/**
@@ -69,6 +69,7 @@ import {isUndefined} from '../../util/util';
6969
})
7070
export class Tabs extends Ion {
7171
private _ids: number = -1;
72+
private _preloadTabs: boolean = null;
7273
private _tabs: Array<Tab> = [];
7374
private _onReady = null;
7475
private _useHighlight: boolean;
@@ -150,11 +151,8 @@ export class Tabs extends Ion {
150151
* @private
151152
*/
152153
ngAfterViewInit() {
153-
this.preloadTabs = (this.preloadTabs !== "false" && this.preloadTabs !== false);
154-
155154
this._setConfig('tabbarPlacement', 'bottom');
156155
this._setConfig('tabbarIcons', 'top');
157-
this._setConfig('preloadTabs', false);
158156

159157
if (this._useHighlight) {
160158
this._platform.onResize(() => {
@@ -167,14 +165,18 @@ export class Tabs extends Ion {
167165
this.select(tab);
168166
});
169167
});
168+
}
170169

170+
ngAfterContentInit() {
171171
let selectedIndex = this.selectedIndex ? parseInt(this.selectedIndex, 10) : 0;
172172

173+
let preloadTabs = (isUndefined(this.preloadTabs) ? this._config.getBoolean('preloadTabs') : isTrueProperty(this.preloadTabs));
174+
173175
this._tabs.forEach((tab, index) => {
174176
if (index === selectedIndex) {
175177
this.select(tab);
176178

177-
} else if (this.preloadTabs) {
179+
} else if (preloadTabs) {
178180
tab.preload(1000 * index);
179181
}
180182
});
@@ -215,7 +217,7 @@ export class Tabs extends Ion {
215217
return this._touchActive(selectedTab);
216218
}
217219

218-
console.time('Tabs#select ' + selectedTab.id);
220+
console.debug('Tabs, select', selectedTab.id);
219221

220222
let opts = {
221223
animate: false
@@ -257,7 +259,6 @@ export class Tabs extends Ion {
257259
this._onReady = null;
258260
}
259261

260-
console.time('Tabs#select ' + selectedTab.id);
261262
});
262263
}
263264

0 commit comments

Comments
 (0)