@@ -44,6 +44,7 @@ const BottomSheetModalComponent = forwardRef<
44
44
stackBehavior = DEFAULT_STACK_BEHAVIOR ,
45
45
enableDismissOnClose = DEFAULT_ENABLE_DISMISS_ON_CLOSE ,
46
46
onDismiss : _providedOnDismiss ,
47
+ onAnimate : _providedOnAnimate ,
47
48
48
49
// bottom sheet props
49
50
index = 0 ,
@@ -78,6 +79,7 @@ const BottomSheetModalComponent = forwardRef<
78
79
//#region refs
79
80
const bottomSheetRef = useRef < BottomSheet > ( null ) ;
80
81
const currentIndexRef = useRef ( ! animateOnMount ? index : - 1 ) ;
82
+ const nextIndexRef = useRef < number | null > ( null ) ;
81
83
const restoreIndexRef = useRef ( - 1 ) ;
82
84
const minimized = useRef ( false ) ;
83
85
const forcedDismissed = useRef ( false ) ;
@@ -225,16 +227,27 @@ const BottomSheetModalComponent = forwardRef<
225
227
} ,
226
228
} ) ;
227
229
}
230
+
231
+ const animating = nextIndexRef . current != null ;
232
+
228
233
/**
229
- * if modal is already been dismiss, we exit the method.
234
+ * early exit, if not minimized, it is in closed position and not animating
230
235
*/
231
- if ( currentIndexRef . current === - 1 && minimized . current === false ) {
236
+ if (
237
+ currentIndexRef . current === - 1 &&
238
+ minimized . current === false &&
239
+ ! animating
240
+ ) {
232
241
return ;
233
242
}
234
243
244
+ /**
245
+ * unmount and early exit, if minimized or it is in closed position and not animating
246
+ */
235
247
if (
236
- minimized . current ||
237
- ( currentIndexRef . current === - 1 && enablePanDownToClose )
248
+ ! animating &&
249
+ ( minimized . current ||
250
+ ( currentIndexRef . current === - 1 && enablePanDownToClose ) )
238
251
) {
239
252
unmount ( ) ;
240
253
return ;
@@ -355,13 +368,24 @@ const BottomSheetModalComponent = forwardRef<
355
368
} ) ;
356
369
}
357
370
currentIndexRef . current = _index ;
371
+ nextIndexRef . current = null ;
358
372
359
373
if ( _providedOnChange ) {
360
374
_providedOnChange ( _index , _position , _type ) ;
361
375
}
362
376
} ,
363
377
[ _providedOnChange ]
364
378
) ;
379
+ const handleBottomSheetOnAnimate = useCallback (
380
+ ( fromIndex : number , toIndex : number ) => {
381
+ nextIndexRef . current = toIndex ;
382
+
383
+ if ( _providedOnAnimate ) {
384
+ _providedOnAnimate ( fromIndex , toIndex ) ;
385
+ }
386
+ } ,
387
+ [ _providedOnAnimate ]
388
+ ) ;
365
389
// biome-ignore lint/correctness/useExhaustiveDependencies(BottomSheetModal.name): used for debug only
366
390
const handleBottomSheetOnClose = useCallback (
367
391
function handleBottomSheetOnClose ( ) {
@@ -429,6 +453,7 @@ const BottomSheetModalComponent = forwardRef<
429
453
containerOffset = { containerOffset }
430
454
onChange = { handleBottomSheetOnChange }
431
455
onClose = { handleBottomSheetOnClose }
456
+ onAnimate = { handleBottomSheetOnAnimate }
432
457
$modal = { true }
433
458
>
434
459
{ typeof Content === 'function' ? < Content data = { data } /> : Content }
0 commit comments