mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 08:09:32 +08:00
feat(modal): data and role are passed to canDismiss (#26384)
resolves #26292
This commit is contained in:
@ -23,7 +23,15 @@ import type { Attributes } from '../../utils/helpers';
|
||||
import { KEYBOARD_DID_OPEN } from '../../utils/keyboard/keyboard';
|
||||
import { printIonWarning } from '../../utils/logging';
|
||||
import { Style as StatusBarStyle, StatusBar } from '../../utils/native/status-bar';
|
||||
import { BACKDROP, activeAnimations, dismiss, eventMethod, prepareOverlay, present } from '../../utils/overlays';
|
||||
import {
|
||||
GESTURE,
|
||||
BACKDROP,
|
||||
activeAnimations,
|
||||
dismiss,
|
||||
eventMethod,
|
||||
prepareOverlay,
|
||||
present,
|
||||
} from '../../utils/overlays';
|
||||
import { getClassMap } from '../../utils/theme';
|
||||
import { deepReady } from '../../utils/transition';
|
||||
|
||||
@ -267,7 +275,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
* If the value is `true` or the value's function returns `true`, the modal will close when trying to dismiss.
|
||||
* If the value is `false` or the value's function returns `false`, the modal will not close when trying to dismiss.
|
||||
*/
|
||||
@Prop() canDismiss?: undefined | boolean | (() => Promise<boolean>);
|
||||
@Prop() canDismiss?: undefined | boolean | ((data?: any, role?: string) => Promise<boolean>);
|
||||
|
||||
/**
|
||||
* Emitted after the modal has presented.
|
||||
@ -449,7 +457,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
* modal is allowed to dismiss based
|
||||
* on the state of the canDismiss prop.
|
||||
*/
|
||||
private async checkCanDismiss() {
|
||||
private async checkCanDismiss(data?: any, role?: string) {
|
||||
const { canDismiss } = this;
|
||||
|
||||
/**
|
||||
@ -461,7 +469,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
}
|
||||
|
||||
if (typeof canDismiss === 'function') {
|
||||
return canDismiss();
|
||||
return canDismiss(data, role);
|
||||
}
|
||||
|
||||
return canDismiss;
|
||||
@ -603,7 +611,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
*/
|
||||
this.gestureAnimationDismissing = true;
|
||||
this.animation!.onFinish(async () => {
|
||||
await this.dismiss(undefined, 'gesture');
|
||||
await this.dismiss(undefined, GESTURE);
|
||||
this.gestureAnimationDismissing = false;
|
||||
});
|
||||
});
|
||||
@ -665,7 +673,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
this.animation!.onFinish(async () => {
|
||||
this.currentBreakpoint = 0;
|
||||
this.ionBreakpointDidChange.emit({ breakpoint: this.currentBreakpoint });
|
||||
await this.dismiss(undefined, 'gesture');
|
||||
await this.dismiss(undefined, GESTURE);
|
||||
this.gestureAnimationDismissing = false;
|
||||
});
|
||||
}
|
||||
@ -678,7 +686,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
*/
|
||||
@Method()
|
||||
async dismiss(data?: any, role?: string): Promise<boolean> {
|
||||
if (this.gestureAnimationDismissing && role !== 'gesture') {
|
||||
if (this.gestureAnimationDismissing && role !== GESTURE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -687,7 +695,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
* for calling the dismiss method, we should
|
||||
* not run the canDismiss check again.
|
||||
*/
|
||||
if (role !== 'handler' && !(await this.checkCanDismiss())) {
|
||||
if (role !== 'handler' && !(await this.checkCanDismiss(data, role))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user