Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lottie-react-native

react-native-community2.1mApache-2.07.2.2TypeScript support: included

React Native bindings for Lottie

lottie, animation, react, react-native, keyframe

readme

Lottie React Native

npm Version License

Lottie component for React Native (iOS, Android, and Windows)

Lottie is an ecosystem of libraries for parsing Adobe After Effects animations exported as JSON with bodymovin and rendering them natively!

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

Installing

Breaking Changes in v6!

We've made some significant updates in version 6 that may impact your current setup. To get all the details about these changes, check out the changelog.

Stay informed to ensure a seamless transition to the latest version. Thank you!

iOS and Android

  • Install lottie-react-native (latest):
yarn add lottie-react-native

Go to your ios folder and run:

pod install

Web

  • Install lottie-react-native (latest):
yarn add lottie-react-native
  • Add dependencies for web players:
yarn add @lottiefiles/dotlottie-react

Windows (React Native >= 0.63)

<summary>Install the `lottie-react-native` npm package. (Click to expand)</summary>

Add the following to the end of your project file. For C# apps, this should come after any Microsoft.Windows.UI.Xaml.CSharp.targets includes. For C++ apps, it should come after any Microsoft.Cpp.targets includes.

<PropertyGroup Label="LottieReactNativeProps">
    <LottieReactNativeDir>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\lottie-react-native\package.json'))\node_modules\lottie-react-native</LottieReactNativeDir>
</PropertyGroup>
<ImportGroup Label="LottieReactNativeTargets">
    <Import Project="$(LottieReactNativeDir)\src\windows\cppwinrt\PropertySheets\LottieGen.Auto.targets" />
</ImportGroup>

Add the LottieReactNative.vcxproj file to your Visual Studio solution to ensure it takes part in the build.

For C# apps, you'll need to install the following packages through NuGet:

  • LottieGen.MsBuild
  • Microsoft.UI.Xaml
  • Win2D.uwp
  • Microsoft.Toolkit.Uwp.UI.Lottie
    • This package is used for loading JSON dynamically. If you only need codegen animation, you can set <EnableLottieDynamicSource>false</EnableLottieDynamicSource> in your project file and omit this reference.

For C++ apps, you'll need these NuGet packages:

  • LottieGen.MsBuild
  • Microsoft.UI.Xaml

WinUI 2.6 (Microsoft.UI.Xaml 2.6.0) is required by default. Overriding this requires creating a Directory.Build.props file in your project root with a <WinUIVersion> property.

In your application code where you set up your React Native Windows PackageProviders list, add the LottieReactNative provider:

// C#
PackageProviders.Add(new LottieReactNative.ReactPackageProvider(new AnimatedVisuals.LottieCodegenSourceProvider()));
// C++
#include <winrt/LottieReactNative.h>
#include <winrt/AnimatedVisuals.h>

...

PackageProviders().Append(winrt::LottieReactNative::ReactPackageProvider(winrt::AnimatedVisuals::LottieCodegenSourceProvider()));

Codegen animations are supported by adding LottieAnimation items to your project file. These will be compiled into your application and available at runtime by name. For example:

<!-- .vcxproj or .csproj -->
<ItemGroup>
    <LottieAnimation Include="Assets/Animations/MyAnimation.json" Name="MyAnimation" />
</ItemGroup>
// js
<LottieView source={'MyAnimation'} />

Codegen is available to both C# and C++ applications. Dynamic loading of JSON strings at runtime is currently only supported in C# applications.

Usage

Lottie can be used in a declarative way:

import React from 'react';
import LottieView from 'lottie-react-native';

export default function Animation() {
  return (
    <LottieView source={require('../path/to/animation.json')} autoPlay loop />
  );
}

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

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

export default function AnimationWithImperativeApi() {
  const animationRef = useRef<LottieView>(null);

  useEffect(() => {
    animationRef.current?.play();

    // Or set a specific startFrame and endFrame with:
    animationRef.current?.play(30, 120);
  }, []);

  return (
    <LottieView
      ref={animationRef}
      source={require('../path/to/animation.json')}
    />
  );
}

Lottie's animation view can be controlled by either React Native Animated or Reanimated API.

import React, { useEffect, useRef, Animated } from 'react';
import { Animated, Easing } from 'react-native';
import LottieView from 'lottie-react-native';

const AnimatedLottieView = Animated.createAnimatedComponent(LottieView);

export default function ControllingAnimationProgress() {
  const animationProgress = useRef(new Animated.Value(0));

  useEffect(() => {
    Animated.timing(animationProgress.current, {
      toValue: 1,
      duration: 5000,
      easing: Easing.linear,
      useNativeDriver: false,
    }).start();
  }, []);

  return (
    <AnimatedLottieView
      source={require('../path/to/animation.json')}
      progress={animationProgress.current}
    />
  );
}

Changing color of layers:

NOTE: This feature may not work properly on Android. We will try fix it soon.

import React from 'react';
import LottieView from 'lottie-react-native';

export default function ChangingColorOfLayers() {
  return (
    <LottieView
      source={require('../path/to/animation.json')}
      colorFilters={[
        {
          keypath: 'button',
          color: '#F00000',
        },
        {
          keypath: 'Sending Loader',
          color: '#F00000',
        },
      ]}
      autoPlay
      loop
    />
  );
}

If you want to use .lottie files

You need to modify your metro.config.js file accordingly by adding lottie extension to the assetExts array:

const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');

const defaultConfig = getDefaultConfig(__dirname);

/**
 * Metro configuration
 * https://facebook.github.io/metro/docs/configuration
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
  resolver: {
    assetExts: [...defaultConfig.resolver.assetExts, 'lottie'],
  },
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);

Setup jest for dotLottie files

Create a file in the following path __mocks__/lottieMock.js and add the following code:

module.exports = 'lottie-test-file-stub';

Then add the following to your jest.config.js file:

module.exports = {
  ...
  moduleNameMapper: {
    ...,
    '\\.(lottie)$': '<rootDir>/jest/__mocks__/lottieMock.js',
  },
  ...
}

API

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

Prop Description Default
source Mandatory - 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
style Style attributes for the view, as expected in a standard View. You need to set it manually. Refer to this pull request.
loop A boolean flag indicating whether or not the animation should loop. true
autoPlay A boolean flag indicating whether or not the animation should start automatically when mounted. This only affects the imperative API. false
colorFilters An array of objects denoting layers by KeyPath and a new color filter value (as hex string). []

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.

More

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

Example1

Example2

Example3

Community

Example4

changelog

Changelog

6.0.0

Features

  • Fabric support for iOS (#955)
  • Fabric support for Android (#910)
  • Upgrade android-lottie to 6.0.0 (#993)
  • Upgrade android-lottie to 6.1.0 (#1060)
  • Implement native auto play for android (63f71aa)
  • Implement native auto play for ios (84e6668)

Bug Fixes

  • Add missing condition (bd44aff)
  • Old arch impl (65ec453)
  • android: Refactor event dispatch logic on android to fix fabric crash (#1000) (ebb8006)
  • android: Add support for upcoming 0.73 (#1038)
  • android: Fix resize mode in Android (#992)
  • iOS: Reset to first frame on app resume bug (#980)
  • iOS: Frames being calculated incorrectly (#1019)
  • macOS: react native macos build (#1031)
  • iOS: Memory leak on deallocation (#1055)
  • iOS: Update lottie-ios to 4.2.0 + fix build error (#1036)
  • iOS: prevent jumping to end frame (#1061)
  • Fabric build on 0.68/0.69 (#1054)
  • Fix different ios related issues (3f7e3e)

Internal Changes

  • Move project to monorepo 077429
  • Update examples to typescript (300e63)
  • Remove redundant logging from the project (#1024)

BREAKING CHANGES

  • BREAKING CHANGE: Removed using Animated API by default in the source code (#992)

  • BREAKING CHANGE: Removed absolute style being applied to the LottieView (#992)

  • BREAKING CHANGE: Removed default aspect ratio styling (#992)

  • BREAKING CHANGE: Removed default width and height being applied (#992)

    Check here for more information.

  • BREAKING CHANGE: Renamed AnimatedLottieViewProps to LottieViewProps (9fd591)

Full changelog can be found here.

Known issues:

5.1.4

  • Support for lottie-ios version 3.4.0
  • Update tvOS deployment target to 11.0

5.1.3

  • Fix Android compilation issue

5.1.2

  • Fix compilation issues on Android

5.1.1

  • Remove deprecated-react-native-prop-types import

5.1.0

  • Upgrade lottie-android dependency to 5.1.1
  • Fix ViewPropTypes imports
  • Support for remote animations
  • Support for dynamic text
  • Support changing lottie props for ongoing animations
  • Regular chore tasks

5.0.1

  • Fix SimpleColorFilter casting error

5.0.0

  • Upgraded to RN 0.66.1
  • Support for PlatformColor

4.1.3

  • Added pod support for tvOS

4.1.2

  • iOS target moved to 11.0 to align with React Native 64

4.1.1

  • Updating Documentation

4.1.0

  • Upgrading Native lottie-android to 4.0.0
  • Migrated to maven_publish
  • Migrated to gradle 7

4.0.3

  • Updated lottie-ios dependency to 3.2.3

4.0.2

  • Minor fixes

4.0.1

  • Update react-native-safe-modules dependency

4.0.0

  • Fix react-native 0.64 compatibility
  • Windows support [C#]
  • macOS Support (based on react-native-windows)
  • Moved lottie-ios to peerDependencies
  • Fix Android playback when startFrame > endFrame

3.4.1

  • Updated the development app to React Native 0.62.2
  • Updated lottie-ios dependency to 3.1.8
  • Updated lottie-android dependency to 3.4.0

3.4.0 (May 20, 2020)

  • Add auto embed fastlane
  • Updated Android Building environment
  • Add testID prop to LottieView typescript definition
  • Added Pause & Resume commands. Also added onLayout prop.
  • Fix iOS speed not changing dynamically
  • Improved documentation

3.3.2 (Nov 15, 2019)

  • Removed support for Reanimated

3.3.1 (Nov 12, 2019)

  • Support for Reanimated
  • Added colorFilters prop for setting individually layers color
  • Documentation update

3.2.1 (Sep 30, 2019)

  • Fix for strange characters in some Java files

3.2.0 (Sep 30, 2019)

  • Updated lottie-ios dependency to 3.1.3
  • Updated lottie-android dependency to 3.0.7
  • Make NPM package leaner
  • Fix playing reverse on Android

3.1.1 (Sep 16, 2019)

  • Fix loading assets from app bundle on iOS
  • Remove unused deprecated publishNonDefault Gradle option
  • Support passing extensionless file names on Android

3.1.0 (Jul 25, 2019)

  • Support for lottie-android 3.0.0

3.0.4 (Jul 23, 2019)

  • Fix for auto linking on Android

3.0.3 (Jul 22, 2019)

  • Support for AndroidX
  • Removed deprecated rnpm support
  • Updated dependency for react-native-safe-module

3.0.2 (Jul 13, 2019)

  • Lock lottie-ios on version 3.3.0

3.0.1 (Jun 28, 2019)

  • Resolving UIViewManager deprecation warning

3.0.0 (Jun 1, 2019)

  • React Native lottie upgrade (iOS)

2.6.1 (March 29, 2019)

  • Lock lottie-ios on version 2.5.0
  • Enable RN projects to define the Android AppCompat Library version

2.6.0 (March 18, 2019)

  • Add Android app compatability support for RN 0.59 on Android (#455)

2.5.11 (December 20, 2018)

  • Improved documentation
  • Added onAnimationFinish callback
  • Fixed compilation errors

2.5.10 (November 6, 2018)

  • Fixed proptype checking on LottieView
  • Added missing typings
  • Use commonjs object export compatible syntax

2.5.9 (October 10, 2018)

  • Fixed Android build - deprecated build script directives
  • Fixed iOS build - header search paths
  • Added missing typings

2.5.8 (August 27, 2018)

  • Fixed Android flickering
  • Added missing duration prop

2.5.7 (August 27, 2018)

  • Fixed Android play method to be run only when the view is attached

2.5.6 (August 1, 2018)

  • Reverted dependencies to ensure compatibility with RN

2.5.5 (August 1, 2018)

  • Fixed Android builds

2.5.1 (July 30, 2018)

  • Fixed built library
  • Refactor + RN 0.56
  • Autoplay animations when animation's source has changed
  • Use project-wide properties and new dependency

2.5.0 (April 3, 2018)

  • Fixed typescript support
  • Bump Lottie to 2.5
  • Support Carthage projects
  • Fix resizeMode for iOS and TypeScript

2.3.2 (January 5, 2018)

  • Moved eslint deps to devDeps
  • Expose hardwareAccelerationAndroid (#254)

2.3.1 (December 5, 2017)

  • Bumped lottie-ios and lottie-android

2.3.0 (November 24, 2017)

Features and Improvements

  • speed prop
  • enableMergePathsAndroidForKitKatAndAbove prop for Android KitKat and above
  • Bump Lottie-Android to 2.3.0
  • Bump Lottie-iOS to 2.1.4
  • Added resizeMode prop similar to <Image>
  • Added play(fromFrame, toFrame)
  • Removed the need for a style prop

    Bugs Fixed

  • Improved the json serialization perf ~10x
  • Fixed some build related issues on iOS and for newer versions of RN
  • Enabled dev menu and reload for Android and iOS sample apps

1.0.6 (Feb 13, 2017)

  • Fix name conflict with new release of ios cocoapod

1.0.5 (Feb 10, 2017)

  • Allow iOS to be statically linked properly with react-native link

1.0.2 - 1.0.4 (Feb 8, 2017)

  • Fix Android NativeModule name
  • Depend on lottie-ios through NPM in order to make static linking easier
  • Fix bad Lottie.xcodeproj reference for static linking
  • Fix iOS header import order for static linking

1.0.1 (Feb 2, 2017)

  • Fix Header / Build issues with iOS on RN 0.40+

1.0.0 (Feb 1, 2017)

  • Official Release!