Lottie React Native
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
-
Build Error with React Native 0.80 - Kotlin Type Mismatch
cause Incompatibility issues arising from Kotlin type declarations when building React Native applications on version 0.80.fixUpgrade `lottie-react-native` to version `7.2.3` or higher, which includes a specific fix for this Kotlin type mismatch error. -
Invariant Violation: LottieView was not found in the UIManager.
cause The native module for LottieView has not been correctly linked or initialized by React Native. This often occurs due to caching issues or incomplete setup steps.fixFor iOS, navigate to your `ios` directory and run `pod install`. For Android, try `npx react-native start --reset-cache` and a clean build of your app (e.g., `cd android && ./gradlew clean` then rebuild). Ensure autolinking is functional or manually link if necessary. -
TypeError: _lottieReactNative.default.LottieView is not a constructor (evaluating '_reactNative.LottieView')
cause This error typically indicates an incorrect import statement where `LottieView` is being imported as a named export when it is, in fact, a default export.fixChange your import statement from `import { LottieView } from 'lottie-react-native';` to `import LottieView from 'lottie-react-native';` -
ReferenceError: Can't find variable: TextAttributeProps
cause This error occurs in specific React Native versions (like 0.82+) due to internal changes in how `TextAttributeProps.UNSET` is imported or referenced.fixUpdate `lottie-react-native` to version `7.3.4` or newer, which includes a fix addressing the `TextAttributeProps.UNSET` import for React Native 0.82+.
Warnings
- breaking Version 6.x introduced significant breaking changes. While specific details are not provided in the excerpt, they require migration steps.
- breaking The way to apply styles to the animation's container changed with the introduction of a new 'containerStyle' prop in v7.3.0, potentially breaking existing layouts. While v7.3.2 reintroduced backward compatibility, direct styling of the LottieView component might behave differently.
- gotcha For web platform support, the '@lottiefiles/dotlottie-react' peer dependency must be explicitly installed, as it is not bundled.
- gotcha Using Lottie React Native with newer React versions (e.g., React 19) typically found in React Native 0.78+ or Expo SDK 53, requires ensuring the `@lottiefiles/dotlottie-react` peer dependency is updated.
Install
-
npm install lottie-react-native -
yarn add lottie-react-native -
pnpm add lottie-react-native
Imports
- LottieView
import { LottieView } from 'lottie-react-native';import LottieView from 'lottie-react-native';
- LottieViewProps
import type { LottieViewProps } from 'lottie-react-native'; - AnimationObject
import type { AnimationObject } from 'lottie-react-native';
Quickstart
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;