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
Maniae
wants to merge
4
commits into
gorhom:master
Choose a base branch
from
Maniae:fix/fix-bottom-sheet-closing-immediately-on-snapPoint-change
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix BottomSheet closing instantly when snapPoints change #1815
Maniae
wants to merge
4
commits into
gorhom:master
from
Maniae:fix/fix-bottom-sheet-closing-immediately-on-snapPoint-change
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maniae
changed the title
update animatedCurrentIndex on animation completion
Fix BottomSheet closing instantly when snapPoints change
Apr 25, 2024
I think it's a good idea. Probably it will also fix issues with dynamic-sizing.mp4 |
ToledoSDL
approved these changes
May 10, 2024
Hey, do you know if it's going to be released soon in V4 ? |
theohdv
reviewed
May 22, 2024
@@ -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] |
There was a problem hiding this comment.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.