Animated library provides a comprehensive set of APIs for creating fluid, high-performance animations. It can animate various values over time using different easing functions and supports running animations on the native thread for optimal performance.
Import
Core Concepts
Animated Values
Animated values are special objects that drive animations:Animated.Value: Animates a single numberAnimated.ValueXY: Animates a vector with x and y coordinatesAnimated.Color: Animates color values
Animated Components
Use animated versions of components to apply animations:Animated.ViewAnimated.TextAnimated.ImageAnimated.ScrollViewAnimated.FlatListAnimated.SectionList
Animation Types
timing()
Animates a value over time using an easing curve.The animated value to animate.
Configuration object:
toValue(number | Animated.Value): Target valueduration(number): Animation duration in milliseconds (default: 500)easing(function): Easing function (default:Easing.inOut(Easing.ease))delay(number): Delay before starting animation in millisecondsuseNativeDriver(boolean): Use native animation driver for better performance
CompositeAnimation with start(), stop(), and reset() methods.
spring()
Creates a spring-based animation using physical spring model.The animated value to animate.
Configuration object:
toValue(number | Animated.Value): Target valuefriction(number): Spring friction (default: 7)tension(number): Spring tension (default: 40)speed(number): Animation speedbounciness(number): Bounciness of the springdelay(number): Delay before startinguseNativeDriver(boolean): Use native driver
decay()
Starts an animation with an initial velocity that gradually slows down.The animated value to animate.
Configuration object:
velocity(number): Initial velocitydeceleration(number): Rate of decay (default: 0.997)useNativeDriver(boolean): Use native driver
Composition Methods
parallel()
Runs multiple animations at the same time.Array of animations to run in parallel.
stopTogether(boolean): If true, all animations stop when one stops (default: true)
sequence()
Runs animations in order, waiting for each to complete before starting the next.delay()
Creates a delay before starting the next animation.stagger()
Starts animations in sequence with specified delay between each.Delay in milliseconds between starting each animation.
loop()
Repeats an animation indefinitely or a specified number of times.The animation to loop.
iterations(number): Number of times to loop (-1 for infinite, default: -1)resetBeforeIteration(boolean): Reset animation before each iteration (default: true)
Interpolation
Map input ranges to output ranges for complex animations.inputRange(number[]): Input value rangeoutputRange(number[] | string[]): Output value rangeextrapolate(string): How to handle values outside range (‘extend’ | ‘clamp’ | ‘identity’)extrapolateLeft(string): Extrapolation for left sideextrapolateRight(string): Extrapolation for right side
Math Operations
Combine animated values with math operations:Animated.add(a, b)Animated.subtract(a, b)Animated.multiply(a, b)Animated.divide(a, b)Animated.modulo(a, modulus)Animated.diffClamp(a, min, max)
Examples
Simple Fade In
Spring Animation
Parallel Animations
Sequence Animation
Interpolation Example
Loop Animation
Creating Custom Animated Components
Easing Functions
Use theEasing module for animation curves:
Easing.linearEasing.easeEasing.quadEasing.cubicEasing.bezier(x1, y1, x2, y2)Easing.in(easing)Easing.out(easing)Easing.inOut(easing)
Performance Tips
Avoid creating new
Animated.Value instances on every render. Use useRef to persist values across renders.