mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(tabs): fix tabs init loading/preloading
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user