Skill: React Native Reanimated
Purpose
To create high-performance, smooth (60fps+) animations and interactions in React Native by running animation logic on the UI thread.
When to Use
- When
AnimatedAPI from React Native is too slow or stutters. - For complex gestures (drag, pinch, swipe).
- For shared element transitions.
Procedure
1. Setup
- Install:
npm install react-native-reanimated - Babel Plugin: Add
react-native-reanimated/plugintobabel.config.js(must be listed last).plugins: [ // other plugins... 'react-native-reanimated/plugin', ], - Clear Cache:
npx expo start -c.
2. Basic Animation (Shared Values)
- Define Value: Use
useSharedValue.const width = useSharedValue(100); - Define Style: Use
useAnimatedStyle.const animatedStyle = useAnimatedStyle(() => { return { width: width.value }; }); - Render: Use
Animated.View.<Animated.View style={[styles.box, animatedStyle]} /> - Trigger: Update value with utility functions.
width.value = withSpring(200); // or withTiming(200, { duration: 500 })
3. Gestures
Combine with react-native-gesture-handler.
- Use
GestureDetectorto modify shared values based on touch events.
Constraints
- UI Thread Only: You cannot run complex JS logic inside
useAnimatedStyle(unless usingrunOnJS). - Debugging: Errors on the UI thread can be harder to trace; use
console.logcarefully orrunOnJSfor debugging.
Expected Output
Fluid animations that do not block the Javascript thread, providing a "native" feel.
Source: Ditto190/crispy-nextjs-turborepo-monorepo — distributed by TomeVault.