onLayout handler should work on UI thread
measure() measures paddings with some infelicity, while onLayout returns correct height/width/etc.
The following example is default accordion animation with opened/closed component inside
1) Closed => Open transition (height)

2) Open => Closed transition (height)

Hello!
Congratulations! Your issue passed the validator! Thank you!
@AlexeyVlasenko How this should be implemented?
Could you describe your vision and API? I think onLayout is expected to be called on JS side so changing <View /> to Reanimated <Animated.View /> does not cause error that JS function is called directly without runOnJS.
@likern is there a way to call measure whenever its size changes? Should we just call measure inside of onLayout?
I would go with that approach. It gives freedom to the developer.
const handler = useAnimatedLayoutEvent((layout) => {
"worklet";
// do whatever you want
}, [])
<Animated.View onLayout={handler} />
@terrysahaidak I like that approach, I think it's better than what I thought about (adding new on UI callback)
@terrysahaidak I assume that's not a real API yet, right? Seems like that would work for me.
Not yet. But would be cool to have. Measure is handy but doesn't work all the times.
Agreed, especially for web where layout changes are very common. I'll stick to normal layout for now.
Most helpful comment
I would go with that approach. It gives freedom to the developer.