What is the expected behavior of measure
inside useDerivedValue
?
#3881
-
The documentation shows a basic measure example that looks like const Comp = () => {
const aref = useAnimatedRef();
useDerivedValue(() => {
const measured = measure(aref);
...
});
return <View ref={aref} />;
}; Looking at this, you might think that any time the view dimensions changed, the function inside There are ways to force a re-measurement when the component size changes, but as far as I can tell, they all rely on Is there a pattern for "subscribing" to layout updates exclusively on the UI thread? Edit: Here is a basic example file to play around with. Edit: @tomekzaw I was wondering if you could let me know whether this would be considered a bug or a feature request. I'm not sure what the expected behavior is, so it's hard to know in which direction I should escalate this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Still un-answered, Great 🥲 |
Beta Was this translation helpful? Give feedback.
Hey! This discussion is quite old so I didn't see that it hasn't been answered yet. I will describe how it works.
How
useDerivedValue
worksIn general,
useDerivedValue
callback is executed only if values, used within the callback, change. So, the callback is triggered if you use other Shared Values within it and modify at least one of them or if you use plain values and they change (like in theuseEffect
hook, but you don't have to specify the dependencies array as the hook is "smart" thanks to the reanimated babel plugin and automatically adds dependencies for you).In short,
useDerivedValue
is triggered only if dependent values (either Shared Values or plain values) change.Answering qu…