React Native Reanimated is a powerful animation library that provides a more performant and flexible alternative to React Native's Animated API. It allows you to create smooth, complex animations that run on the UI thread, ensuring 60fps performance even when the JavaScript thread is busy.
- π High Performance: Animations run on the UI thread, independent of the JavaScript thread
- π¨ Rich Animation API: Support for timing, spring, decay, and custom animations
- π Gesture Integration: Seamless integration with
react-native-gesture-handler - π Layout Animations: Automatic animations for layout changes
- π§΅ Worklets: Write JavaScript functions that run on the UI thread
- π Shared Values: Reactive values that can be used across components
- π± Cross-Platform: Works on iOS, Android, and Web
- πͺ TypeScript Support: Full TypeScript definitions included
npm install react-native-reanimated
# or
yarn add react-native-reanimatedcd ios && pod install && cd ..No additional steps required.
Add the Reanimated plugin to your babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['react-native-reanimated/plugin'],
};Important: The Reanimated plugin must be listed last in the plugins array.
import Animated, {
useSharedValue,
withTiming,
useAnimatedStyle,
Easing,
} from 'react-native-reanimated';
function App() {
const width = useSharedValue(100);
const animatedStyle = useAnimatedStyle(() => {
return {
width: withTiming(width.value, {
duration: 500,
easing: Easing.bezier(0.25, 0.1, 0.25, 1),
}),
};
});
return (
<Animated.View style={[{ height: 100, backgroundColor: 'blue' }, animatedStyle]} />
);
}import { GestureDetector, Gesture } from 'react-native-gesture-handler';
import Animated, {
useSharedValue,
useAnimatedStyle,
withSpring,
} from 'react-native-reanimated';
function DraggableBox() {
const translateX = useSharedValue(0);
const translateY = useSharedValue(0);
const pan = Gesture.Pan()
.onUpdate((e) => {
translateX.value = e.translationX;
translateY.value = e.translationY;
})
.onEnd(() => {
translateX.value = withSpring(0);
translateY.value = withSpring(0);
});
const animatedStyle = useAnimatedStyle(() => {
return {
transform: [
{ translateX: translateX.value },
{ translateY: translateY.value },
],
};
});
return (
<GestureDetector gesture={pan}>
<Animated.View style={[styles.box, animatedStyle]} />
</GestureDetector>
);
}import Animated, { FadeIn, FadeOut, Layout } from 'react-native-reanimated';
function AnimatedList({ items }) {
return (
<FlatList
data={items}
renderItem={({ item }) => (
<Animated.View
entering={FadeIn}
exiting={FadeOut}
layout={Layout.springify()}
>
<Text>{item.title}</Text>
</Animated.View>
)}
/>
);
}For detailed documentation, examples, and tutorials, visit:
Check out the Example directory for comprehensive examples demonstrating various features and use cases.
- React Native >= 0.64
- react-native-gesture-handler (peer dependency)
Contributions are welcome! Please read our contributing guidelines and code of conduct before submitting pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
yarn setupThis will install dependencies and set up the example app.
yarn testyarn type:checkMIT
- Krzysztof Magiera
- Software Mansion
Made with β€οΈ by Software Mansion