chore(): sync with main

This commit is contained in:
Liam DeBeasi
2022-12-08 12:39:38 -05:00
457 changed files with 927 additions and 3106 deletions

View File

@ -22,7 +22,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';
@ -252,7 +260,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: boolean | (() => Promise<boolean>) = true;
@Prop() canDismiss: boolean | ((data?: any, role?: string) => Promise<boolean>) = true;
/**
* Emitted after the modal has presented.
@ -419,11 +427,11 @@ 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;
if (typeof canDismiss === 'function') {
return canDismiss();
return canDismiss(data, role);
}
return canDismiss;
@ -469,7 +477,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
writeTask(() => this.el.classList.add('show-modal'));
this.currentTransition = present(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation, {
this.currentTransition = present<ModalPresentOptions>(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation, {
presentingEl: presentingElement,
currentBreakpoint: this.initialBreakpoint,
backdropBreakpoint: this.backdropBreakpoint,
@ -557,7 +565,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;
});
});
@ -619,7 +627,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;
});
}
@ -632,7 +640,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;
}
@ -641,7 +649,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;
}
@ -676,11 +684,19 @@ export class Modal implements ComponentInterface, OverlayInterface {
const enteringAnimation = activeAnimations.get(this) || [];
this.currentTransition = dismiss(this, data, role, 'modalLeave', iosLeaveAnimation, mdLeaveAnimation, {
presentingEl: presentingElement,
currentBreakpoint: this.currentBreakpoint ?? this.initialBreakpoint,
backdropBreakpoint: this.backdropBreakpoint,
});
this.currentTransition = dismiss<ModalDismissOptions>(
this,
data,
role,
'modalLeave',
iosLeaveAnimation,
mdLeaveAnimation,
{
presentingEl: presentingElement,
currentBreakpoint: this.currentBreakpoint ?? this.initialBreakpoint,
backdropBreakpoint: this.backdropBreakpoint,
}
);
const dismissed = await this.currentTransition;
@ -908,3 +924,22 @@ const LIFECYCLE_MAP: any = {
};
let modalIds = 0;
interface ModalOverlayOptions {
/**
* The element that presented the modal.
*/
presentingEl?: HTMLElement;
/**
* The current breakpoint of the sheet modal.
*/
currentBreakpoint?: number;
/**
* The point after which the backdrop will being
* to fade in when using a sheet modal.
*/
backdropBreakpoint: number;
}
type ModalPresentOptions = ModalOverlayOptions;
type ModalDismissOptions = ModalOverlayOptions;