From 61a86253a83dc9d77d53d73fe34b9a4704b2e97a Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 4 Aug 2016 11:49:18 -0500 Subject: [PATCH] fix(nav): register child nav when created from modal --- src/components/modal/test/basic/index.ts | 34 +++++++++++------------- src/components/nav/nav.ts | 10 +++++-- src/components/tabs/tabs.ts | 7 ++++- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/components/modal/test/basic/index.ts b/src/components/modal/test/basic/index.ts index ef3091b00a7..16056f3a4de 100644 --- a/src/components/modal/test/basic/index.ts +++ b/src/components/modal/test/basic/index.ts @@ -5,7 +5,7 @@ import { ActionSheetController, App, Config, ionicBootstrap, ModalController, Na @Injectable() class SomeComponentProvider { - constructor(private config: Config) { + constructor(public config: Config) { console.log('SomeComponentProvider constructor'); } @@ -16,7 +16,7 @@ class SomeComponentProvider { @Injectable() class SomeAppProvider { - constructor(private config: Config) { + constructor(public config: Config) { console.log('SomeAppProvider constructor'); } @@ -32,7 +32,7 @@ class SomeAppProvider { class E2EPage { platforms: string[]; - constructor(private nav: NavController, private modalCtrl: ModalController, config: Config, platform: Platform) { + constructor(public navCtrl: NavController, public modalCtrl: ModalController, config: Config, platform: Platform) { console.log('platforms', platform.platforms()); console.log('mode', config.get('mode')); @@ -117,11 +117,10 @@ class E2EPage { ` }) class NavigableModal { - constructor(private nav: NavController) { - } + constructor(public navCtrl: NavController) {} submit() { - this.nav.push(NavigableModal2); + this.navCtrl.push(NavigableModal2); } } @@ -139,7 +138,7 @@ class NavigableModal { ` }) class NavigableModal2 { - constructor(private navController: NavController) { + constructor(public navController: NavController) { } submit() { @@ -175,7 +174,7 @@ class NavigableModal2 { class ModalPassData { data: any; - constructor(params: NavParams, private viewCtrl: ViewController, someComponentProvider: SomeComponentProvider, someAppProvider: SomeAppProvider) { + constructor(params: NavParams, public viewCtrl: ViewController, someComponentProvider: SomeComponentProvider, someAppProvider: SomeAppProvider) { this.data = { userId: params.get('userId'), name: someComponentProvider.getName() @@ -245,7 +244,7 @@ class ModalPassData { }) class ToolbarModal { - constructor(private viewCtrl: ViewController) {} + constructor(public viewCtrl: ViewController) {} dismiss() { this.viewCtrl.emit({ @@ -294,7 +293,7 @@ class ToolbarModal { class ModalWithInputs { data: any; - constructor(private viewCtrl: ViewController) { + constructor(public viewCtrl: ViewController) { this.data = { title: 'Title', note: 'Note', @@ -374,11 +373,10 @@ class ContactUs { ` }) class ModalFirstPage { + items: any[] = []; - private items: any[]; - constructor(private nav: NavController, private app: App, private actionSheetCtrl: ActionSheetController) { - this.items = []; - for ( let i = 0; i < 50; i++ ) { + constructor(public navCtrl: NavController, public app: App, public actionSheetCtrl: ActionSheetController) { + for (let i = 0; i < 50; i++) { this.items.push({ value: (i + 1) }); @@ -389,11 +387,11 @@ class ModalFirstPage { let page = ModalSecondPage; let params = { id: 8675309, myData: [1, 2, 3, 4] }; - this.nav.push(page, params); + this.navCtrl.push(page, params); } dismiss() { - this.app.getRootNav().pop(); + this.navCtrl.parent.pop(); } ionViewLoaded() { @@ -465,7 +463,7 @@ class ModalFirstPage {

- +

@@ -473,7 +471,7 @@ class ModalFirstPage { ` }) class ModalSecondPage { - constructor(private nav: NavController, params: NavParams) { + constructor(public navCtrl: NavController, params: NavParams) { console.log('Second page params:', params); } diff --git a/src/components/nav/nav.ts b/src/components/nav/nav.ts index 8817ac21c84..ba6b4e41594 100644 --- a/src/components/nav/nav.ts +++ b/src/components/nav/nav.ts @@ -81,9 +81,15 @@ export class Nav extends NavControllerBase implements AfterViewInit { // this Nav has a parent Nav parent.registerChildNav(this); - } else if (app) { + } else if (viewCtrl && viewCtrl.getNav()) { + // this Nav was opened from a modal + this.parent = viewCtrl.getNav(); + this.parent.registerChildNav(this); + + } else if (app && !app.getRootNav()) { + // a root nav has not been registered yet with the app // this is the root navcontroller for the entire app - this._app.setRootNav(this); + app.setRootNav(this); } } diff --git a/src/components/tabs/tabs.ts b/src/components/tabs/tabs.ts index 7be08bf7df0..1a157435142 100644 --- a/src/components/tabs/tabs.ts +++ b/src/components/tabs/tabs.ts @@ -274,6 +274,11 @@ export class Tabs extends Ion { // this Tabs has a parent Nav this.parent.registerChildNav(this); + } else if (viewCtrl && viewCtrl.getNav()) { + // this Nav was opened from a modal + this.parent = viewCtrl.getNav(); + this.parent.registerChildNav(this); + } else if (this._app) { // this is the root navcontroller for the entire app this._app.setRootNav(this); @@ -375,7 +380,7 @@ export class Tabs extends Ion { * @private */ private _setConfig(attrKey: string, fallback: any) { - var val = this[attrKey]; + var val = (this)[attrKey]; if (isBlank(val)) { val = this._config.get(attrKey, fallback); }