Skip to content

Commit

Permalink
feat(viewcontroller): adds onWillDismiss callback (0 delay)
Browse files Browse the repository at this point in the history
fixed #6702
  • Loading branch information
manucorporat committed Jun 26, 2016
1 parent d0b1930 commit fbb5a22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/components/modal/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ class E2EPage {
let modal = Modal.create(ModalPassData, { userId: 8675309 });
this.nav.present(modal);

modal.onWillDismiss((data: any) => {
console.log('WILL DISMISS with data', data);
console.timeEnd('modal');
});
modal.onDismiss((data: any) => {
console.log('modal data', data);
console.timeEnd('modal');
});
}

Expand Down Expand Up @@ -155,27 +160,28 @@ class ModalPassData {
}

submit() {
console.time('modal');
this.viewCtrl.dismiss(this.data);
}

ionViewLoaded(){
console.log("ModalPassData ionViewLoaded fired");
console.log('ModalPassData ionViewLoaded fired');
}

ionViewWillEnter(){
console.log("ModalPassData ionViewWillEnter fired");
console.log('ModalPassData ionViewWillEnter fired');
}

ionViewDidEnter(){
console.log("ModalPassData ionViewDidEnter fired");
console.log('ModalPassData ionViewDidEnter fired');
}

ionViewWillLeave(){
console.log("ModalPassData ionViewWillLeave fired");
console.log('ModalPassData ionViewWillLeave fired');
}

ionViewDidLeave(){
console.log("ModalPassData ionViewDidLeave fired");
console.log('ModalPassData ionViewDidLeave fired');
}
}

Expand Down Expand Up @@ -367,15 +373,15 @@ class ModalFirstPage {
}

ionViewLoaded(){
console.log("ModalFirstPage ionViewLoaded fired");
console.log('ModalFirstPage ionViewLoaded fired');
}

ionViewWillEnter(){
console.log("ModalFirstPage ionViewWillEnter fired");
console.log('ModalFirstPage ionViewWillEnter fired');
}

ionViewDidEnter(){
console.log("ModalFirstPage ionViewDidEnter fired");
console.log('ModalFirstPage ionViewDidEnter fired');
}

openActionSheet() {
Expand Down Expand Up @@ -448,15 +454,15 @@ class ModalSecondPage {
}

ionViewLoaded(){
console.log("ModalSecondPage ionViewLoaded");
console.log('ModalSecondPage ionViewLoaded');
}

ionViewWillEnter(){
console.log("ModalSecondPage ionViewWillEnter");
console.log('ModalSecondPage ionViewWillEnter');
}

ionViewDidEnter(){
console.log("ModalSecondPage ionViewDidEnter");
console.log('ModalSecondPage ionViewDidEnter');
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/components/nav/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class ViewController {
private _loaded: boolean = false;
private _nbDir: Navbar;
private _onDismiss: Function = null;
private _onWillDismiss: Function = null;
private _pgRef: ElementRef;
private _cd: ChangeDetectorRef;
protected _nav: NavController;
Expand Down Expand Up @@ -127,11 +128,19 @@ export class ViewController {
this._onDismiss = callback;
}

/**
* @private
*/
onWillDismiss(callback: Function) {
this._onWillDismiss = callback;
}

/**
* @private
*/
dismiss(data?: any, role?: any, navOptions: NavOptions = {}) {
let options = merge({}, this._leavingOpts, navOptions);
this._onWillDismiss && this._onWillDismiss(data, role);
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {
this._onDismiss && this._onDismiss(data, role);
return data;
Expand Down

0 comments on commit fbb5a22

Please sign in to comment.