Skip to content

Commit 176585f

Browse files
authored
fix(modal): swipe to dismiss resets status bar style (#28110)
Issue number: resolves #28105 --------- <!-- 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? <!-- Please describe the current behavior that you are modifying. --> When swiping to dismiss the card modal, the status bar style is reset too late. Since we are using 1 animation for the card modal, the dismiss animation is played _then_ the `dismiss` method is called (which resets the status bar style). This means the status bar style is wrong for the duration of the dismiss animation. This does not impact dragging to close the modal such that the status bar changes mid-gesture or calling the `dismiss` method directly -- only quickly swiping to dismiss. Also one of the changes in core/src/components/modal/modal.tsx accidentally changed the modal behavior so that the status bar is changed _after_ the present transition finishes. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - When the card modal is swiped to dismiss the `onDismiss` callback will also reset the status bar style. - When the card modal is presented the status bar is set correctly as the animation begins | `main` | branch | | - | - | | <video src="https://github.com/ionic-team/ionic-framework/assets/2721089/8a18419d-a7ec-4629-8632-62e2ed401912"></video> | <video src="https://github.com/ionic-team/ionic-framework/assets/2721089/62ffcf00-8dbd-4e0c-83a3-5af5d463bccc"></video> | ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev build: `7.3.3-dev.11693592322.138d91e6`
1 parent 38c4da3 commit 176585f

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

core/src/components/modal/modal.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,19 @@ export class Modal implements ComponentInterface, OverlayInterface {
473473

474474
writeTask(() => this.el.classList.add('show-modal'));
475475

476+
const hasCardModal = presentingElement !== undefined;
477+
478+
/**
479+
* We need to change the status bar at the
480+
* start of the animation so that it completes
481+
* by the time the card animation is done.
482+
*/
483+
if (hasCardModal && getIonMode(this) === 'ios') {
484+
// Cache the original status bar color before the modal is presented
485+
this.statusBarStyle = await StatusBar.getStyle();
486+
setCardStatusBarDark();
487+
}
488+
476489
await present<ModalPresentOptions>(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation, {
477490
presentingEl: presentingElement,
478491
currentBreakpoint: this.initialBreakpoint,
@@ -511,19 +524,6 @@ export class Modal implements ComponentInterface, OverlayInterface {
511524
window.addEventListener(KEYBOARD_DID_OPEN, this.keyboardOpenCallback);
512525
}
513526

514-
const hasCardModal = presentingElement !== undefined;
515-
516-
/**
517-
* We need to change the status bar at the
518-
* start of the animation so that it completes
519-
* by the time the card animation is done.
520-
*/
521-
if (hasCardModal && getIonMode(this) === 'ios') {
522-
// Cache the original status bar color before the modal is presented
523-
this.statusBarStyle = await StatusBar.getStyle();
524-
setCardStatusBarDark();
525-
}
526-
527527
if (this.isSheetModal) {
528528
this.initSheetGesture();
529529
} else if (hasCardModal) {
@@ -566,6 +566,16 @@ export class Modal implements ComponentInterface, OverlayInterface {
566566
* removed from the DOM.
567567
*/
568568
this.gestureAnimationDismissing = true;
569+
570+
/**
571+
* Reset the status bar style as the dismiss animation
572+
* starts otherwise the status bar will be the wrong
573+
* color for the duration of the dismiss animation.
574+
* The dismiss method does this as well, but
575+
* in this case it's only called once the animation
576+
* has finished.
577+
*/
578+
setCardStatusBarDefault(this.statusBarStyle);
569579
this.animation!.onFinish(async () => {
570580
await this.dismiss(undefined, GESTURE);
571581
this.gestureAnimationDismissing = false;

0 commit comments

Comments
 (0)