docs(overlay): onDidDismiss

This commit is contained in:
Manu Mtz.-Almeida
2018-03-19 17:10:44 +01:00
parent 50abcf5ab3
commit d8234e90dd
8 changed files with 138 additions and 26 deletions

View File

@ -137,7 +137,7 @@ export class ActionSheet implements OverlayInterface {
*/
@Method()
present(): Promise<void> {
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<void> {
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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionActionSheetWillDismiss', callback);
}

View File

@ -150,7 +150,7 @@ export class Alert implements OverlayInterface {
*/
@Method()
present(): Promise<void> {
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<void> {
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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionAlertWillDismiss', callback);
}

View File

@ -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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionLoadingWillDismiss', callback);
}

View File

@ -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<void> {
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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionModalWillDismiss', callback);
}

View File

@ -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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionPickerWillDismiss', callback);
}

View File

@ -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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionPopoverWillDismiss', callback);
}

View File

@ -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<OverlayEventDetail> {
onDidDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
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<OverlayEventDetail> {
onWillDismiss(callback?: (detail: OverlayEventDetail) => void): Promise<OverlayEventDetail> {
return eventMethod(this.el, 'ionToastWillDismiss', callback);
}

View File

@ -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<void> {
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<any> {
export function eventMethod<T>(element: HTMLElement, eventName: string, callback?: (detail: T) => void): Promise<T> {
let resolve: Function;
const promise = new Promise(r => resolve = r);
const promise = new Promise<T>(r => resolve = r);
onceEvent(element, eventName, (event) => {
const detail = event.detail;
callback && callback(detail);