From 8039eae2d2b3a749c3ddc711ce5b5cfd708f1a23 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 14 Sep 2015 23:20:17 -0500 Subject: [PATCH] prevent double navigations to the same view --- ionic/components/nav/nav-router.ts | 5 +++++ ionic/components/view/view-controller.ts | 28 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/ionic/components/nav/nav-router.ts b/ionic/components/nav/nav-router.ts index 36b1230cb0..f76488ceb6 100644 --- a/ionic/components/nav/nav-router.ts +++ b/ionic/components/nav/nav-router.ts @@ -49,6 +49,11 @@ export class NavRouter extends RouterOutlet { var componentType = nextInstruction.componentType; var childRouter = this._parentRouter.childRouter(componentType); + // prevent double navigations to the same view + var lastView = this.nav.last(); + if (lastView && lastView.componentType === componentType && lastView.params.data === nextInstruction.params) { + return Promise.resolve(); + } // tell the ViewController which componentType, and it's params, to navigate to return this.nav.push(componentType, nextInstruction.params); diff --git a/ionic/components/view/view-controller.ts b/ionic/components/view/view-controller.ts index dfdff88c1f..9a795a2060 100644 --- a/ionic/components/view/view-controller.ts +++ b/ionic/components/view/view-controller.ts @@ -640,6 +640,34 @@ export class ViewController extends Ion { util.array.remove(this.items, itemOrIndex); } + /** + * First view item in this view controller's stack. This would + * not return an item which is about to be destroyed. + * @returns {TODO} TODO + */ + first() { + for (let i = 0, l = this.items.length; i < l; i++) { + if (!this.items[i].shouldDestroy) { + return this.items[i]; + } + } + return null; + } + + /** + * Last view item in this view controller's stack. This would + * not return an item which is about to be destroyed. + * @returns {TODO} TODO + */ + last() { + for (let i = this.items.length - 1; i >= 0; i--) { + if (!this.items[i].shouldDestroy) { + return this.items[i]; + } + } + return null; + } + /** * TODO * @param {TODO} item TODO