Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork908
FixsnapToPosition function call, right away after the mount.#1623
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:v4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
| /** | ||
| * 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 toisLayoutCalculated ?
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 ? |
henrymoulton commentedNov 26, 2023
Noticed Reanimated 3 has an unreleased PR related to a race conditionsoftware-mansion/react-native-reanimated#5224 - wonder if there's a relation to this issue. |
beqramo commentedNov 27, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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: constsheetRef=useRef<BottomSheet>(null);useEffect(()=>{// call right after mountsheetRef.current?.snapToPosition(400);},[]);return<BottomSheetref={sheetRef}snapPoints={[10]}index={-1}><Columnmt={7}px={5}stretch>{/* children here*/}</Column></BottomSheet> Thank you. Hope I will not waste your time. |
beqramo commentedNov 27, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@henrymoulton Thanks for the info, Thank you |
henrymoulton commentedJan 8, 2024
@beqramo can you confirm it still happens if you're using Reanimated V2? |
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. |
MBach commentedJun 4, 2024
Seems interesting! I'd like to see this PR merged if possible |
jspizziri commentedSep 3, 2025
@gorhom , this is still an issue in It would seem that a simple solution could simply be to provide a callback on the BottomSheet like: |
Uh oh!
There was an error while loading.Please reload this page.
Fixes:#1294
Motivation
When
snapToPositiongets called right away after a mount,animatedContainerHeighthas 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 termsonLayoutfunction takes time to be called and to update the value ofanimatedContainerHeightThat means that
snapToPositioncauses some problems.To fix the issue, we need to wait for the update of the value of
animatedContainerHeightand then continue calculating thenextPositionvalue fromnormalizeSnapPointfunction.Because of that, I added a listener if I see that
animatedContainerHeightstill 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.