Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resume close animation when container gets resized (#1374) #1392

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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