Skip to content

Commit 9fa854d

Browse files
Following @tanner-reits' suggested approach & fixing snapshot tests
1 parent 2afe4b9 commit 9fa854d

File tree

27 files changed

+43
-88
lines changed

27 files changed

+43
-88
lines changed

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@ import type { ModalAnimationOptions } from '../modal-interface';
44
import { getBackdropValueForSheet } from '../utils';
55

66
export const createSheetEnterAnimation = (opts: ModalAnimationOptions) => {
7-
const { currentBreakpoint, backdropBreakpoint } = opts;
7+
const { currentBreakpoint, backdropBreakpoint, staticBackdropOpacity } = opts;
88

99
/**
1010
* If the backdropBreakpoint is undefined, then the backdrop
1111
* should always fade in. If the backdropBreakpoint came before the
1212
* current breakpoint, then the backdrop should be fading in.
1313
*/
1414
const shouldShowBackdrop = backdropBreakpoint === undefined || backdropBreakpoint < currentBreakpoint!;
15-
16-
let initialBackdropOpacity = '0';
17-
if (opts.initialBackdropOpacity) {
18-
initialBackdropOpacity = opts.initialBackdropOpacity;
19-
} else if (shouldShowBackdrop) {
20-
initialBackdropOpacity = `calc(var(--backdrop-opacity) * ${currentBreakpoint!})`;
21-
}
22-
23-
const backdropAnimation = createAnimation('backdropAnimation').fromTo('opacity', 0, initialBackdropOpacity);
15+
const initialBackdrop = shouldShowBackdrop
16+
? `calc(var(--backdrop-opacity) * ${staticBackdropOpacity ? 1 : currentBreakpoint!})`
17+
: '0';
18+
console.log('initial backdrop', initialBackdrop);
19+
const backdropAnimation = createAnimation('backdropAnimation').fromTo('opacity', 0, initialBackdrop);
2420

2521
if (shouldShowBackdrop) {
2622
backdropAnimation
@@ -46,17 +42,17 @@ export const createSheetLeaveAnimation = (opts: ModalAnimationOptions) => {
4642
* is defined, so we need to account for that offset by figuring out
4743
* what the current backdrop value should be.
4844
*/
49-
const backdropOpacityValue = opts.backdropOpacityValue
50-
? opts.backdropOpacityValue
51-
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(currentBreakpoint!, backdropBreakpoint!)})`;
52-
45+
const backdropValue = `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(
46+
currentBreakpoint!,
47+
backdropBreakpoint!
48+
)})`;
5349
const defaultBackdrop = [
54-
{ offset: 0, opacity: backdropOpacityValue },
50+
{ offset: 0, opacity: backdropValue },
5551
{ offset: 1, opacity: 0 },
5652
];
5753

5854
const customBackdrop = [
59-
{ offset: 0, opacity: backdropOpacityValue },
55+
{ offset: 0, opacity: backdropValue },
6056
{ offset: backdropBreakpoint!, opacity: 0 },
6157
{ offset: 1, opacity: 0 },
6258
];

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

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { getIonTheme } from '@global/ionic-global';
21
import { isIonContent, findClosestIonContent } from '@utils/content';
32
import { createGesture } from '@utils/gesture';
43
import { clamp, raf, getElementRoot } from '@utils/helpers';
54
import { FOCUS_TRAP_DISABLE_CLASS } from '@utils/overlays';
65

76
import type { Animation } from '../../../interface';
87
import type { GestureDetail } from '../../../utils/gesture';
9-
import { getBackdropValueForSheet, staticBackdropOpacity } from '../utils';
8+
import { getBackdropValueForSheet } from '../utils';
109

1110
import { calculateSpringStep, handleCanDismiss } from './utils';
1211

@@ -52,39 +51,27 @@ export const createSheetGesture = (
5251
breakpoints: number[] = [],
5352
getCurrentBreakpoint: () => number,
5453
onDismiss: () => void,
55-
onBreakpointChange: (breakpoint: number) => void
54+
onBreakpointChange: (breakpoint: number) => void,
55+
staticBackdropOpacity: boolean
5656
) => {
57-
const theme = getIonTheme(baseEl);
5857
// Defaults for the sheet swipe animation
5958
const defaultBackdrop = [
6059
{ offset: 0, opacity: 'var(--backdrop-opacity)' },
61-
{ offset: 1, opacity: 0.01 },
60+
{ offset: 1, opacity: staticBackdropOpacity ? 'var(--backdrop-opacity)' : 0.01 },
6261
];
6362

6463
const customBackdrop = [
6564
{ offset: 0, opacity: 'var(--backdrop-opacity)' },
66-
{ offset: 1 - backdropBreakpoint, opacity: 0 },
67-
{ offset: 1, opacity: 0 },
65+
{ offset: 1 - backdropBreakpoint, opacity: staticBackdropOpacity ? 'var(--backdrop-opacity)' : 0 },
66+
{ offset: 1, opacity: staticBackdropOpacity ? 'var(--backdrop-opacity)' : 0 },
6867
];
6968

70-
const ionicThemeBackdrop = [
71-
{ offset: 0, opacity: staticBackdropOpacity },
72-
{ offset: 1, opacity: staticBackdropOpacity },
73-
];
74-
75-
let backdropKeyframes = defaultBackdrop;
76-
if (theme === 'ionic') {
77-
backdropKeyframes = ionicThemeBackdrop;
78-
} else if (backdropBreakpoint !== 0) {
79-
backdropKeyframes = customBackdrop;
80-
}
81-
8269
const SheetDefaults = {
8370
WRAPPER_KEYFRAMES: [
8471
{ offset: 0, transform: 'translateY(0%)' },
8572
{ offset: 1, transform: 'translateY(100%)' },
8673
],
87-
BACKDROP_KEYFRAMES: backdropKeyframes,
74+
BACKDROP_KEYFRAMES: backdropBreakpoint !== 0 ? customBackdrop : defaultBackdrop,
8875
};
8976

9077
const contentEl = baseEl.querySelector('ion-content');
@@ -323,35 +310,20 @@ export const createSheetGesture = (
323310
{ offset: 1, transform: `translateY(${(1 - snapToBreakpoint) * 100}%)` },
324311
]);
325312

326-
backdropAnimation.keyframes(
327-
theme === 'ionic'
328-
? [
329-
{
330-
offset: 0,
331-
opacity: staticBackdropOpacity,
332-
},
333-
{
334-
offset: 1,
335-
opacity: staticBackdropOpacity,
336-
},
337-
]
338-
: [
339-
{
340-
offset: 0,
341-
opacity: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(
342-
1 - breakpointOffset,
343-
backdropBreakpoint
344-
)})`,
345-
},
346-
{
347-
offset: 1,
348-
opacity: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(
349-
snapToBreakpoint,
350-
backdropBreakpoint
351-
)})`,
352-
},
353-
]
354-
);
313+
backdropAnimation.keyframes([
314+
{
315+
offset: 0,
316+
opacity: staticBackdropOpacity
317+
? 'var(--backdrop-opacity)'
318+
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(1 - breakpointOffset, backdropBreakpoint)})`,
319+
},
320+
{
321+
offset: 1,
322+
opacity: staticBackdropOpacity
323+
? 'var(--backdrop-opacity)'
324+
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(snapToBreakpoint, backdropBreakpoint)})`,
325+
},
326+
]);
355327

356328
animation.progressStep(0);
357329
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export interface ModalAnimationOptions {
2727
presentingEl?: HTMLElement;
2828
currentBreakpoint?: number;
2929
backdropBreakpoint?: number;
30-
initialBackdropOpacity?: string;
31-
backdropOpacityValue?: string;
30+
staticBackdropOpacity?: boolean;
3231
}
3332

3433
export interface ModalBreakpointChangeEventDetail {

core/src/components/modal/modal.ionic.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:host {
88
--background: #{globals.$ionic-color-base-white};
99
--box-shadow: #{globals.$ionic-elevation-300};
10-
--backdrop-opacity: 1;
10+
--backdrop-opacity: 0.7;
1111

1212
color: globals.$ionic-color-neutral-1200;
1313
}

core/src/components/modal/modal.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import type {
3131
FrameworkDelegate,
3232
Gesture,
3333
OverlayInterface,
34-
Theme,
3534
} from '../../interface';
3635
import { KEYBOARD_DID_OPEN } from '../../utils/keyboard/keyboard';
3736
import type { OverlayEventDetail } from '../../utils/overlays-interface';
@@ -44,7 +43,7 @@ import type { MoveSheetToBreakpointOptions } from './gestures/sheet';
4443
import { createSheetGesture } from './gestures/sheet';
4544
import { createSwipeToCloseGesture } from './gestures/swipe-to-close';
4645
import type { ModalBreakpointChangeEventDetail, ModalHandleBehavior } from './modal-interface';
47-
import { setCardStatusBarDark, setCardStatusBarDefault, staticBackdropOpacity } from './utils';
46+
import { setCardStatusBarDark, setCardStatusBarDefault } from './utils';
4847

4948
// TODO(FW-2832): types
5049

@@ -83,10 +82,6 @@ export class Modal implements ComponentInterface, OverlayInterface {
8382
private inheritedAttributes: Attributes = {};
8483
private statusBarStyle?: StatusBarStyle;
8584

86-
get theme(): Theme {
87-
return getIonTheme(this);
88-
}
89-
9085
private inline = false;
9186
private workingDelegate?: FrameworkDelegate;
9287

@@ -578,8 +573,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
578573
presentingEl: presentingElement,
579574
currentBreakpoint: this.initialBreakpoint,
580575
backdropBreakpoint: this.backdropBreakpoint,
581-
initialBackdropOpacity: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
582-
backdropOpacityValue: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
576+
staticBackdropOpacity: getIonTheme(this) === 'ionic',
583577
});
584578

585579
/* tslint:disable-next-line */
@@ -686,7 +680,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
686680
presentingEl: this.presentingElement,
687681
currentBreakpoint: initialBreakpoint,
688682
backdropBreakpoint,
689-
theme: getIonTheme(this),
683+
staticBackdropOpacity: getIonTheme(this) === 'ionic',
690684
}));
691685

692686
ani.progressStart(true, 1);
@@ -706,7 +700,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
706700
this.currentBreakpoint = breakpoint;
707701
this.ionBreakpointDidChange.emit({ breakpoint });
708702
}
709-
}
703+
},
704+
getIonTheme(this) === 'ionic'
710705
);
711706

712707
this.gesture = gesture;
@@ -797,8 +792,6 @@ export class Modal implements ComponentInterface, OverlayInterface {
797792
presentingEl: presentingElement,
798793
currentBreakpoint: this.currentBreakpoint ?? this.initialBreakpoint,
799794
backdropBreakpoint: this.backdropBreakpoint,
800-
initialBackdropOpacity: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
801-
backdropOpacityValue: this.theme === 'ionic' ? staticBackdropOpacity : undefined,
802795
}
803796
);
804797

@@ -1059,13 +1052,10 @@ interface ModalOverlayOptions {
10591052
*/
10601053
backdropBreakpoint: number;
10611054
/**
1062-
* The initial backdrop opacity value
1063-
*/
1064-
initialBackdropOpacity?: string;
1065-
/**
1066-
* The current backdrop opacity value
1055+
* Defines whether the backdrop should have a
1056+
* static opacity.
10671057
*/
1068-
backdropOpacityValue?: string;
1058+
staticBackdropOpacity?: boolean;
10691059
}
10701060

10711061
type ModalPresentOptions = ModalOverlayOptions;
62 Bytes
Loading
66 Bytes
Loading
117 Bytes
Loading
63 Bytes
Loading
68 Bytes
Loading

0 commit comments

Comments
 (0)