Introduction
Animations make apps feel smooth and alive. They help users understand changes and keep their attention.
Animations make apps feel smooth and alive. They help users understand changes and keep their attention.
import { Animated } from 'react-native'; const fadeAnim = new Animated.Value(0); Animated.timing(fadeAnim, { toValue: 1, duration: 500, useNativeDriver: true }).start();
Animated.Value to create an animatable value.Animated.timing to change the value over time.const fadeAnim = new Animated.Value(0); Animated.timing(fadeAnim, { toValue: 1, duration: 1000, useNativeDriver: true }).start();
const slideAnim = new Animated.Value(-100); Animated.timing(slideAnim, { toValue: 0, duration: 500, useNativeDriver: true }).start();
This example shows a green box with text that smoothly appears by fading in over 2 seconds.
import React, { useRef, useEffect } from 'react'; import { Animated, View, Text, StyleSheet } from 'react-native'; export default function FadeInExample() { const fadeAnim = useRef(new Animated.Value(0)).current; useEffect(() => { Animated.timing(fadeAnim, { toValue: 1, duration: 2000, useNativeDriver: true }).start(); }, [fadeAnim]); return ( <Animated.View style={[styles.box, { opacity: fadeAnim }]}> <Text style={styles.text}>Hello, I fade in!</Text> </Animated.View> ); } const styles = StyleSheet.create({ box: { marginTop: 50, padding: 20, backgroundColor: '#4CAF50', borderRadius: 10, alignItems: 'center' }, text: { color: 'white', fontSize: 18 } });
Animations help users notice changes without confusion.
Use useNativeDriver: true for better performance.
Keep animations short and smooth to avoid delays.
Animations make apps feel smooth and natural.
They guide users by showing changes clearly.
React Native's Animated API helps create these effects easily.
const opacity = new Animated.Value(0);
Animated.timing(opacity, {toValue: 1, duration: 1000}).start();
return <Animated.View style={{opacity}}></Animated.View>;const scale = new Animated.Value(1);
Animated.timing(scale, {toValue: 2, duration: 500});
return <Animated.View style={{transform: [{scale}]}}></Animated.View>;Pass the test and this pattern moves unknown