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 4, 2023
1 parent 235466f commit 92ad842
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 @@ -679,6 +679,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
currentPosition: animatedPosition.value,
position,
velocity,
animatedContainerHeight: animatedContainerHeight.value,
},
});

Expand Down Expand Up @@ -1291,6 +1292,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 @@ -1308,10 +1334,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 92ad842

Please sign in to comment.