From 54af55d9da63bc00854c88f20e82eb717e08295f Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Thu, 24 Sep 2015 15:17:48 -0600 Subject: [PATCH] feat(navController): navController insert method --- ionic/components/nav/nav-controller.ts | 27 +++++++++++++++++++++++- ionic/components/nav/test/basic/index.ts | 5 +++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 13fd914ecf..91687b8cd6 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -159,6 +159,27 @@ export class NavController extends Ion { * @param {TODO} [opts={}] 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 = {}) { if (!components || !components.length) { return Promise.resolve(); @@ -668,10 +689,14 @@ export class NavController extends Ion { * @returns {TODO} TODO */ add(view) { - view.id = this.id + '-' + (++this._ids); + this._incrementId(view); this.views.push(view); } + _incrementId(view) { + view.id = this.id + '-' + (++this._ids); + } + /** * TODO * @param {TODO} viewOrIndex TODO diff --git a/ionic/components/nav/test/basic/index.ts b/ionic/components/nav/test/basic/index.ts index 13aaa21019..a3e2a27396 100644 --- a/ionic/components/nav/test/basic/index.ts +++ b/ionic/components/nav/test/basic/index.ts @@ -100,6 +100,7 @@ class SecondPage {

+

@@ -116,6 +117,10 @@ class ThirdPage { this.nav.pop() } + insert() { + this.nav.insert(FirstPage, 2); + } + }