mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
prevent new transition during a transition
This commit is contained in:
@ -29,7 +29,11 @@ export class NavBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push(Class: Function, params = {}, opts = {}) {
|
push(Component, params = {}, opts = {}) {
|
||||||
|
if (this.isTransitioning()) {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
|
||||||
let resolve;
|
let resolve;
|
||||||
let promise = new Promise(res => { resolve = res; });
|
let promise = new Promise(res => { resolve = res; });
|
||||||
|
|
||||||
@ -46,7 +50,7 @@ export class NavBase {
|
|||||||
leavingItem.shouldDestroy = false;
|
leavingItem.shouldDestroy = false;
|
||||||
|
|
||||||
// create a new NavStackItem
|
// create a new NavStackItem
|
||||||
let enteringItem = new NavItem(this, Class, params);
|
let enteringItem = new NavItem(this, Component, params);
|
||||||
|
|
||||||
// set that this item is staged (it's not ready to be animated in yet)
|
// set that this item is staged (it's not ready to be animated in yet)
|
||||||
enteringItem.state = STAGED_STATE;
|
enteringItem.state = STAGED_STATE;
|
||||||
@ -64,6 +68,10 @@ export class NavBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pop(opts = {}) {
|
pop(opts = {}) {
|
||||||
|
if (this.isTransitioning()) {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
|
||||||
// reject if there's nothing to pop to
|
// reject if there's nothing to pop to
|
||||||
if (this.items.length < 2) {
|
if (this.items.length < 2) {
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
@ -103,13 +111,6 @@ export class NavBase {
|
|||||||
// wait for the new item to complete setup
|
// wait for the new item to complete setup
|
||||||
enteringItem.setup().then(() => {
|
enteringItem.setup().then(() => {
|
||||||
|
|
||||||
// get any items that are already staged to leave, or are actively leaving
|
|
||||||
// since a different item will be leaving, reset any actively leaving items to cached
|
|
||||||
let leavingItems = this.getLeavingItems();
|
|
||||||
for (let i = 0; i < leavingItems.length; i++) {
|
|
||||||
leavingItems[i].state = CACHED_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set that the leaving item is stage to be leaving
|
// set that the leaving item is stage to be leaving
|
||||||
leavingItem.state = STAGED_LEAVING_STATE;
|
leavingItem.state = STAGED_LEAVING_STATE;
|
||||||
|
|
||||||
@ -166,6 +167,19 @@ export class NavBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isTransitioning() {
|
||||||
|
var state;
|
||||||
|
for (let i = 0, ii = this.items.length; i < ii; i++) {
|
||||||
|
state = this.items[i].state;
|
||||||
|
if (state === ACTIVELY_ENTERING_STATE ||
|
||||||
|
state === ACTIVELY_LEAVING_STATE ||
|
||||||
|
state === STAGED_ENTERING_STATE ||
|
||||||
|
state === STAGED_LEAVING_STATE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
getActive() {
|
getActive() {
|
||||||
for (let i = 0, ii = this.items.length; i < ii; i++) {
|
for (let i = 0, ii = this.items.length; i < ii; i++) {
|
||||||
@ -201,16 +215,6 @@ export class NavBase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getLeavingItems() {
|
|
||||||
let items = [];
|
|
||||||
for (let i = 0, ii = this.items.length; i < ii; i++) {
|
|
||||||
if (this.items[i].state === ACTIVELY_LEAVING_STATE || this.items[i].state === STAGED_LEAVING_STATE) {
|
|
||||||
items.push(this.items[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
last() {
|
last() {
|
||||||
return this.items[this.items.length - 1]
|
return this.items[this.items.length - 1]
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ import {NavController} from './nav-controller';
|
|||||||
|
|
||||||
export class NavItem {
|
export class NavItem {
|
||||||
|
|
||||||
constructor(nav, ComponentClass, params = {}) {
|
constructor(nav, Component, params = {}) {
|
||||||
this.nav = nav;
|
this.nav = nav;
|
||||||
this.Class = ComponentClass;
|
this.Component = Component;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.id = util.nextUid();
|
this.id = util.nextUid();
|
||||||
this.headerProtos = [];
|
this.headerProtos = [];
|
||||||
@ -36,7 +36,7 @@ export class NavItem {
|
|||||||
bind(NavItem).toValue(this)
|
bind(NavItem).toValue(this)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.nav.loader.loadNextToExistingLocation(this.Class, this.nav.contentElementRef, injector).then((componentRef) => {
|
this.nav.loader.loadNextToExistingLocation(this.Component, this.nav.contentElementRef, injector).then((componentRef) => {
|
||||||
|
|
||||||
// content
|
// content
|
||||||
this.component = componentRef;
|
this.component = componentRef;
|
||||||
|
Reference in New Issue
Block a user