Skip to content

Commit

Permalink
feat(viewcontroller): add onWillDismiss callback
Browse files Browse the repository at this point in the history
Fixed #6702
  • Loading branch information
manucorporat authored and adamdbradley committed Jun 30, 2016
1 parent 1c882b3 commit ec99bfd
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 38 deletions.
10 changes: 5 additions & 5 deletions demos/toast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ApiDemoPage {
duration: 3000
});

toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

Expand All @@ -26,7 +26,7 @@ class ApiDemoPage {
duration: 3000
});

toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

Expand All @@ -35,7 +35,7 @@ class ApiDemoPage {
message: 'I am dismissed after 1.5 seconds',
duration: 1500
});
toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

Expand All @@ -45,12 +45,12 @@ class ApiDemoPage {
showCloseButton: true,
closeButtonText: 'Ok'
});
toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

private dismissHandler() {
console.info('Toast onDismiss()');
console.info('Toast onDidDismiss()');
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/components/alert/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class E2EPage {
this.testPromptOpen = true;
});

alert.onDismiss((data: any, role: any) => {
console.log('onDismiss, data:', data, 'role:', role);
alert.onDidDismiss((data: any, role: any) => {
console.log('onDidDismiss, data:', data, 'role:', role);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/alert/test/dismiss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class E2EPage {
]
});

alert.onDismiss(() => {
alert.onDidDismiss(() => {
console.log('dismiss');
this.nav.push(AnotherPage);
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/datetime/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export class DateTime {
picker.present(pickerOptions);

this._isOpen = true;
picker.onDismiss(() => {
picker.onDidDismiss(() => {
this._isOpen = false;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/loading/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Loading extends ViewController {
* will show even during page changes, but this can be disabled by setting
* `dismissOnPageChange` to `true`. To dismiss the loading indicator after
* creation, call the `dismiss()` method on the Loading instance. The
* `onDismiss` function can be called to perform an action after the loading
* `onDidDismiss` function can be called to perform an action after the loading
* indicator is dismissed.
*
* >Note that after the component is dismissed, it will not be usable anymore
Expand Down Expand Up @@ -126,7 +126,7 @@ export class Loading extends ViewController {
* duration: 5000
* });
*
* loading.onDismiss(() => {
* loading.onDidDismiss(() => {
* console.log('Dismissed loading');
* });
*
Expand Down
2 changes: 1 addition & 1 deletion src/components/loading/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class E2EPage {
cssClass: 'my-custom-loader'
});

loading.onDismiss(() => {
loading.onDidDismiss(() => {
console.log('Dismissed loading');
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class Modal extends ViewController {
*
* presentProfileModal() {
* let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
* profileModal.onDismiss(data => {
* profileModal.onDidDismiss(data => {
* console.log(data);
* });
* profileModal.present();
Expand Down
32 changes: 19 additions & 13 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 = this.modalCtrl.create(ModalPassData, { userId: 8675309 });
modal.present();

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

Expand All @@ -56,7 +61,7 @@ class E2EPage {

presentModalWithInputs() {
let modal = this.modalCtrl.create(ModalWithInputs);
modal.onDismiss((data: any) => {
modal.onDidDismiss((data: any) => {
console.log('Modal with inputs data:', data);
});
modal.present();
Expand Down Expand Up @@ -153,27 +158,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 @@ -365,15 +371,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 @@ -446,15 +452,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
24 changes: 21 additions & 3 deletions src/components/nav/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class ViewController {
private _leavingOpts: NavOptions = null;
private _loaded: boolean = false;
private _nbDir: Navbar;
private _onDismiss: Function = null;
private _onDidDismiss: Function = null;
private _onWillDismiss: Function = null;
private _pgRef: ElementRef;
private _cd: ChangeDetectorRef;
protected _nav: NavController;
Expand Down Expand Up @@ -120,16 +121,33 @@ export class ViewController {
* @private
*/
onDismiss(callback: Function) {
this._onDismiss = callback;
// deprecated warning: added beta.11 2016-06-30
console.warn('onDismiss(..) has been deprecated. Please use onDidDismiss(..) instead');
this.onDidDismiss(callback);
}

/**
* @private
*/
onDidDismiss(callback: Function) {
this._onDidDismiss = 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);
this._onDidDismiss && this._onDidDismiss(data, role);
return data;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Popover extends ViewController {
* To dismiss the popover after creation, call the `dismiss()` method on the
* `Popover` instance. The popover can also be dismissed from within the popover's
* view by calling the `dismiss()` method on the [ViewController](../../nav/ViewController).
* The `onDismiss` function can be called to perform an action after the popover
* The `onDidDismiss` function can be called to perform an action after the popover
* is dismissed. The popover will dismiss when the backdrop is clicked, but this
* can be disabled by setting `enableBackdropDismiss` to `false` in the popover
* options.
Expand Down
2 changes: 1 addition & 1 deletion src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class Select {
overlay.present(alertOptions);

this._isOpen = true;
overlay.onDismiss(() => {
overlay.onDidDismiss(() => {
this._isOpen = false;
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/toast/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class E2EPage {
message: 'User was created successfully'
});

toast.onDismiss(() => {
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});

Expand All @@ -50,7 +50,7 @@ class E2EPage {
duration: 5000
});

toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

Expand All @@ -59,7 +59,7 @@ class E2EPage {
message: 'I am dismissed after 1.5 seconds',
duration: 1500
});
toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

Expand All @@ -70,12 +70,12 @@ class E2EPage {
closeButtonText: 'Ok',
position: positionString
});
toast.onDismiss(this.dismissHandler);
toast.onDidDismiss(this.dismissHandler);
toast.present();
}

private dismissHandler(toast: Toast) {
console.info('Toast onDismiss()');
console.info('Toast onDidDismiss()');
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Toast extends ViewController {
* by passing the number of milliseconds to display it in the `duration` of
* the toast options. If `showCloseButton` is set to true, then the close button
* will dismiss the toast. To dismiss the toast after creation, call the `dismiss()`
* method on the Toast instance. The `onDismiss` function can be called to perform an action after the toast
* method on the Toast instance. The `onDidDismiss` function can be called to perform an action after the toast
* is dismissed.
*
* @usage
Expand All @@ -119,7 +119,7 @@ export class Toast extends ViewController {
* position: 'top'
* });
*
* toast.onDismiss(() => {
* toast.onDidDismiss(() => {
* console.log('Dismissed toast');
* });
*
Expand Down

0 comments on commit ec99bfd

Please sign in to comment.