Skip to content

Latest commit

History

550 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Lottie for React Native, iOS, and Android

npm VersionLicense

Lottie component for React Native (iOS and Android)

Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as JSON with bodymovin and renders them natively on mobile!

For the first time, designers can create and ship beautiful animations without an engineer painstakingly recreating it by hand.

Installing

Install lottie-react-native (latest) and lottie-ios (3.2.3):

yarn add lottie-react-native
yarn add lottie-ios@3.2.3

or

npm i --save lottie-react-native
npm i --save lottie-ios@3.2.3

Go to your ios folder and run:

pod install

Versioning

Depending on which version of React Native your app runs on you might need to install a specific version of lottie-react-native. Here's the compatibility list:

App built in React Native versionRequires lottie-react-native versionRequires lottie-ios version
>= 0.593.0.23.0.3
>= 0.604.0.23.2.3
>= 0.634.0.33.2.3
>= 0.644.1.33.2.3
>= 0.66latest3.2.3

Usage

(If you are using TypeScript, please read this first)

LottieView can be used in a declarative way:

importReactfrom'react';importLottieViewfrom'lottie-react-native';exportdefaultclassBasicExampleextendsReact.Component{render(){return<LottieViewsource={require('./animation.json')}autoPlayloop/>;}}

Additionally, there is an imperative API which is sometimes simpler.

importReactfrom'react';importLottieViewfrom'lottie-react-native';exportdefaultclassBasicExampleextendsReact.Component{componentDidMount(){this.animation.play();// Or set a specific startFrame and endFrame with:this.animation.play(30,120);}render(){return(<LottieViewref={animation=>{this.animation=animation;}}source={require('../path/to/animation.json')}/>);}}

Lottie's animation progress can be controlled with an Animated value:

importReactfrom'react';import{Animated,Easing}from'react-native';importLottieViewfrom'lottie-react-native';exportdefaultclassBasicExampleextendsReact.Component{constructor(props){super(props);this.state={progress: newAnimated.Value(0),};}componentDidMount(){Animated.timing(this.state.progress,{toValue: 1,duration: 5000,easing: Easing.linear,}).start();}render(){return(<LottieViewsource={require('../path/to/animation.json')}progress={this.state.progress}/>);}}

Changing color of layers:

importReactfrom'react';importLottieViewfrom'lottie-react-native';exportdefaultclassBasicExampleextendsReact.Component{render(){return(<LottieViewsource={require('../path/to/animation.json')}colorFilters={[{keypath: 'button',color: '#F00000',},{keypath: 'Sending Loader',color: '#F00000',},]}autoPlayloop/>);}}

API

You can find the full list of props and methods available in our API document. These are the most common ones:

PropDescriptionDefault
sourceMandatory - The source of animation. Can be referenced as a local asset by a string, or remotely with an object with a uri property, or it can be an actual JS object of an animation, obtained (for example) with something like require('../path/to/animation.json').None
styleStyle attributes for the view, as expected in a standard View.The aspectRatio exported by Bodymovin will be set. Also the width if you haven't provided a width or height
loopA boolean flag indicating whether or not the animation should loop.true
autoPlayA boolean flag indicating whether or not the animation should start automatically when mounted. This only affects the imperative API.false
colorFiltersAn Array of layers you want to change the color filter.[]

More...

Troubleshooting

Not all After Effects features are supported by Lottie. If you notice there are some layers or animations missing check this list to ensure they are supported.

iOS specifc problems

If you have issues linking your iOS project check out this StackOverflow thread on how to fix it.

Android specific problems

If your app crashes on Android, means auto linking didn't work. You will need to make the following changes:

android/app/src/main/java/<AppName>/MainApplication.java

  • add import com.airbnb.android.react.lottie.LottiePackage; on the imports section
  • add packages.add(new LottiePackage()); in List<ReactPackage> getPackages();

android/app/build.gradle

add implementation project(':lottie-react-native') in the dependencies block

android/settings.gradle

add:

include ':lottie-react-native'
project(':lottie-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/lottie-react-native/src/android')

More

View more documentation, FAQ, help, examples, and more at airbnb.io/lottie

Example1

Example2

Example3

Community

Example4

About

Lottie wrapper for React Native.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages