feat(navController): navController insert method

This commit is contained in:
Tim Lancina
2015-09-24 15:17:48 -06:00
parent fe7b070a6d
commit 54af55d9da
2 changed files with 31 additions and 1 deletions

View File

@ -159,6 +159,27 @@ export class NavController extends Ion {
* @param {TODO} [opts={}] TODO * @param {TODO} [opts={}] TODO
* @returns {Promise} TODO * @returns {Promise} TODO
*/ */
insert(componentType, index) {
if (!componentType || index < 0) {
return Promise.reject();
}
// push it onto the end
if (index >= this.views.length) {
return this.push(componentType);
}
// create new ViewController, but don't render yet
let viewCtrl = new ViewController(this, componentType);
viewCtrl.state = CACHED_STATE;
viewCtrl.shouldDestroy = false;
viewCtrl.shouldCache = false;
this._incrementId(viewCtrl);
this.views.splice(index, 0, viewCtrl);
}
setViews(components, opts = {}) { setViews(components, opts = {}) {
if (!components || !components.length) { if (!components || !components.length) {
return Promise.resolve(); return Promise.resolve();
@ -668,10 +689,14 @@ export class NavController extends Ion {
* @returns {TODO} TODO * @returns {TODO} TODO
*/ */
add(view) { add(view) {
view.id = this.id + '-' + (++this._ids); this._incrementId(view);
this.views.push(view); this.views.push(view);
} }
_incrementId(view) {
view.id = this.id + '-' + (++this._ids);
}
/** /**
* TODO * TODO
* @param {TODO} viewOrIndex TODO * @param {TODO} viewOrIndex TODO

View File

@ -100,6 +100,7 @@ class SecondPage {
<ion-content padding> <ion-content padding>
<p> <p>
<button id="from3To2" (click)="pop()">Pop (Go back to 2nd)</button> <button id="from3To2" (click)="pop()">Pop (Go back to 2nd)</button>
<button id="insert" (click)="insert()">Insert first page into history before this</button>
</p> </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> <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> </ion-content>
@ -116,6 +117,10 @@ class ThirdPage {
this.nav.pop() this.nav.pop()
} }
insert() {
this.nav.insert(FirstPage, 2);
}
} }