mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
select tabs update
This commit is contained in:
@ -190,24 +190,6 @@ export class NavBase {
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
select(enteringItem, opts = {}) {
|
|
||||||
if (!enteringItem || !enteringItem.instance || this.isTransitioning()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enteringItem.instance.loadInitial();
|
|
||||||
|
|
||||||
opts.animation = 'none';
|
|
||||||
|
|
||||||
let leavingItem = this.getActive() || new NavItem();
|
|
||||||
leavingItem.shouldDestroy = false;
|
|
||||||
leavingItem.shouldCache = true;
|
|
||||||
leavingItem.willCache();
|
|
||||||
|
|
||||||
this.transition(enteringItem, leavingItem, opts, () => {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
transition(enteringItem, leavingItem, opts, callback) {
|
transition(enteringItem, leavingItem, opts, callback) {
|
||||||
if (!enteringItem || enteringItem === leavingItem) {
|
if (!enteringItem || enteringItem === leavingItem) {
|
||||||
return callback();
|
return callback();
|
||||||
|
@ -31,6 +31,6 @@ export class TabButton {
|
|||||||
onClick(ev) {
|
onClick(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.tabs.selectTab(this.tab);
|
this.tabs.select(this.tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,14 @@ export class Tab extends NavBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadInitial() {
|
loadInitial(callback) {
|
||||||
if (this.initial && !this._loaded) {
|
if (!this._loaded && this.initial) {
|
||||||
this.push(this.initial);
|
this.push(this.initial).then(() => {
|
||||||
|
callback && callback();
|
||||||
|
});
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
|
} else {
|
||||||
|
callback && callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,18 +58,36 @@ export class Tabs extends NavBase {
|
|||||||
this.add(tabItem);
|
this.add(tabItem);
|
||||||
|
|
||||||
if (this.length() === 1) {
|
if (this.length() === 1) {
|
||||||
this.selectTab(0);
|
this.select(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectTab(tab) {
|
select(tab) {
|
||||||
let item = null;
|
let enteringItem = null;
|
||||||
if (typeof tab === 'number') {
|
if (typeof tab === 'number') {
|
||||||
item = this.getByIndex(tab);
|
enteringItem = this.getByIndex(tab);
|
||||||
} else {
|
} else {
|
||||||
item = this.getByInstance(tab)
|
enteringItem = this.getByInstance(tab)
|
||||||
}
|
}
|
||||||
this.select(item);
|
|
||||||
|
if (!enteringItem || !enteringItem.instance || this.isTransitioning()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enteringItem.instance.loadInitial(() => {
|
||||||
|
let opts = {
|
||||||
|
animation: 'none'
|
||||||
|
};
|
||||||
|
|
||||||
|
let leavingItem = this.getActive() || new NavItem();
|
||||||
|
leavingItem.shouldDestroy = false;
|
||||||
|
leavingItem.shouldCache = true;
|
||||||
|
leavingItem.willCache();
|
||||||
|
|
||||||
|
this.transition(enteringItem, leavingItem, opts, () => {
|
||||||
|
console.log('tab selected')
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get tabs() {
|
get tabs() {
|
||||||
|
Reference in New Issue
Block a user