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 BottomSheet closing instantly when snapPoints change #1815

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Maniae
Copy link

@Maniae Maniae commented Apr 25, 2024

Please provide enough information so that others can review your pull request:

Motivation

Probably related to #1053

When snapPoints of a bottom sheet change while its animating, it may close it in some situations.
After some investigation, I think the reason for that is the animatedReaction on snapPoints/containerHeight that closes the bottom sheet under these conditions : animatedCurrentIndex.value === -1

The problem being in some cases, when animation complete, the snapPoints change reaction seems to be called right after the completion callback, before any reaction on the animatedPosition. Since the the animatedPosition reaction is the one setting the animatedCurrentIndex value, this old value is used and causes the closing of the bottom sheet.

This fix is a simple line on the completion callback, setting the animatedCurrentIndex value to its goal value.
The previous fix caused an issue where the onChange callback would not fire anymore.

A better fix is to handle the case were the animation is STOPPPED in the snapPoints change listener, and set the new position using the actual animatedIndex value.

@Maniae Maniae changed the title update animatedCurrentIndex on animation completion Fix BottomSheet closing instantly when snapPoints change Apr 25, 2024
@XantreDev
Copy link

XantreDev commented May 1, 2024

I think it's a good idea. Probably it will also fix issues with enableDymanicSizing resize

dynamic-sizing.mp4

@theohdv
Copy link

theohdv commented May 22, 2024

Hey, do you know if it's going to be released soon in V4 ?

@@ -1361,6 +1361,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
animatedNextPositionIndex.value !== -1
? snapPoints[animatedNextPositionIndex.value]
: animatedNextPosition.value;
} else if (animatedAnimationState.value === ANIMATION_STATE.STOPPED && animatedIndex.value % 1 === 0) {
nextPosition = snapPoints[animatedIndex.value]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nextPosition = snapPoints[animatedIndex.value]
nextPosition = snapPoints[animatedIndex.value];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants