React Native theorytheory 0/50 · 0%
Animation · medium

26. Animations with Animated

Driving smooth UI transitions.

The `Animated` API drives values over time and can run on the native thread via `useNativeDriver: true`, keeping animations smooth even if the JS thread is busy.

import { Animated, useRef, useEffect } from "react";

function FadeIn({ children }: { children: React.ReactNode }) {
  const opacity = useRef(new Animated.Value(0)).current;
  useEffect(() => {
    Animated.timing(opacity, { toValue: 1, duration: 300, useNativeDriver: true }).start();
  }, [opacity]);
  return <Animated.View style={{ opacity }}>{children}</Animated.View>;
}

Not every style property supports the native driver (layout properties like `width` typically don't), so check the docs before assuming an animation can be offloaded.

Check your understanding

  1. 1. What does useNativeDriver: true do?

  2. 2. Do all style properties support the native driver?

  3. 3. What object represents an animatable value?