Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Lesson 5 of 9
Lottie Animations
Lottie renders Adobe After Effects animations exported as JSON. Use it for splash screens, success animations, loading states, onboarding illustrations, and empty states - all at native frame rate and tiny file sizes (JSON, not video).
lottie-react-native
npx expo install lottie-react-native
import LottieView from 'lottie-react-native';
import { useRef } from 'react';
// ---- Auto-playing animation ----
function SuccessAnimation({ onComplete }: { onComplete: () => void }) {
return (
<LottieView
source={require('../assets/animations/success.json')}
autoPlay
loop={false}
speed={1.2} // 20% faster
onAnimationFinish={onComplete} // navigate away after animation
style={{ width: 200, height: 200 }}
resizeMode="cover"
/>
);
}
// ---- Imperative control (play/pause/seek) ----
function OnboardingAnimation({ step }: { step: number }) {
const ref = useRef<LottieView>(null);
function playFromFrame(frame: number) {
ref.current?.play(frame, frame + 60); // play a 60-frame segment
}
return (
<View>
<LottieView
ref={ref}
source={require('../assets/animations/onboarding.json')}
autoPlay={false} // manual control
loop={false}
style={{ width: '100%', height: 300 }}
/>
<Pressable onPress={() => ref.current?.play()}>
<Text>Play</Text>
</Pressable>
<Pressable onPress={() => ref.current?.pause()}>
<Text>Pause</Text>
</Pressable>
<Pressable onPress={() => ref.current?.reset()}>
<Text>Reset</Text>
</Pressable>
</View>
);
}
// ---- Lottie progress driven by scroll (Reanimated) ----
function ScrollDrivenLottie() {
const progress = useSharedValue(0);
const scrollHandler = useAnimatedScrollHandler(e => {
progress.value = e.contentOffset.y / 500; // 500 = max scroll
});
return (
<Animated.ScrollView onScroll={scrollHandler} scrollEventThrottle={16}>
{/* Lottie doesn't support Reanimated shared values directly */}
{/* Use Animated.event from react-native instead */}
</Animated.ScrollView>
);
}Tip
Tip
Practice Lottie Animations in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Rendering smooth vector animations from Adobe After Effects via Lottie JSON
Practice Task
Note
Practice Task - (1) Write a working example of Lottie Animations from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Lottie Animations is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?