-
I'm writing logic like this: <Pressable
onPress={() => {
sv.value = 1;
setState(true);
}}
/>
// ...
return state && <Foo sv={sv} />; This updates the shared value on the JS thread and triggers a re-render of the component on the UI thread. However, onPress={() => {
sv.value = 1;
requestAnimationFrame(() => {
setState(true);
});
}} This partially solves the problem, but it's not perfect— What is the best way to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Hey @bglgwyng! Can you show me how you access the You have to keep in mind that updates of SharedValues aren't performed at the same time as React renders so you might not get the new value when the component renders. To properly use SharedValues, you need reanimated hooks like |
Beta Was this translation helpful? Give feedback.
Good, thanks for explanation.
Since the problem is not reproducible in the small example but appears in the app code, I suspect one more thing here. This is related to how reanimated works. It batches all animated styles changes and commits them once per animation frame, but, if the React render is heavy, changes from reanimated might be much delayed, after React successfully commits its changes.
There is not an easy workaround for this case and using
requestAnimationFrame
, timeouts, etc. won't work here.Possible solution
You can try using the
onLayout
to check if the proper height was applied before making the view visible. This is a tricky way but I used something similar before to det…