From d8234e90dd4b5f240ecad4bd207d176117f2eec7 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Mon, 19 Mar 2018 17:10:44 +0100 Subject: [PATCH] docs(overlay): onDidDismiss --- .../components/action-sheet/action-sheet.tsx | 24 +++++++++++++++---- core/src/components/alert/alert.tsx | 24 +++++++++++++++---- core/src/components/loading/loading.tsx | 22 ++++++++++++++--- core/src/components/modal/modal.tsx | 24 +++++++++++++++---- core/src/components/picker/picker.tsx | 22 ++++++++++++++--- core/src/components/popover/popover.tsx | 20 ++++++++++++++-- core/src/components/toast/toast.tsx | 20 ++++++++++++++-- core/src/utils/overlays.ts | 8 +++---- 8 files changed, 138 insertions(+), 26 deletions(-) diff --git a/core/src/components/action-sheet/action-sheet.tsx b/core/src/components/action-sheet/action-sheet.tsx index 6953bd26cd..a8901b5ebe 100644 --- a/core/src/components/action-sheet/action-sheet.tsx +++ b/core/src/components/action-sheet/action-sheet.tsx @@ -137,7 +137,7 @@ export class ActionSheet implements OverlayInterface { */ @Method() present(): Promise { - return present(this, 'actionSheetEnter', iosEnterAnimation, mdEnterAnimation, undefined); + return present(this, 'actionSheetEnter', iosEnterAnimation, mdEnterAnimation); } /** @@ -145,16 +145,32 @@ export class ActionSheet implements OverlayInterface { */ @Method() dismiss(data?: any, role?: string): Promise { - return dismiss(this, data, role, 'actionSheetLeave', iosLeaveAnimation, mdLeaveAnimation, undefined); + return dismiss(this, data, role, 'actionSheetLeave', iosLeaveAnimation, mdLeaveAnimation); } + /** + * Returns a promise that resolves when the action-sheet did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await actionSheet.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionActionSheetDidDismiss', callback); } + /** + * Returns a promise that resolves when the action-sheet will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await actionSheet.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionActionSheetWillDismiss', callback); } diff --git a/core/src/components/alert/alert.tsx b/core/src/components/alert/alert.tsx index 51485df9fd..6e4ac57237 100644 --- a/core/src/components/alert/alert.tsx +++ b/core/src/components/alert/alert.tsx @@ -150,7 +150,7 @@ export class Alert implements OverlayInterface { */ @Method() present(): Promise { - return present(this, 'alertEnter', iosEnterAnimation, mdEnterAnimation, undefined).then(() => { + return present(this, 'alertEnter', iosEnterAnimation, mdEnterAnimation).then(() => { autoFocus(this.el); }); } @@ -160,16 +160,32 @@ export class Alert implements OverlayInterface { */ @Method() dismiss(data?: any, role?: string): Promise { - return dismiss(this, data, role, 'alertLeave', iosLeaveAnimation, mdLeaveAnimation, undefined); + return dismiss(this, data, role, 'alertLeave', iosLeaveAnimation, mdLeaveAnimation); } + /** + * Returns a promise that resolves when the alert did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await alert.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionAlerDidDismiss', callback); } + /** + * Returns a promise that resolves when the alert will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await alert.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionAlertWillDismiss', callback); } diff --git a/core/src/components/loading/loading.tsx b/core/src/components/loading/loading.tsx index fb6f086f9a..0d8c129a56 100644 --- a/core/src/components/loading/loading.tsx +++ b/core/src/components/loading/loading.tsx @@ -159,16 +159,32 @@ export class Loading implements OverlayInterface { if (this.durationTimeout) { clearTimeout(this.durationTimeout); } - return dismiss(this, data, role, 'loadingLeave', iosLeaveAnimation, mdLeaveAnimation, undefined); + return dismiss(this, data, role, 'loadingLeave', iosLeaveAnimation, mdLeaveAnimation); } + /** + * Returns a promise that resolves when the loading did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await loading.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionLoadingDidDismiss', callback); } + /** + * Returns a promise that resolves when the loading will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await loading.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionLoadingWillDismiss', callback); } diff --git a/core/src/components/modal/modal.tsx b/core/src/components/modal/modal.tsx index f850b08f15..04680a962a 100644 --- a/core/src/components/modal/modal.tsx +++ b/core/src/components/modal/modal.tsx @@ -177,7 +177,7 @@ export class Modal implements OverlayInterface { }; return attachComponent(this.delegate, container, this.component, classes, data) .then(el => this.usersElement = el) - .then(() => present(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation, undefined)); + .then(() => present(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation)); } /** @@ -185,16 +185,32 @@ export class Modal implements OverlayInterface { */ @Method() dismiss(data?: any, role?: string): Promise { - return dismiss(this, data, role, 'modalLeave', iosLeaveAnimation, mdLeaveAnimation, undefined); + return dismiss(this, data, role, 'modalLeave', iosLeaveAnimation, mdLeaveAnimation); } + /** + * Returns a promise that resolves when the modal did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await modal.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionModalDidDismiss', callback); } + /** + * Returns a promise that resolves when the modal will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await modal.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionModalWillDismiss', callback); } diff --git a/core/src/components/picker/picker.tsx b/core/src/components/picker/picker.tsx index 84f9e167a0..353e19838d 100644 --- a/core/src/components/picker/picker.tsx +++ b/core/src/components/picker/picker.tsx @@ -164,16 +164,32 @@ export class Picker implements OverlayInterface { if (this.durationTimeout) { clearTimeout(this.durationTimeout); } - return dismiss(this, data, role, 'pickerLeave', iosLeaveAnimation, iosLeaveAnimation, undefined); + return dismiss(this, data, role, 'pickerLeave', iosLeaveAnimation, iosLeaveAnimation); } + /** + * Returns a promise that resolves when the picker did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await picker.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionPickerDidDismiss', callback); } + /** + * Returns a promise that resolves when the picker will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await picker.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionPickerWillDismiss', callback); } diff --git a/core/src/components/popover/popover.tsx b/core/src/components/popover/popover.tsx index 9448ff513c..41ee509fcd 100644 --- a/core/src/components/popover/popover.tsx +++ b/core/src/components/popover/popover.tsx @@ -198,13 +198,29 @@ export class Popover implements OverlayInterface { return dismiss(this, data, role, 'popoverLeave', iosLeaveAnimation, mdLeaveAnimation, this.ev); } + /** + * Returns a promise that resolves when the popover did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await popover.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionPopoverDidDismiss', callback); } + /** + * Returns a promise that resolves when the popover will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await popover.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionPopoverWillDismiss', callback); } diff --git a/core/src/components/toast/toast.tsx b/core/src/components/toast/toast.tsx index feb0c40b25..38818e053a 100644 --- a/core/src/components/toast/toast.tsx +++ b/core/src/components/toast/toast.tsx @@ -157,13 +157,29 @@ export class Toast implements OverlayInterface { return dismiss(this, data, role, 'toastLeave', iosLeaveAnimation, mdLeaveAnimation, this.position); } + /** + * Returns a promise that resolves when the toast did dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await toast.onDidDismiss(); + * ``` + */ @Method() - onDidDismiss(callback: (data?: any, role?: string) => void): Promise { + onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionToastDidDismiss', callback); } + /** + * Returns a promise that resolves when the toast will dismiss. It also accepts a callback + * that is called in the same circustances. + * + * ``` + * const {data, role} = await toast.onWillDismiss(); + * ``` + */ @Method() - onWillDismiss(callback: (data?: any, role?: string) => void): Promise { + onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise { return eventMethod(this.el, 'ionToastWillDismiss', callback); } diff --git a/core/src/utils/overlays.ts b/core/src/utils/overlays.ts index 7177ed5c03..e42a65c723 100644 --- a/core/src/utils/overlays.ts +++ b/core/src/utils/overlays.ts @@ -58,7 +58,7 @@ export function present( name: string, iosEnterAnimation: AnimationBuilder, mdEnterAnimation: AnimationBuilder, - opts: any + opts?: any ) { if (overlay.presented) { return Promise.resolve(); @@ -83,7 +83,7 @@ export function dismiss( name: string, iosLeaveAnimation: AnimationBuilder, mdLeaveAnimation: AnimationBuilder, - opts: any + opts?: any ): Promise { if (!overlay.presented) { return Promise.resolve(); @@ -151,9 +151,9 @@ export function attachComponent(delegate: FrameworkDelegate, container: Element, return Promise.resolve(el); } -export function eventMethod(element: HTMLElement, eventName: string, callback: Function): Promise { +export function eventMethod(element: HTMLElement, eventName: string, callback?: (detail: T) => void): Promise { let resolve: Function; - const promise = new Promise(r => resolve = r); + const promise = new Promise(r => resolve = r); onceEvent(element, eventName, (event) => { const detail = event.detail; callback && callback(detail);