Анимации
React Native предоставляет два API: Animated (старый) и Reanimated (современный).
Animated (встроенный)
Простая анимация
import { Animated, View, Pressable } from 'react-native';
import { useRef } from 'react';
function FadeIn() {
const opacity = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.timing(opacity, {
toValue: 1,
duration: 300,
useNativeDriver: true,
}).start();
}, []);
return <Animated.View style={{ opacity, width: 100, height: 100, backgroundColor: 'red' }} />;
}
useNativeDriver: true — анимация выполняется на нативной стороне, работает быстрее. Работает для opacity и transform.
Анимируемые свойства
opacitytransform(translateX, translateY, scale, rotate)width,height(без native driver)backgroundColor(с интерполяцией)
Interpolation
const animated = useRef(new Animated.Value(0)).current;
const translateY = animated.interpolate({
inputRange: [0, 1],
outputRange: [0, -100],
});
<Animated.View style={{ transform: [{ translateY }] }} />
Последовательность
Animated.sequence([
Animated.timing(x, { toValue: 100, duration: 300, useNativeDriver: true }),
Animated.timing(x, { toValue: 0, duration: 300, useNativeDriver: true }),
]).start();
Параллельно
Animated.parallel([
Animated.timing(opacity, { toValue: 1, duration: 300, useNativeDriver: true }),
Animated.timing(scale, { toValue: 1, duration: 300, useNativeDriver: true }),
]).start();
Цикл
Animated.loop(
Animated.sequence([
Animated.timing(rotate, { toValue: 1, duration: 1000, useNativeDriver: true }),
Animated.timing(rotate, { toValue: 0, duration: 1000, useNativeDriver: true }),
])
).start();
Reanimated (современный)
Более мощный, работает в UI-потоке, не блокирует JS.
npx expo install react-native-reanimated
Простая анимация
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
function Box() {
const offset = useSharedValue(0);
const style = useAnimatedStyle(() => ({
transform: [{ translateX: offset.value }],
}));
return (
<Animated.View style={[styles.box, style]} />
);
}
withSpring
import { withSpring } from 'react-native-reanimated';
offset.value = withSpring(100);
withTiming
import { withTiming } from 'react-native-reanimated';
offset.value = withTiming(100, { duration: 500 });
withDelay, withSequence
import { withDelay, withSequence, withTiming } from 'react-native-reanimated';
offset.value = withSequence(
withTiming(100, { duration: 300 }),
withDelay(200, withTiming(0, { duration: 300 }))
);
Жесты
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { useSharedValue, useAnimatedStyle } from 'react-native-reanimated';
function Draggable() {
const x = useSharedValue(0);
const y = useSharedValue(0);
const pan = Gesture.Pan()
.onUpdate((e) => {
x.value = e.translationX;
y.value = e.translationY;
})
.onEnd(() => {
x.value = withSpring(0);
y.value = withSpring(0);
});
const style = useAnimatedStyle(() => ({
transform: [{ translateX: x.value }, { translateY: y.value }],
}));
return (
<GestureDetector gesture={pan}>
<Animated.View style={[styles.box, style]} />
</GestureDetector>
);
}
Layout animations
import Animated, { FadeIn, FadeOut, SlideInRight } from 'react-native-reanimated';
<Animated.View entering={FadeIn.duration(300)} exiting={FadeOut}>
{/* контент */}
</Animated.View>
Что использовать
- Animated — если не нужны сложные жесты, работает из коробки
- Reanimated — для жестов, сложных анимаций, UI-потока
В 2026 году Reanimated — стандарт для серьёзных проектов.
Если ты уже знаешь React
В вебе — CSS-анимации, transitions, Framer Motion. В React Native — Animated и Reanimated. CSS-анимаций нет.
Итоги
AnimatedвстроенReanimated— стандартuseSharedValue+useAnimatedStylewithTiming,withSpring,withSequence- Layout animations для появления/исчезновения
- Жесты через
GestureDetector