NavController popTo takes componentType

This commit is contained in:
Tim Lancina
2015-10-08 22:56:07 -05:00
parent b2336550dd
commit 63aebf8ba8
2 changed files with 27 additions and 8 deletions

View File

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

View File

@@ -105,6 +105,7 @@ class SecondPage {
<button id="from3To2" (click)="pop()">Pop (Go back to 2nd)</button>
<button id="insert" (click)="insert()">Insert first page into history before this</button>
<button id="remove" (click)="removeSecond()">Remove second page in history</button>
<button id="popto" (click)="popTo()">popTo FirstPage</button>
</p>
<div class="yellow"><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f></div>
</ion-content>
@@ -129,6 +130,10 @@ class ThirdPage {
this.nav.remove(1);
}
popTo() {
this.nav.popTo(FirstPage);
}
}