Skip to content

Commit 1f69625

Browse files
committed
fix: resume close animation when container gets resized (#1374) (#1392)
1 parent 67e1e09 commit 1f69625

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/components/bottomSheet/BottomSheet.tsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
685685
currentPosition: animatedPosition.value,
686686
position,
687687
velocity,
688+
animatedContainerHeight: animatedContainerHeight.value,
688689
},
689690
});
690691

@@ -1297,6 +1298,31 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
12971298
const _previousSnapPoints = _previousResult?.snapPoints;
12981299
const _previousContainerHeight = _previousResult?.containerHeight;
12991300

1301+
let nextPosition;
1302+
let animationConfig;
1303+
let animationSource = ANIMATION_SOURCE.SNAP_POINT_CHANGE;
1304+
1305+
/**
1306+
* if the bottom sheet is closing and the container gets resized,
1307+
* then we restart the closing animation to the new position.
1308+
*/
1309+
if (
1310+
animatedAnimationState.value === ANIMATION_STATE.RUNNING &&
1311+
animatedNextPositionIndex.value === -1 &&
1312+
_previousContainerHeight !== containerHeight
1313+
) {
1314+
animationSource = ANIMATION_SOURCE.CONTAINER_RESIZE;
1315+
animationConfig = {
1316+
duration: 0,
1317+
};
1318+
animateToPosition(
1319+
containerHeight,
1320+
animationSource,
1321+
0,
1322+
animationConfig
1323+
);
1324+
}
1325+
13001326
if (
13011327
JSON.stringify(snapPoints) === JSON.stringify(_previousSnapPoints) ||
13021328
!isLayoutCalculated.value ||
@@ -1314,10 +1340,6 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13141340
},
13151341
});
13161342

1317-
let nextPosition;
1318-
let animationConfig;
1319-
let animationSource = ANIMATION_SOURCE.SNAP_POINT_CHANGE;
1320-
13211343
/**
13221344
* if snap points changed while sheet is animating, then
13231345
* we stop the animation and animate to the updated point.

0 commit comments

Comments
 (0)