Skip to content

Commit

Permalink
fix(nav): register child nav when created from modal
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Aug 4, 2016
1 parent 3977928 commit 61a8625
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
34 changes: 16 additions & 18 deletions src/components/modal/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -16,7 +16,7 @@ class SomeComponentProvider {

@Injectable()
class SomeAppProvider {
constructor(private config: Config) {
constructor(public config: Config) {
console.log('SomeAppProvider constructor');
}

Expand All @@ -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'));

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -139,7 +138,7 @@ class NavigableModal {
`
})
class NavigableModal2 {
constructor(private navController: NavController) {
constructor(public navController: NavController) {
}

submit() {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -245,7 +244,7 @@ class ModalPassData {
})
class ToolbarModal {

constructor(private viewCtrl: ViewController) {}
constructor(public viewCtrl: ViewController) {}

dismiss() {
this.viewCtrl.emit({
Expand Down Expand Up @@ -294,7 +293,7 @@ class ToolbarModal {
class ModalWithInputs {
data: any;

constructor(private viewCtrl: ViewController) {
constructor(public viewCtrl: ViewController) {
this.data = {
title: 'Title',
note: 'Note',
Expand Down Expand Up @@ -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)
});
Expand All @@ -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() {
Expand Down Expand Up @@ -465,15 +463,15 @@ class ModalFirstPage {
</ion-header>
<ion-content padding>
<p>
<button (click)="nav.pop()">Pop (Go back to 1st)</button>
<button (click)="navCtrl.pop()">Pop (Go back to 1st)</button>
</p>
<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>
</ion-content>
`
})
class ModalSecondPage {
constructor(private nav: NavController, params: NavParams) {
constructor(public navCtrl: NavController, params: NavParams) {
console.log('Second page params:', params);
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/nav/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <any>viewCtrl.getNav();
this.parent.registerChildNav(this);

} else if (this._app) {
// this is the root navcontroller for the entire app
this._app.setRootNav(this);
Expand Down Expand Up @@ -375,7 +380,7 @@ export class Tabs extends Ion {
* @private
*/
private _setConfig(attrKey: string, fallback: any) {
var val = this[attrKey];
var val = (<any>this)[attrKey];
if (isBlank(val)) {
val = this._config.get(attrKey, fallback);
}
Expand Down

0 comments on commit 61a8625

Please sign in to comment.