Skip to content

Commit

Permalink
perf(tabs): render tab navbar at same time of tab content
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 5, 2016
1 parent e8f1b16 commit 687a17b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
12 changes: 10 additions & 2 deletions ionic/components/navbar/navbar.ts
Expand Up @@ -106,6 +106,7 @@ class ToolbarBackground {
'</div>',
host: {
'[hidden]': '_hidden',
'[class.show-tab-navbar]': '_showNavbar',
'class': 'toolbar'
},
directives: [BackButton, BackButtonText, Icon, ToolbarBackground]
Expand All @@ -117,6 +118,7 @@ export class Navbar extends ToolbarBase {
private _bbRef: ElementRef;
private _bbtRef: ElementRef;
private _bgRef: ElementRef;
private _showNavbar: boolean;

/**
* @private
Expand Down Expand Up @@ -211,8 +213,14 @@ export class Navbar extends ToolbarBase {
/**
* @private
*/
setHidden(isHidden) {
this._hidden = isHidden
setHidden(isHidden: boolean) {
// used to display none/block the navbar
this._hidden = isHidden;

// on the very first load, the navbar may load quicker than
// the tab content, which looks weird. This makes sure that
// the tab's navbar doesn't show before the tab has fully loaded
this._showNavbar = !isHidden;
}

}
Expand Down
1 change: 1 addition & 0 deletions ionic/components/tabs/tab.ts
Expand Up @@ -184,6 +184,7 @@ export class Tab extends NavController {
preload(wait) {
this._loadTimer = setTimeout(() => {
if (!this._loaded) {
console.debug('Tabs, preload', this.id);
this.load({
animate: false,
preload: true,
Expand Down
10 changes: 10 additions & 0 deletions ionic/components/tabs/tabs.scss
Expand Up @@ -38,6 +38,16 @@ ion-tabs > ion-navbar-section {
order: $flex-order-tabbar-navbar;
}

ion-tabs > ion-navbar-section ion-navbar.toolbar.show-navbar {
// by default, do not show tab navbars when they render
opacity: 0;
}

ion-tabs > ion-navbar-section ion-navbar.toolbar.show-navbar.show-tab-navbar {
// only when the tab content has loaded should it be rendered
opacity: 1;
}

ion-tabbar-section {
position: relative;
order: $flex-order-tabbar-bottom;
Expand Down
15 changes: 8 additions & 7 deletions ionic/components/tabs/tabs.ts
Expand Up @@ -12,7 +12,7 @@ import {NavController} from '../nav/nav-controller';
import {ViewController} from '../nav/view-controller';
import {Icon} from '../icon/icon';
import {rafFrames} from '../../util/dom';
import {isUndefined} from '../../util/util';
import {isUndefined, isTrueProperty} from '../../util/util';


/**
Expand Down Expand Up @@ -69,6 +69,7 @@ import {isUndefined} from '../../util/util';
})
export class Tabs extends Ion {
private _ids: number = -1;
private _preloadTabs: boolean = null;
private _tabs: Array<Tab> = [];
private _onReady = null;
private _useHighlight: boolean;
Expand Down Expand Up @@ -150,11 +151,8 @@ export class Tabs extends Ion {
* @private
*/
ngAfterViewInit() {
this.preloadTabs = (this.preloadTabs !== "false" && this.preloadTabs !== false);

this._setConfig('tabbarPlacement', 'bottom');
this._setConfig('tabbarIcons', 'top');
this._setConfig('preloadTabs', false);

if (this._useHighlight) {
this._platform.onResize(() => {
Expand All @@ -167,14 +165,18 @@ export class Tabs extends Ion {
this.select(tab);
});
});
}

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

let preloadTabs = (isUndefined(this.preloadTabs) ? this._config.getBoolean('preloadTabs') : isTrueProperty(this.preloadTabs));

this._tabs.forEach((tab, index) => {
if (index === selectedIndex) {
this.select(tab);

} else if (this.preloadTabs) {
} else if (preloadTabs) {
tab.preload(1000 * index);
}
});
Expand Down Expand Up @@ -215,7 +217,7 @@ export class Tabs extends Ion {
return this._touchActive(selectedTab);
}

console.time('Tabs#select ' + selectedTab.id);
console.debug('Tabs, select', selectedTab.id);

let opts = {
animate: false
Expand Down Expand Up @@ -257,7 +259,6 @@ export class Tabs extends Ion {
this._onReady = null;
}

console.time('Tabs#select ' + selectedTab.id);
});
}

Expand Down

0 comments on commit 687a17b

Please sign in to comment.