Skip to content

Commit a6c9e55

Browse files
authored
fix(modal): status bar style defaults to app settings (#26291)
Resolves #26173
1 parent dd727db commit a6c9e55

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

core/src/components/modal/gestures/swipe-to-close.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import type { GestureDetail } from '../../../utils/gesture';
1010
import { createGesture } from '../../../utils/gesture';
1111
import { clamp, getElementRoot } from '../../../utils/helpers';
12+
import type { Style as StatusBarStyle } from '../../../utils/native/status-bar';
1213
import { setCardStatusBarDark, setCardStatusBarDefault } from '../utils';
1314

1415
import { calculateSpringStep, handleCanDismiss } from './utils';
@@ -18,7 +19,12 @@ export const SwipeToCloseDefaults = {
1819
MIN_PRESENTING_SCALE: 0.93,
1920
};
2021

21-
export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: Animation, onDismiss: () => void) => {
22+
export const createSwipeToCloseGesture = (
23+
el: HTMLIonModalElement,
24+
animation: Animation,
25+
statusBarStyle: StatusBarStyle,
26+
onDismiss: () => void
27+
) => {
2228
/**
2329
* The step value at which a card modal
2430
* is eligible for dismissing via gesture.
@@ -173,14 +179,14 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
173179
* should block the gesture from
174180
* proceeding,
175181
*/
176-
const isAttempingDismissWithCanDismiss = step >= 0 && canDismissBlocksGesture;
182+
const isAttemptingDismissWithCanDismiss = step >= 0 && canDismissBlocksGesture;
177183

178184
/**
179185
* If we are blocking the gesture from dismissing,
180186
* set the max step value so that the sheet cannot be
181187
* completely hidden.
182188
*/
183-
const maxStep = isAttempingDismissWithCanDismiss ? canDismissMaxStep : 0.9999;
189+
const maxStep = isAttemptingDismissWithCanDismiss ? canDismissMaxStep : 0.9999;
184190

185191
/**
186192
* If we are blocking the gesture from
@@ -190,7 +196,7 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
190196
* Note that the starting breakpoint is always 0,
191197
* so we omit adding 0 to the result.
192198
*/
193-
const processedStep = isAttempingDismissWithCanDismiss ? calculateSpringStep(step / maxStep) : step;
199+
const processedStep = isAttemptingDismissWithCanDismiss ? calculateSpringStep(step / maxStep) : step;
194200

195201
const clampedStep = clamp(0.0001, processedStep, maxStep);
196202

@@ -205,7 +211,7 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
205211
* crossed a certain threshold.
206212
*/
207213
if (clampedStep >= DISMISS_THRESHOLD && lastStep < DISMISS_THRESHOLD) {
208-
setCardStatusBarDefault();
214+
setCardStatusBarDefault(statusBarStyle);
209215

210216
/**
211217
* However, if we swipe back up, then the
@@ -223,10 +229,10 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
223229
const velocity = detail.velocityY;
224230
const step = detail.deltaY / height;
225231

226-
const isAttempingDismissWithCanDismiss = step >= 0 && canDismissBlocksGesture;
227-
const maxStep = isAttempingDismissWithCanDismiss ? canDismissMaxStep : 0.9999;
232+
const isAttemptingDismissWithCanDismiss = step >= 0 && canDismissBlocksGesture;
233+
const maxStep = isAttemptingDismissWithCanDismiss ? canDismissMaxStep : 0.9999;
228234

229-
const processedStep = isAttempingDismissWithCanDismiss ? calculateSpringStep(step / maxStep) : step;
235+
const processedStep = isAttemptingDismissWithCanDismiss ? calculateSpringStep(step / maxStep) : step;
230236

231237
const clampedStep = clamp(0.0001, processedStep, maxStep);
232238

@@ -238,7 +244,7 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
238244
* animation can never complete until
239245
* canDismiss is checked.
240246
*/
241-
const shouldComplete = !isAttempingDismissWithCanDismiss && threshold >= DISMISS_THRESHOLD;
247+
const shouldComplete = !isAttemptingDismissWithCanDismiss && threshold >= DISMISS_THRESHOLD;
242248
let newStepValue = shouldComplete ? -0.001 : 0.001;
243249

244250
if (!shouldComplete) {
@@ -280,7 +286,7 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
280286
* check canDismiss. 25% was chosen
281287
* to avoid accidental swipes.
282288
*/
283-
if (isAttempingDismissWithCanDismiss && clampedStep > maxStep / 4) {
289+
if (isAttemptingDismissWithCanDismiss && clampedStep > maxStep / 4) {
284290
handleCanDismiss(el, animation);
285291
} else if (shouldComplete) {
286292
onDismiss();

core/src/components/modal/modal.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { raf, inheritAttributes } from '../../utils/helpers';
2222
import type { Attributes } from '../../utils/helpers';
2323
import { KEYBOARD_DID_OPEN } from '../../utils/keyboard/keyboard';
2424
import { printIonWarning } from '../../utils/logging';
25+
import { Style as StatusBarStyle, StatusBar } from '../../utils/native/status-bar';
2526
import { BACKDROP, activeAnimations, dismiss, eventMethod, prepareOverlay, present } from '../../utils/overlays';
2627
import { getClassMap } from '../../utils/theme';
2728
import { deepReady } from '../../utils/transition';
@@ -68,6 +69,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
6869
private keyboardOpenCallback?: () => void;
6970
private moveSheetToBreakpoint?: (options: MoveSheetToBreakpointOptions) => Promise<void>;
7071
private inheritedAttributes: Attributes = {};
72+
private statusBarStyle?: StatusBarStyle;
7173

7274
private inline = false;
7375
private workingDelegate?: FrameworkDelegate;
@@ -519,14 +521,16 @@ export class Modal implements ComponentInterface, OverlayInterface {
519521
* If we did not do this check, then not using swipeToClose would mean you could
520522
* not run canDismiss on swipe as there would be no swipe gesture created.
521523
*/
522-
const hasCardModal = this.swipeToClose || (this.canDismiss !== undefined && this.presentingElement !== undefined);
524+
const hasCardModal = this.presentingElement !== undefined && (this.swipeToClose || this.canDismiss !== undefined);
523525

524526
/**
525527
* We need to change the status bar at the
526528
* start of the animation so that it completes
527529
* by the time the card animation is done.
528530
*/
529531
if (hasCardModal && getIonMode(this) === 'ios') {
532+
// Cache the original status bar color before the modal is presented
533+
this.statusBarStyle = await StatusBar.getStyle();
530534
setCardStatusBarDark();
531535
}
532536

@@ -584,7 +588,9 @@ export class Modal implements ComponentInterface, OverlayInterface {
584588
return;
585589
}
586590

587-
this.gesture = createSwipeToCloseGesture(el, ani, () => {
591+
const statusBarStyle = this.statusBarStyle ?? StatusBarStyle.Default;
592+
593+
this.gesture = createSwipeToCloseGesture(el, ani, statusBarStyle, () => {
588594
/**
589595
* While the gesture animation is finishing
590596
* it is possible for a user to tap the backdrop.
@@ -691,9 +697,9 @@ export class Modal implements ComponentInterface, OverlayInterface {
691697
* finishes when the dismiss animation does.
692698
* TODO (FW-937)
693699
*/
694-
const hasCardModal = this.swipeToClose || (this.canDismiss !== undefined && this.presentingElement !== undefined);
700+
const hasCardModal = this.presentingElement !== undefined && (this.swipeToClose || this.canDismiss !== undefined);
695701
if (hasCardModal && getIonMode(this) === 'ios') {
696-
setCardStatusBarDefault();
702+
setCardStatusBarDefault(this.statusBarStyle);
697703
}
698704

699705
/* tslint:disable-next-line */

core/src/components/modal/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ export const setCardStatusBarDark = () => {
8181
StatusBar.setStyle({ style: Style.Dark });
8282
};
8383

84-
export const setCardStatusBarDefault = () => {
84+
export const setCardStatusBarDefault = (defaultStyle = Style.Default) => {
8585
if (!win || win.innerWidth >= 768 || !StatusBar.supportsDefaultStatusBarStyle()) {
8686
return;
8787
}
8888

89-
StatusBar.setStyle({ style: Style.Default });
89+
StatusBar.setStyle({ style: defaultStyle });
9090
};

core/src/utils/native/status-bar.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ export const StatusBar = {
3131

3232
engine.setStyle(options);
3333
},
34+
getStyle: async function (): Promise<Style> {
35+
const engine = this.getEngine();
36+
if (!engine) {
37+
return Style.Default;
38+
}
39+
const { style } = await engine.getInfo();
40+
return style;
41+
},
3442
};

0 commit comments

Comments
 (0)