Reanimated — runs animations on native thread.
1import Animated, {2 useSharedValue,3 useAnimatedStyle,4 withSpring,5 withTiming,6 interpolate,7} from "react-native-reanimated";89function Box() {10 const offset = useSharedValue(0);1112 const style = useAnimatedStyle(() => ({13 transform: [{ translateX: offset.value }],14 }));1516 return (17 <Animated.View18 style={[styles.box, style]}19 onTouchEnd={() => {20 offset.value = withSpring(offset.value + 100);21 }}22 />23 );24}
Key concepts:
useSharedValue: mutable values on UI threaduseAnimatedStyle: reactive styleswithSpring/withTiming: animation functionsinterpolate: map input ranges to output ranges