Gathering detailed insights and metrics for lottie-react-native
Gathering detailed insights and metrics for lottie-react-native
Gathering detailed insights and metrics for lottie-react-native
Gathering detailed insights and metrics for lottie-react-native
npm install lottie-react-native
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
16,759 Stars
829 Commits
1,776 Forks
227 Watching
11 Branches
137 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
Kotlin (28.14%)
C++ (20.27%)
TypeScript (15.08%)
Swift (11.4%)
C# (11.35%)
Objective-C (4.16%)
Objective-C++ (3.63%)
JavaScript (3.3%)
Ruby (2.19%)
HTML (0.39%)
C (0.09%)
Cumulative downloads
Total Downloads
Last day
-0.3%
79,143
Compared to previous day
Last week
2.5%
398,043
Compared to previous week
Last month
9.6%
1,654,519
Compared to previous month
Last year
24.9%
17,171,771
Compared to previous year
4
18
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.
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 migration guide.
Stay informed to ensure a seamless transition to the latest version. Thank you!
lottie-react-native
(latest):yarn add lottie-react-native
Go to your ios folder and run:
pod install
lottie-react-native
(latest):yarn add lottie-react-native
yarn add @lottiefiles/dotlottie-react
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.
1<PropertyGroup Label="LottieReactNativeProps"> 2 <LottieReactNativeDir>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\lottie-react-native\package.json'))\node_modules\lottie-react-native</LottieReactNativeDir> 3</PropertyGroup> 4<ImportGroup Label="LottieReactNativeTargets"> 5 <Import Project="$(LottieReactNativeDir)\src\windows\cppwinrt\PropertySheets\LottieGen.Auto.targets" /> 6</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:
<EnableLottieDynamicSource>false</EnableLottieDynamicSource>
in your project file and omit this reference.For C++ apps, you'll need these NuGet packages:
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:
1// C# 2PackageProviders.Add(new LottieReactNative.ReactPackageProvider(new AnimatedVisuals.LottieCodegenSourceProvider()));
1// C++ 2#include <winrt/LottieReactNative.h> 3#include <winrt/AnimatedVisuals.h> 4 5... 6 7PackageProviders().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:
1<!-- .vcxproj or .csproj --> 2<ItemGroup> 3 <LottieAnimation Include="Assets/Animations/MyAnimation.json" Name="MyAnimation" /> 4</ItemGroup>
1// js 2<LottieView source={"MyAnimation"} style={{width: "100%", height: "100%"}} />
Codegen is available to both C# and C++ applications. Dynamic loading of JSON strings at runtime is currently only supported in C# applications.
Lottie iOS and Lottie React Native do not collect any data. We provide this notice to help you fill out App Privacy Details. Both libraries provide privacy manifests (Lottie iOS's privacy manifest, Lottie React Native's privacy manifest) which can be included in your app and are available as bundle resources within the libraries by default.
Lottie can be used in a declarative way:
1import React from "react"; 2import LottieView from "lottie-react-native"; 3 4export default function Animation() { 5 return ( 6 <LottieView 7 source={require("../path/to/animation.json")} 8 style={{width: "100%", height: "100%"}} 9 autoPlay 10 loop 11 /> 12 ); 13}
Additionally, there is an imperative API which is sometimes simpler.
1import React, { useEffect, useRef } from "react"; 2import LottieView from "lottie-react-native"; 3 4export default function AnimationWithImperativeApi() { 5 const animationRef = useRef<LottieView>(null); 6 7 useEffect(() => { 8 animationRef.current?.play(); 9 10 // Or set a specific startFrame and endFrame with: 11 animationRef.current?.play(30, 120); 12 }, []); 13 14 return ( 15 <LottieView 16 ref={animationRef} 17 source={require("../path/to/animation.json")} 18 style={{width: "100%", height: "100%"}} 19 /> 20 ); 21}
Lottie's animation view can be controlled by either React Native Animated or Reanimated API.
1import React, { useEffect, useRef, Animated } from "react"; 2import { Animated, Easing } from "react-native"; 3import LottieView from "lottie-react-native"; 4 5const AnimatedLottieView = Animated.createAnimatedComponent(LottieView); 6 7export default function ControllingAnimationProgress() { 8 const animationProgress = useRef(new Animated.Value(0)); 9 10 useEffect(() => { 11 Animated.timing(animationProgress.current, { 12 toValue: 1, 13 duration: 5000, 14 easing: Easing.linear, 15 useNativeDriver: false, 16 }).start(); 17 }, []); 18 19 return ( 20 <AnimatedLottieView 21 source={require("../path/to/animation.json")} 22 progress={animationProgress.current} 23 style={{width: "100%", height: "100%"}} 24 /> 25 ); 26}
Changing color of layers:
NOTE: This feature may not work properly on Android. We will try fix it soon.
1import React from "react"; 2import LottieView from "lottie-react-native"; 3 4export default function ChangingColorOfLayers() { 5 return ( 6 <LottieView 7 source={require("../path/to/animation.json")} 8 colorFilters={[ 9 { 10 keypath: "button", 11 color: "#F00000", 12 }, 13 { 14 keypath: "Sending Loader", 15 color: "#F00000", 16 }, 17 ]} 18 style={{width: "100%", height: "100%"}} 19 autoPlay 20 loop 21 /> 22 ); 23}
.lottie
filesYou need to modify your metro.config.js
file accordingly by adding lottie
extension to the assetExts
array:
1const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config"); 2 3const defaultConfig = getDefaultConfig(__dirname); 4 5/** 6 * Metro configuration 7 * https://facebook.github.io/metro/docs/configuration 8 * 9 * @type {import('metro-config').MetroConfig} 10 */ 11const config = { 12 resolver: { 13 assetExts: [...defaultConfig.resolver.assetExts, "lottie"], 14 }, 15}; 16 17module.exports = mergeConfig(getDefaultConfig(__dirname), config);
Create a file in the following path __mocks__/lottieMock.js
and add the following code:
1module.exports = "lottie-test-file-stub";
Then add the following to your jest.config.js
file:
1module.exports = { 2 ... 3 moduleNameMapper: { 4 ..., 5 '\\.(lottie)$': '<rootDir>/jest/__mocks__/lottieMock.js', 6 }, 7 ... 8}
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). | [] |
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.
When it comes to animations, please validate that your animation file is compliant with the standard (for example, that it doesn't have floating number in places that require integers). If you have an animation that is not working as expected, it is always recommended that you look at the Logcat output on Android and the console on iOS, as both ecosystems will have logs attached in case of an error that usually highlights what has gone wrong.
View more documentation, FAQ, help, examples, and more at airbnb.io/lottie
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
10 commit(s) and 13 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
Found 25/30 approved changesets -- score normalized to 8
Reason
binaries present in source code
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
43 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More