prevent new transition during a transition

This commit is contained in:
Adam Bradley
2015-05-14 16:11:42 -05:00
parent 4f0fded520
commit 2e881d53e3
2 changed files with 26 additions and 22 deletions

View File

@ -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]
} }

View File

@ -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;