Skip to content

Commit 6509b15

Browse files
CR
1 parent f914101 commit 6509b15

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

core/src/components/modal/animations/sheet.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createAnimation } from '@utils/animation/animation';
22

33
import type { ModalAnimationOptions } from '../modal-interface';
4-
import { getBackdropValueForSheet, staticBackdropOpacity } from '../utils';
4+
import { getBackdropValueForSheet } from '../utils';
55

66
export const createSheetEnterAnimation = (opts: ModalAnimationOptions) => {
77
const { currentBreakpoint, backdropBreakpoint } = opts;
@@ -13,14 +13,14 @@ export const createSheetEnterAnimation = (opts: ModalAnimationOptions) => {
1313
*/
1414
const shouldShowBackdrop = backdropBreakpoint === undefined || backdropBreakpoint < currentBreakpoint!;
1515

16-
const initialBackdrop =
17-
opts.theme === 'ionic'
18-
? staticBackdropOpacity
19-
: shouldShowBackdrop
20-
? `calc(var(--backdrop-opacity) * ${currentBreakpoint!})`
21-
: '0';
16+
let initialBackdropOpacity = '0';
17+
if (opts.initialBackdropOpacity) {
18+
initialBackdropOpacity = opts.initialBackdropOpacity;
19+
} else if (shouldShowBackdrop) {
20+
initialBackdropOpacity = `calc(var(--backdrop-opacity) * ${currentBreakpoint!})`;
21+
}
2222

23-
const backdropAnimation = createAnimation('backdropAnimation').fromTo('opacity', 0, initialBackdrop);
23+
const backdropAnimation = createAnimation('backdropAnimation').fromTo('opacity', 0, initialBackdropOpacity);
2424

2525
if (shouldShowBackdrop) {
2626
backdropAnimation
@@ -46,18 +46,17 @@ export const createSheetLeaveAnimation = (opts: ModalAnimationOptions) => {
4646
* is defined, so we need to account for that offset by figuring out
4747
* what the current backdrop value should be.
4848
*/
49-
const backdropValue =
50-
opts.theme === 'ionic'
51-
? staticBackdropOpacity
52-
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(currentBreakpoint!, backdropBreakpoint!)})`;
49+
const backdropOpacityValue = opts.backdropOpacityValue
50+
? opts.backdropOpacityValue
51+
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(currentBreakpoint!, backdropBreakpoint!)})`;
5352

5453
const defaultBackdrop = [
55-
{ offset: 0, opacity: backdropValue },
54+
{ offset: 0, opacity: backdropOpacityValue },
5655
{ offset: 1, opacity: 0 },
5756
];
5857

5958
const customBackdrop = [
60-
{ offset: 0, opacity: backdropValue },
59+
{ offset: 0, opacity: backdropOpacityValue },
6160
{ offset: backdropBreakpoint!, opacity: 0 },
6261
{ offset: 1, opacity: 0 },
6362
];

core/src/components/modal/gestures/sheet.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,19 @@ export const createSheetGesture = (
7272
{ offset: 1, opacity: staticBackdropOpacity },
7373
];
7474

75+
let backdropKeyframes = defaultBackdrop;
76+
if (theme === 'ionic') {
77+
backdropKeyframes = ionicThemeBackdrop;
78+
} else if (backdropBreakpoint !== 0) {
79+
backdropKeyframes = customBackdrop;
80+
}
81+
7582
const SheetDefaults = {
7683
WRAPPER_KEYFRAMES: [
7784
{ offset: 0, transform: 'translateY(0%)' },
7885
{ offset: 1, transform: 'translateY(100%)' },
7986
],
80-
BACKDROP_KEYFRAMES:
81-
theme === 'ionic' ? ionicThemeBackdrop : backdropBreakpoint !== 0 ? customBackdrop : defaultBackdrop,
87+
BACKDROP_KEYFRAMES: backdropKeyframes,
8288
};
8389

8490
const contentEl = baseEl.querySelector('ion-content');

core/src/components/modal/modal-interface.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OverlayOptions } from '@utils/overlays-interface';
22

3-
import type { ComponentProps, ComponentRef, FrameworkDelegate, Theme } from '../../interface';
3+
import type { ComponentProps, ComponentRef, FrameworkDelegate } from '../../interface';
44

55
export interface ModalOptions<T extends ComponentRef = ComponentRef> extends OverlayOptions {
66
component: T;
@@ -27,7 +27,8 @@ export interface ModalAnimationOptions {
2727
presentingEl?: HTMLElement;
2828
currentBreakpoint?: number;
2929
backdropBreakpoint?: number;
30-
theme: Theme;
30+
initialBackdropOpacity?: string;
31+
backdropOpacityValue?: string;
3132
}
3233

3334
export interface ModalBreakpointChangeEventDetail {

core/src/components/modal/modal.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import type { MoveSheetToBreakpointOptions } from './gestures/sheet';
4444
import { createSheetGesture } from './gestures/sheet';
4545
import { createSwipeToCloseGesture } from './gestures/swipe-to-close';
4646
import type { ModalBreakpointChangeEventDetail, ModalHandleBehavior } from './modal-interface';
47-
import { setCardStatusBarDark, setCardStatusBarDefault } from './utils';
47+
import { setCardStatusBarDark, setCardStatusBarDefault, staticBackdropOpacity } from './utils';
4848

4949
// TODO(FW-2832): types
5050

@@ -83,6 +83,10 @@ export class Modal implements ComponentInterface, OverlayInterface {
8383
private inheritedAttributes: Attributes = {};
8484
private statusBarStyle?: StatusBarStyle;
8585

86+
get theme(): Theme {
87+
return getIonTheme(this);
88+
}
89+
8690
private inline = false;
8791
private workingDelegate?: FrameworkDelegate;
8892

@@ -574,7 +578,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
574578
presentingEl: presentingElement,
575579
currentBreakpoint: this.initialBreakpoint,
576580
backdropBreakpoint: this.backdropBreakpoint,
577-
theme: getIonTheme(this),
581+
initialBackdropOpacity: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
582+
backdropOpacityValue: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
578583
});
579584

580585
/* tslint:disable-next-line */
@@ -792,7 +797,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
792797
presentingEl: presentingElement,
793798
currentBreakpoint: this.currentBreakpoint ?? this.initialBreakpoint,
794799
backdropBreakpoint: this.backdropBreakpoint,
795-
theme: getIonTheme(this),
800+
initialBackdropOpacity: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
801+
backdropOpacityValue: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
796802
}
797803
);
798804

@@ -1048,14 +1054,12 @@ interface ModalOverlayOptions {
10481054
*/
10491055
currentBreakpoint?: number;
10501056
/**
1051-
* The point after which the backdrop will being
1057+
* The point after which the backdrop will begin
10521058
* to fade in when using a sheet modal.
10531059
*/
10541060
backdropBreakpoint: number;
1055-
/**
1056-
* The theme used by the sheet modal
1057-
*/
1058-
theme: Theme;
1061+
initialBackdropOpacity?: string;
1062+
backdropOpacityValue?: string;
10591063
}
10601064

10611065
type ModalPresentOptions = ModalOverlayOptions;

core/src/components/modal/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { win } from '@utils/browser';
22
import { StatusBar, Style } from '@utils/native/status-bar';
33

4-
export const staticBackdropOpacity = 0.7;
4+
export const staticBackdropOpacity = '0.7';
55

66
/**
77
* Use y = mx + b to

0 commit comments

Comments
 (0)