reanimated/Insights
Reanimated Insights
Key patterns and learnings for Reanimated
insightsreanimatedanimationsreact-native
Reanimated Insights
Critical Patterns
Worklet Execution
Functions marked with 'worklet' run on the UI thread. This means:
- No access to JS closures or variables outside the worklet
- No
console.log,Date.now(), or other non-reanimated APIs - Use
runOnJSto bridge back to JS thread when needed
Streaming Text Animation
For AI streaming text effects:
const scale = useSharedValue(1)
React.useEffect(() => {
scale.value = withSpring(1.02, {}, () => {
scale.value = withSpring(1)
})
}, [text.length])
Gesture Integration
Reanimated v4+ with Gesture Handler:
- Babel plugin auto-workletizes gesture callbacks
- Use
SharedValuedirectly in gesture config for thread-safe updates disableReanimated: trueforces gesture callbacks to run on JS thread
Performance Considerations
- Native driver - Animations run on UI thread when possible via native driver
- Reduce re-renders - Use
useAnimatedStyleto update styles without triggering React re-renders - Avoid LayoutAnimation conflicts - Don't mix Reanimated layout animations with React Native's built-in LayoutAnimation
Version Notes
- v4 breaking changes - Reanimated 4.x requires
react-native-workletspackage andreact-native-worklets/pluginbabel plugin - Migration from v3 -
runOnJSsyntax unchanged, but workletization behavior is stricter in v4