From 63aebf8ba89120f3347977c69130ec1d86cf0410 Mon Sep 17 00:00:00 2001
From: Tim Lancina
Date: Thu, 8 Oct 2015 22:56:07 -0500
Subject: [PATCH] NavController popTo takes componentType
---
ionic/components/nav/nav-controller.ts | 30 +++++++++++++++++-------
ionic/components/nav/test/basic/index.ts | 5 ++++
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts
index 91edc2d10e..a443ec7194 100644
--- a/ionic/components/nav/nav-controller.ts
+++ b/ionic/components/nav/nav-controller.ts
@@ -253,16 +253,15 @@ export class NavController extends Ion {
}
/**
- * @private
- * Pop to a specific view in the history stack
+ * Pop to a specific page in the history stack
*
- * @param view {ViewController} to pop to
+ * @param componentType the page to pop to
* @param opts {object} pop options
*/
- _popTo(view, opts = {}) {
+ popTo(componentType, opts = {}) {
// Get the target index of the view to pop to
- let viewIndex = this._views.indexOf(view);
+ let viewIndex = this.getIndexByComponentType(componentType);
let targetIndex = viewIndex + 1;
let resolve;
let promise = new Promise(res => { resolve = res; });
@@ -272,7 +271,6 @@ export class NavController extends Ion {
return;
}
-
opts.direction = opts.direction || 'back';
// get the views to auto remove without having to do a transiton for each
@@ -287,7 +285,7 @@ export class NavController extends Ion {
}
let leavingView = this._views[this._views.length - 1];
- let enteringView = view;
+ let enteringView = this.getByIndex(viewIndex);
if(this.router) {
this.router.stateChange('pop', enteringView);
@@ -305,7 +303,7 @@ export class NavController extends Ion {
* @param opts extra animation options
*/
popToRoot(opts = {}) {
- this.popTo(this._views[0]);
+ this.popTo(this._views[0].componentType);
}
/**
@@ -816,6 +814,22 @@ export class NavController extends Ion {
return null;
}
+ /**
+ * Get the index of the view with the specified componentType
+ * @param componentType
+ * @return index
+ */
+ getIndexByComponentType(componentType) {
+ if (componentType) {
+ for (let i = 0, ii = this._views.length; i < ii; i++) {
+ if (this._views[i].componentType === componentType) {
+ return i;
+ }
+ }
+ }
+ return null;
+ }
+
/**
* TODO
* @param {TODO} index TODO
diff --git a/ionic/components/nav/test/basic/index.ts b/ionic/components/nav/test/basic/index.ts
index d20838f9bf..91df16917d 100644
--- a/ionic/components/nav/test/basic/index.ts
+++ b/ionic/components/nav/test/basic/index.ts
@@ -105,6 +105,7 @@ class SecondPage {
+