diff --git a/src/components/bottomSheetModal/BottomSheetModal.tsx b/src/components/bottomSheetModal/BottomSheetModal.tsx index 4198cf5d1..40e4d2316 100644 --- a/src/components/bottomSheetModal/BottomSheetModal.tsx +++ b/src/components/bottomSheetModal/BottomSheetModal.tsx @@ -48,6 +48,7 @@ const BottomSheetModalComponent = forwardRef< // callbacks onChange: _providedOnChange, + onAnimate: _providedOnAnimate, // components children: Content, @@ -73,6 +74,7 @@ const BottomSheetModalComponent = forwardRef< const bottomSheetRef = useRef(null); const currentIndexRef = useRef(!animateOnMount ? index : -1); const restoreIndexRef = useRef(-1); + const animatingRef = useRef(!animateOnMount); const minimized = useRef(false); const forcedDismissed = useRef(false); const mounted = useRef(false); @@ -200,7 +202,11 @@ const BottomSheetModalComponent = forwardRef< /** * if modal is already been dismiss, we exit the method. */ - if (currentIndexRef.current === -1 && minimized.current === false) { + if ( + currentIndexRef.current === -1 && + minimized.current === false && + !animatingRef.current + ) { return; } @@ -276,7 +282,11 @@ const BottomSheetModalComponent = forwardRef< /** * if modal is already been dismiss, we exit the method. */ - if (currentIndexRef.current === -1 && minimized.current === false) { + if ( + currentIndexRef.current === -1 && + minimized.current === false && + !animatingRef.current + ) { return; } @@ -300,6 +310,19 @@ const BottomSheetModalComponent = forwardRef< } }, []); + const handleBottomSheetOnAnimate = useCallback( + function handleBottomSheetOnAnimate( + _fromIndex: number, + _toIndex: number, + ) { + animatingRef.current = true; + + if (_providedOnAnimate) { + _providedOnAnimate(_fromIndex, _toIndex); + } + }, + [_providedOnAnimate] + ); const handleBottomSheetOnChange = useCallback( function handleBottomSheetOnChange(_index: number) { print({ @@ -311,6 +334,7 @@ const BottomSheetModalComponent = forwardRef< }, }); currentIndexRef.current = _index; + animatingRef.current = false; if (_providedOnChange) { _providedOnChange(_index); @@ -381,6 +405,7 @@ const BottomSheetModalComponent = forwardRef< containerOffset={containerOffset} onChange={handleBottomSheetOnChange} onClose={handleBottomSheetOnClose} + onAnimate={handleBottomSheetOnAnimate} children={ typeof Content === 'function' ? : Content }