From 176585f446b04a6a0cedab2e09417637dbfc78ee Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 5 Sep 2023 12:15:30 -0400 Subject: [PATCH] fix(modal): swipe to dismiss resets status bar style (#28110) Issue number: resolves #28105 --------- ## What is the current behavior? 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? - 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 | | - | - | | | | ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `7.3.3-dev.11693592322.138d91e6` --- core/src/components/modal/modal.tsx | 36 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/src/components/modal/modal.tsx b/core/src/components/modal/modal.tsx index 0b4a0d3799..3c8a091901 100644 --- a/core/src/components/modal/modal.tsx +++ b/core/src/components/modal/modal.tsx @@ -473,6 +473,19 @@ export class Modal implements ComponentInterface, OverlayInterface { writeTask(() => this.el.classList.add('show-modal')); + const hasCardModal = presentingElement !== undefined; + + /** + * We need to change the status bar at the + * start of the animation so that it completes + * by the time the card animation is done. + */ + if (hasCardModal && getIonMode(this) === 'ios') { + // Cache the original status bar color before the modal is presented + this.statusBarStyle = await StatusBar.getStyle(); + setCardStatusBarDark(); + } + await present(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation, { presentingEl: presentingElement, currentBreakpoint: this.initialBreakpoint, @@ -511,19 +524,6 @@ export class Modal implements ComponentInterface, OverlayInterface { window.addEventListener(KEYBOARD_DID_OPEN, this.keyboardOpenCallback); } - const hasCardModal = presentingElement !== undefined; - - /** - * We need to change the status bar at the - * start of the animation so that it completes - * by the time the card animation is done. - */ - if (hasCardModal && getIonMode(this) === 'ios') { - // Cache the original status bar color before the modal is presented - this.statusBarStyle = await StatusBar.getStyle(); - setCardStatusBarDark(); - } - if (this.isSheetModal) { this.initSheetGesture(); } else if (hasCardModal) { @@ -566,6 +566,16 @@ export class Modal implements ComponentInterface, OverlayInterface { * removed from the DOM. */ this.gestureAnimationDismissing = true; + + /** + * Reset the status bar style as the dismiss animation + * starts otherwise the status bar will be the wrong + * color for the duration of the dismiss animation. + * The dismiss method does this as well, but + * in this case it's only called once the animation + * has finished. + */ + setCardStatusBarDefault(this.statusBarStyle); this.animation!.onFinish(async () => { await this.dismiss(undefined, GESTURE); this.gestureAnimationDismissing = false;