-
-
Notifications
You must be signed in to change notification settings - Fork 780
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 snapToPosition
function call, right away after the mount.
#1623
base: v4
Are you sure you want to change the base?
Conversation
|
||
/** | ||
* mark the new position as temporary. | ||
* Checks whether the library has measured the container's height or if it was passed from props. |
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.
why not early exit this method , and ensure to listen to isLayoutCalculated
?
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.
I don't believe exiting from a function in that manner is correct. The caller has requested to open the bottom sheet, and the caller doesn't have any information on whether the package is ready or undergoing some heavy operations.
Regarding listening to isLayoutCalculated, if I understood it correctly, it seems more appropriate. I will update it after we know precisely whether there is a problem or not.
For more details on these matters, please refer to the comment section below.
thanks @beqramo for submitting this PR, but i think it is not about layout not being ready, |
could you please provide a reproducible sample code of the issue ? |
Noticed Reanimated 3 has an unreleased PR related to a race condition software-mansion/react-native-reanimated#5224 - wonder if there's a relation to this issue. |
Hi, thanks for your feedback, @gorhom. I will try to provide more context before presenting the conclusions: When snapToPosition is called from the ref right away after mount: useEffect(() => {
sheetRef.current?.snapToPosition(400);
}, []); At that time, SOMETIMES, the value of isLayoutCalculated is false. Why? The value of isLayoutCalculated changes after the onLayout callback gets called (when the component is rendered and we have sizes and other details about the container). What are the solutions? (Sorted from worse to best solution)
Reproducible sample code: Other than that I will drop my code snippet too: const sheetRef = useRef<BottomSheet>(null);
useEffect(() => {
// call right after mount
sheetRef.current?.snapToPosition(400);
}, []);
return <BottomSheet
ref={sheetRef}
snapPoints={[10]}
index={ -1}
>
<Column mt={7} px={5} stretch>
{/* children here*/}
</Column>
</BottomSheet> Thank you. Hope I will not waste your time. |
@henrymoulton Thanks for the info, Thank you |
@beqramo can you confirm it still happens if you're using Reanimated V2? |
Hi @henrymoulton, I am currently using my fork, and I haven't encountered the issue. Additionally, I am utilizing reanimated version 3. If you wish to test it, the problem might be more noticeable on low-end devices, particularly Android. The issue you mentioned seems slightly different here. The problem lies in the synchronization of the Thank you. |
Seems interesting! I'd like to see this PR merged if possible |
Fixes: #1294
Motivation
When
snapToPosition
gets called right away after a mount,animatedContainerHeight
has an initial value of -999, if the prop didn't get passed. It is happening as the package can't calculate height right away on the mount. in simple termsonLayout
function takes time to be called and to update the value ofanimatedContainerHeight
That means that
snapToPosition
causes some problems.To fix the issue, we need to wait for the update of the value of
animatedContainerHeight
and then continue calculating thenextPosition
value fromnormalizeSnapPoint
function.Because of that, I added a listener if I see that
animatedContainerHeight
still has an initial value. after I receive the update, I'm following the same process as it was before.I was forced to update the Reanimated package due to the recent addition of the listener feature. I've been using the updated Reanimated package in my production app for a while now, and it's been working seamlessly, so it shouldn't be a problem.
Thank you.