Skip to content

Commit

Permalink
fix: resume close animation when container gets resized (#1374) (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jun 25, 2023
1 parent 67e1e09 commit 1f69625
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
currentPosition: animatedPosition.value,
position,
velocity,
animatedContainerHeight: animatedContainerHeight.value,
},
});

Expand Down Expand Up @@ -1297,6 +1298,31 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
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 ||
Expand All @@ -1314,10 +1340,6 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
},
});

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.
Expand Down

0 comments on commit 1f69625

Please sign in to comment.