fix(tabs): fix tabs init loading/preloading

This commit is contained in:
Adam Bradley
2016-01-25 11:44:53 -06:00
parent 8fc159e2e8
commit 36737143bf
2 changed files with 27 additions and 21 deletions

View File

@@ -101,7 +101,9 @@ export class Tab extends NavController {
private _btnId: string;
private _loaded: boolean;
private _loadTimer: any;
btn: TabButton;
@Input() root: Type;
@Input() tabTitle: string;
@Input() tabIcon: string;
@@ -123,7 +125,7 @@ export class Tab extends NavController {
// A Tab is a NavController for its child pages
super(parentTabs, app, config, keyboard, elementRef, 'contents', compiler, viewManager, zone, renderer);
this._isInitial = parentTabs.add(this);
parentTabs.add(this);
this._panelId = 'tabpanel-' + this.id;
this._btnId = 'tab-' + this.id;
@@ -134,24 +136,6 @@ export class Tab extends NavController {
*/
ngOnInit() {
this.tabBadgeStyle = this.tabBadgeStyle ? this.tabBadgeStyle : 'default';
if (this._isInitial) {
this.parent.select(this);
} else if (this.parent.preloadTabs) {
this._loadTimer = setTimeout(() => {
if (!this._loaded) {
this.load({
animate: false,
preload: true,
postLoad: (viewCtrl) => {
let navbar = viewCtrl.getNavbar();
navbar && navbar.setHidden(true);
}
}, function(){});
}
}, 1000 * this.index);
}
}
/**
@@ -169,6 +153,21 @@ export class Tab extends NavController {
}
}
preload(wait) {
this._loadTimer = setTimeout(() => {
if (!this._loaded) {
this.load({
animate: false,
preload: true,
postLoad: (viewCtrl) => {
let navbar = viewCtrl.getNavbar();
navbar && navbar.setHidden(true);
}
}, function(){});
}
}, wait);
}
/**
* @private
*/

View File

@@ -132,6 +132,15 @@ export class Tabs extends Ion {
this.select(tab);
});
});
this._tabs.forEach((tab, index) => {
if (index === 0) {
this.select(tab);
} else if (this.preloadTabs) {
tab.preload(1000 * index);
}
});
}
/**
@@ -151,8 +160,6 @@ export class Tabs extends Ion {
add(tab) {
tab.id = this.id + '-' + (++this._ids);
this._tabs.push(tab);
return (this._tabs.length === 1);
}
/**