99import type { GestureDetail } from '../../../utils/gesture' ;
1010import { createGesture } from '../../../utils/gesture' ;
1111import { clamp , getElementRoot } from '../../../utils/helpers' ;
12+ import { setCardStatusBarDark , setCardStatusBarDefault } from '../utils' ;
1213
1314import { calculateSpringStep , handleCanDismiss } from './utils' ;
1415
@@ -18,13 +19,20 @@ export const SwipeToCloseDefaults = {
1819} ;
1920
2021export const createSwipeToCloseGesture = ( el : HTMLIonModalElement , animation : Animation , onDismiss : ( ) => void ) => {
22+ /**
23+ * The step value at which a card modal
24+ * is eligible for dismissing via gesture.
25+ */
26+ const DISMISS_THRESHOLD = 0.5 ;
27+
2128 const height = el . offsetHeight ;
2229 let isOpen = false ;
2330 let canDismissBlocksGesture = false ;
2431 let contentEl : HTMLElement | null = null ;
2532 let scrollEl : HTMLElement | null = null ;
2633 const canDismissMaxStep = 0.2 ;
2734 let initialScrollY = true ;
35+ let lastStep = 0 ;
2836 const getScrollY = ( ) => {
2937 if ( contentEl && isIonContent ( contentEl ) ) {
3038 return ( contentEl as HTMLIonContentElement ) . scrollY ;
@@ -187,6 +195,28 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
187195 const clampedStep = clamp ( 0.0001 , processedStep , maxStep ) ;
188196
189197 animation . progressStep ( clampedStep ) ;
198+
199+ /**
200+ * When swiping down half way, the status bar style
201+ * should be reset to its default value.
202+ *
203+ * We track lastStep so that we do not fire these
204+ * functions on every onMove, only when the user has
205+ * crossed a certain threshold.
206+ */
207+ if ( clampedStep >= DISMISS_THRESHOLD && lastStep < DISMISS_THRESHOLD ) {
208+ setCardStatusBarDefault ( ) ;
209+
210+ /**
211+ * However, if we swipe back up, then the
212+ * status bar style should be set to have light
213+ * text on a dark background.
214+ */
215+ } else if ( clampedStep < DISMISS_THRESHOLD && lastStep >= DISMISS_THRESHOLD ) {
216+ setCardStatusBarDark ( ) ;
217+ }
218+
219+ lastStep = clampedStep ;
190220 } ;
191221
192222 const onEnd = ( detail : GestureDetail ) => {
@@ -208,7 +238,7 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
208238 * animation can never complete until
209239 * canDismiss is checked.
210240 */
211- const shouldComplete = ! isAttempingDismissWithCanDismiss && threshold >= 0.5 ;
241+ const shouldComplete = ! isAttempingDismissWithCanDismiss && threshold >= DISMISS_THRESHOLD ;
212242 let newStepValue = shouldComplete ? - 0.001 : 0.001 ;
213243
214244 if ( ! shouldComplete ) {
0 commit comments