mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
fix(tab): correct lifecycle calls
This commit is contained in:
@ -86,26 +86,24 @@ export class Tab extends NavController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onInit() {
|
onInit() {
|
||||||
console.debug('Tab onInit', this.index);
|
|
||||||
|
|
||||||
if (this._isInitial) {
|
if (this._isInitial) {
|
||||||
this.tabs.select(this);
|
this.tabs.select(this);
|
||||||
|
|
||||||
} else if (this.tabs.preloadTabs) {
|
} else if (this.tabs.preloadTabs) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.load(() => {
|
let opts = {
|
||||||
console.debug('preloaded tab', this.index);
|
animate: false,
|
||||||
|
preload: true
|
||||||
|
};
|
||||||
|
this.load(opts, () => {
|
||||||
this.hideNavbars(true);
|
this.hideNavbars(true);
|
||||||
});
|
});
|
||||||
}, 500 * this.index);
|
}, 1000 * this.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load(done) {
|
load(opts, done) {
|
||||||
if (!this._loaded && this.root) {
|
if (!this._loaded && this.root) {
|
||||||
let opts = {
|
|
||||||
animate: false
|
|
||||||
};
|
|
||||||
this.push(this.root, null, opts).then(done);
|
this.push(this.root, null, opts).then(done);
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ export class Tabs extends Ion {
|
|||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug('select tab', selectedTab.id);
|
console.time('select tab ' + selectedTab.id);
|
||||||
|
|
||||||
let deselectedTab = this.getSelected();
|
let deselectedTab = this.getSelected();
|
||||||
|
|
||||||
@ -161,14 +161,32 @@ export class Tabs extends Ion {
|
|||||||
return this.touchActive(selectedTab);
|
return this.touchActive(selectedTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedTab.load(() => {
|
let opts = {
|
||||||
this.isReady && this.isReady();
|
animate: false
|
||||||
|
};
|
||||||
|
|
||||||
|
let deselectedPage;
|
||||||
|
if (deselectedTab) {
|
||||||
|
deselectedPage = deselectedTab.getActive();
|
||||||
|
deselectedPage && deselectedPage.willLeave();
|
||||||
|
}
|
||||||
|
|
||||||
|
let selectedPage = selectedTab.getActive();
|
||||||
|
selectedPage && selectedPage.willEnter();
|
||||||
|
|
||||||
|
selectedTab.load(opts, () => {
|
||||||
this.tabs.forEach(tab => {
|
this.tabs.forEach(tab => {
|
||||||
tab.setSelected(tab === selectedTab);
|
tab.setSelected(tab === selectedTab);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.highlight && this.highlight.select(selectedTab);
|
this.highlight && this.highlight.select(selectedTab);
|
||||||
|
|
||||||
|
selectedPage && selectedPage.didEnter();
|
||||||
|
deselectedPage && deselectedPage.didLeave();
|
||||||
|
|
||||||
|
this.isReady && this.isReady();
|
||||||
|
|
||||||
|
console.timeEnd('select tab ' + selectedTab.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,18 +288,16 @@ class TabHighlight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
select(tab) {
|
select(tab) {
|
||||||
setTimeout(() => {
|
let d = tab.btn.getDimensions();
|
||||||
let d = tab.btn.getDimensions();
|
let ele = this.elementRef.nativeElement;
|
||||||
let ele = this.elementRef.nativeElement;
|
ele.style.transform = 'translate3d(' + d.left + 'px,0,0) scaleX(' + d.width + ')';
|
||||||
ele.style.transform = 'translate3d(' + d.left + 'px,0,0) scaleX(' + d.width + ')';
|
|
||||||
|
|
||||||
if (!this.init) {
|
if (!this.init) {
|
||||||
this.init = true;
|
this.init = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ele.classList.add('animate');
|
ele.classList.add('animate');
|
||||||
}, 64)
|
}, 64)
|
||||||
}
|
}
|
||||||
}, 32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user