Skip to content

Commit 0b18b6e

Browse files
feat(modal): add static backdrop behaviour when using ionic theme (#29932)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? The modal's backdrop opacity changes dynamically according to the current breakpoint, independently of what theme is being used. ## What is the new behavior? - The modal's backdrop opacity is now static once it has finished entering the screen and while dragging the modal's handle. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
1 parent d8bdf39 commit 0b18b6e

File tree

30 files changed

+30
-15
lines changed

30 files changed

+30
-15
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ 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-
const initialBackdrop = shouldShowBackdrop ? `calc(var(--backdrop-opacity) * ${currentBreakpoint!})` : '0';
15+
const initialBackdrop = shouldShowBackdrop
16+
? `calc(var(--backdrop-opacity) * ${staticBackdropOpacity ? 1 : currentBreakpoint!})`
17+
: '0';
1618

1719
const backdropAnimation = createAnimation('backdropAnimation').fromTo('opacity', 0, initialBackdrop);
1820

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ export const createSheetGesture = (
5151
breakpoints: number[] = [],
5252
getCurrentBreakpoint: () => number,
5353
onDismiss: () => void,
54-
onBreakpointChange: (breakpoint: number) => void
54+
onBreakpointChange: (breakpoint: number) => void,
55+
staticBackdropOpacity: boolean
5556
) => {
5657
// Defaults for the sheet swipe animation
5758
const defaultBackdrop = [
5859
{ offset: 0, opacity: 'var(--backdrop-opacity)' },
59-
{ offset: 1, opacity: 0.01 },
60+
{ offset: 1, opacity: staticBackdropOpacity ? 'var(--backdrop-opacity)' : 0.01 },
6061
];
6162

6263
const customBackdrop = [
6364
{ offset: 0, opacity: 'var(--backdrop-opacity)' },
64-
{ offset: 1 - backdropBreakpoint, opacity: 0 },
65-
{ offset: 1, opacity: 0 },
65+
{ offset: 1 - backdropBreakpoint, opacity: staticBackdropOpacity ? 'var(--backdrop-opacity)' : 0 },
66+
{ offset: 1, opacity: staticBackdropOpacity ? 'var(--backdrop-opacity)' : 0 },
6667
];
6768

6869
const SheetDefaults = {
@@ -312,14 +313,15 @@ export const createSheetGesture = (
312313
backdropAnimation.keyframes([
313314
{
314315
offset: 0,
315-
opacity: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(
316-
1 - breakpointOffset,
317-
backdropBreakpoint
318-
)})`,
316+
opacity: staticBackdropOpacity
317+
? 'var(--backdrop-opacity)'
318+
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(1 - breakpointOffset, backdropBreakpoint)})`,
319319
},
320320
{
321321
offset: 1,
322-
opacity: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(snapToBreakpoint, backdropBreakpoint)})`,
322+
opacity: staticBackdropOpacity
323+
? 'var(--backdrop-opacity)'
324+
: `calc(var(--backdrop-opacity) * ${getBackdropValueForSheet(snapToBreakpoint, backdropBreakpoint)})`,
323325
},
324326
]);
325327

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface ModalAnimationOptions {
2727
presentingEl?: HTMLElement;
2828
currentBreakpoint?: number;
2929
backdropBreakpoint?: number;
30+
staticBackdropOpacity?: boolean;
3031
}
3132

3233
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
573573
presentingEl: presentingElement,
574574
currentBreakpoint: this.initialBreakpoint,
575575
backdropBreakpoint: this.backdropBreakpoint,
576+
staticBackdropOpacity: getIonTheme(this) === 'ionic',
576577
});
577578

578579
/* tslint:disable-next-line */
@@ -679,6 +680,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
679680
presentingEl: this.presentingElement,
680681
currentBreakpoint: initialBreakpoint,
681682
backdropBreakpoint,
683+
staticBackdropOpacity: getIonTheme(this) === 'ionic',
682684
}));
683685

684686
ani.progressStart(true, 1);
@@ -698,7 +700,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
698700
this.currentBreakpoint = breakpoint;
699701
this.ionBreakpointDidChange.emit({ breakpoint });
700702
}
701-
}
703+
},
704+
getIonTheme(this) === 'ionic'
702705
);
703706

704707
this.gesture = gesture;
@@ -1044,10 +1047,17 @@ interface ModalOverlayOptions {
10441047
*/
10451048
currentBreakpoint?: number;
10461049
/**
1047-
* The point after which the backdrop will being
1050+
* The point after which the backdrop will begin
10481051
* to fade in when using a sheet modal.
10491052
*/
10501053
backdropBreakpoint: number;
1054+
/**
1055+
* Defines whether the backdrop should have a
1056+
* static opacity = var(--backdrop-opacity).
1057+
* This option is true only when the widget
1058+
* is using the ionic theme.
1059+
*/
1060+
staticBackdropOpacity?: boolean;
10511061
}
10521062

10531063
type ModalPresentOptions = ModalOverlayOptions;

core/src/components/modal/test/basic/modal.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
6060
});
6161
});
6262

63-
configs().forEach(({ title, screenshot, config }) => {
63+
configs({ modes: ['ios', 'md', 'ionic-md'] }).forEach(({ title, screenshot, config }) => {
6464
test.describe(title('modal: rendering'), () => {
6565
const runVisualTests = async (page: E2EPage, screenshotModifier = '') => {
6666
await page.goto('/src/components/modal/test/basic', config);
13 KB
Loading
20.5 KB
Loading
12.5 KB
Loading
13 KB
Loading

0 commit comments

Comments
 (0)