1--- 2title: Animation 3description: Learn how to integrate the react-native-reanimated library and use it in your Expo project. 4--- 5 6import { Terminal, SnackInline } from '~/ui/components/Snippet'; 7import { BoxLink } from '~/ui/components/BoxLink'; 8 9Animations are a great way to enhance and provide a better user experience. In your Expo projects, you can use the [Animated API](https://reactnative.dev/docs/next/animations) from React Native. However, if you want to use more advanced animations with better performance, you can use the [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/) library. It provides an API that simplifies the process of creating smooth, powerful, and maintainable animations. 10 11## Installation 12 13To install `react-native-reanimated`, run the following command: 14 15<Terminal cmd={['$ npx expo install react-native-reanimated']} /> 16 17After the installation completes, add the Babel plugin to **babel.config.js**: 18 19```js babel.config.js 20module.exports = function (api) { 21 api.cache(true); 22 return { 23 presets: ['babel-preset-expo'], 24 plugins: ['react-native-reanimated/plugin'], 25 }; 26}; 27``` 28 29After you add the Babel plugin, restart your development server and clear the bundler cache using `npx expo start --clear`. 30 31> If you load other Babel plugins, the Reanimated plugin has to be the last item in the plugins array. 32 33### Web support 34 35**For web**, install the [`@babel/plugin-proposal-export-namespace-from`](https://babeljs.io/docs/en/babel-plugin-proposal-export-namespace-from#installation) Babel plugin and update the **babel.config.js** to load it: 36 37{/* prettier-ignore */} 38```js babel.config.js 39plugins: [ 40 '@babel/plugin-proposal-export-namespace-from', 41 'react-native-reanimated/plugin', 42], 43``` 44 45After you add the Babel plugin, restart your development server and clear the bundler cache using `npx expo start --clear`. 46 47## Minimal example 48 49The following example shows how to use the `react-native-reanimated` library to create a simple animation. For more information on the API and its usage, see [**`react-native-reanimated` documentation**](https://docs.swmansion.com/react-native-reanimated/docs/). 50 51<SnackInline label="Using react-native-reanimated" dependencies={['react-native-reanimated']}> 52 53{/* prettier-ignore */} 54```jsx 55import Animated, { 56 useSharedValue, 57 withTiming, 58 useAnimatedStyle, 59 Easing, 60} from 'react-native-reanimated'; 61import { View, Button, StyleSheet } from 'react-native'; 62 63export default function AnimatedStyleUpdateExample() { 64 const randomWidth = useSharedValue(10); 65 66 const config = { 67 duration: 500, 68 easing: Easing.bezier(0.5, 0.01, 0, 1), 69 }; 70 71 const style = useAnimatedStyle(() => { 72 return { 73 width: withTiming(randomWidth.value, config), 74 }; 75 }); 76 77 return ( 78 <View style={styles.container}> 79 <Animated.View style={[styles.box, style]} /> 80 <Button 81 title="toggle" 82 onPress={() => { 83 randomWidth.value = Math.random() * 350; 84 }} 85 /> 86 </View> 87 ); 88} 89 90const styles = StyleSheet.create({ 91 container: { 92 flex: 1, 93 alignItems: 'center', 94 justifyContent: 'center', 95 flexDirection: 'column', 96 }, 97 box: { 98 width: 100, 99 height: 80, 100 backgroundColor: 'black', 101 margin: 30, 102 }, 103}); 104``` 105 106</SnackInline> 107 108### Other animation libraries 109 110Other animation packages are available, such as Moti, that you also use in your Expo project and work on Android, iOS, and the web. For more information on its API and usage, see [Moti's documentation](https://moti.fyi/). 111 112## Next step 113 114<BoxLink 115 title="Store data" 116 description="Learn about different libraries available to store data in your app." 117 href="/develop/user-interface/store-data" 118/> 119