Lottie React Native

7.3.6 · active · verified Sun Apr 19

Lottie React Native provides comprehensive React Native bindings for the Lottie animation ecosystem, enabling the display of Adobe After Effects animations exported as JSON files via Bodymovin. Currently stable at version 7.3.6, the library maintains an active release cadence with frequent bug fixes and feature updates, often including support for new React Native versions and Expo SDKs. Its primary differentiation lies in allowing designers to directly ship complex animations without requiring engineers to painstakingly recreate them in code. It offers native rendering on iOS (using `lottie-ios`), Android (using `lottie-android`), and Windows (using `Lottie-Windows`), ensuring high performance and fidelity across platforms. The package ships with TypeScript types, facilitating robust development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate and control a Lottie animation using a local JSON file within a React Native component, including playback controls and lifecycle events.

import React, { useRef, useEffect } from 'react';
import { View, StyleSheet, Button } from 'react-native';
import LottieView from 'lottie-react-native';

// Assuming 'myAnimation.json' is in your project's assets folder
// and contains a valid Lottie JSON animation.
const myAnimation = require('./path/to/myAnimation.json'); 

function AnimationScreen() {
  const animationRef = useRef<LottieView>(null);

  useEffect(() => {
    // Start animation automatically on component mount
    animationRef.current?.play();
  }, []);

  return (
    <View style={styles.container}>
      <LottieView
        ref={animationRef}
        source={myAnimation} // Path to your local JSON animation
        autoPlay={true}
        loop={true}
        style={styles.lottieAnimation}
        onAnimationFinish={(isCancelled) => {
          console.log('Animation finished:', isCancelled ? 'cancelled' : 'completed');
        }}
      />
      <View style={styles.controls}>
        <Button title="Play" onPress={() => animationRef.current?.play()} />
        <Button title="Pause" onPress={() => animationRef.current?.pause()} />
        <Button title="Reset" onPress={() => animationRef.current?.reset()} />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  lottieAnimation: {
    width: 300,
    height: 300,
    backgroundColor: 'transparent',
  },
  controls: {
    flexDirection: 'row',
    marginTop: 20,
    gap: 10
  }
});

export default AnimationScreen;

view raw JSON →