From 92ad84283afb389ee23768f0c29e7808af4b6b0c Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Sun, 4 Jun 2023 17:38:56 +0200 Subject: [PATCH] fix: resume close animation when container gets resized (#1374) (#1392) --- src/components/bottomSheet/BottomSheet.tsx | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index b1664407..3b1264fb 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -679,6 +679,7 @@ const BottomSheetComponent = forwardRef( currentPosition: animatedPosition.value, position, velocity, + animatedContainerHeight: animatedContainerHeight.value, }, }); @@ -1291,6 +1292,31 @@ const BottomSheetComponent = forwardRef( const _previousSnapPoints = _previousResult?.snapPoints; const _previousContainerHeight = _previousResult?.containerHeight; + let nextPosition; + let animationConfig; + let animationSource = ANIMATION_SOURCE.SNAP_POINT_CHANGE; + + /** + * if the bottom sheet is closing and the container gets resized, + * then we restart the closing animation to the new position. + */ + if ( + animatedAnimationState.value === ANIMATION_STATE.RUNNING && + animatedNextPositionIndex.value === -1 && + _previousContainerHeight !== containerHeight + ) { + animationSource = ANIMATION_SOURCE.CONTAINER_RESIZE; + animationConfig = { + duration: 0, + }; + animateToPosition( + containerHeight, + animationSource, + 0, + animationConfig + ); + } + if ( JSON.stringify(snapPoints) === JSON.stringify(_previousSnapPoints) || !isLayoutCalculated.value || @@ -1308,10 +1334,6 @@ const BottomSheetComponent = forwardRef( }, }); - let nextPosition; - let animationConfig; - let animationSource = ANIMATION_SOURCE.SNAP_POINT_CHANGE; - /** * if snap points changed while sheet is animating, then * we stop the animation and animate to the updated point.