2.0.0-alpha.0 • Published 6 years ago

@jeremyjonas/react-lottie v2.0.0-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Lottie Animation View for React (Angular, Vue)

npm version

Demo

https://chenqingspring.github.io/react-lottie

Wapper of bodymovin.js

bodymovin is Adobe After Effects plugin for exporting animations as JSON, also it provide bodymovin.js for render them as svg/canvas/html.

Why Lottie?

Flexible After Effects features

We currently support solids, shape layers, masks, alpha mattes, trim paths, and dash patterns. And we’ll be adding new features on a regular basis.

Manipulate your animation any way you like

You can go forward, backward, and most importantly you can program your animation to respond to any interaction.

Small file sizes

Bundle vector animations within your app without having to worry about multiple dimensions or large file sizes. Alternatively, you can decouple animation files from your app’s code entirely by loading them from a JSON API.

Learn morehttp://airbnb.design/lottie/

Looking for lottie files › https://www.lottiefiles.com/

Installation

npm install --save react-lottie

or

yarn add react-lottie

Usage

import React from 'react'
import Lottie from 'react-lottie';
import * as animationData from './data.json'

export default () => <Lottie animationData={pinJump} />

Download example data.json file from Lottie Files

View Storybook Examples for Additional Usage

Storybook demo files are located in stories directory.

Props

The <Lottie /> Component supports the following properties:

PropertyTypeDefault valueDescription
animationDataobjectAn Object with the exported animation data
isStoppedboolnullControls stopped behavior of Lottie instance
isPausedboolnullControls paused behavior of Lottie instance
segmentsnumber / [number]Defines what segment of the animation to play using playSegments(segments, force). Can also be [number] for sequential segment playback
forceSegmentsboolfalse*Indicates force parameter value of playSegments(segments, force) when using segments
loopbool / numberfalse*Indicates if animation is looping, defaults to lottie default of false
speednumber1Controls speed of animation playback through setSpeed(speed)
directionnumber1*Controls direction of animation playback through setDirection(direction)
eventListenersobjectRegisters event callbacks with Lottie instance.
clickToPauseboolfalseEnables clicking on animation to toggle play/pause
heightnumber / stringShorthand for setting style.height
widthnumber / stringShorthand for setting style.width
classNamestringSets className property of container div
styleobjectSets inline style of container div
style.widthnumber / string100%
style.heightnumber / string100%
ariaRolestringSets aria role of container div
ariaLabelstringSets aria aria-label of container div
titlestringSets aria title of container div
innerReffuncCallback to receive reference to container div node
animationReffuncCallback to receive reference to Lottie animation instance
onCompletefuncDirect event callback for complete event
onLoopCompletefuncDirect event callback for loopComplete event
onEnterFramefuncDirect event callback for enterFrame event
onSegmentStartfuncDirect event callback for segmentStart event
***any*All other properties are proxied to lottie.loadAnimation(options)

default*: Indicates default is undefined but lottie-web default is type in {type}* format.

Migrating from v1 => v2

Version 2 takes the opinion that react-lottie should match the default functionality of lottie-web as much as possible. Any additional functionality provided by react-lottie is therefore disabled by default, such as click to pause.

For reconciliation performance the options property has been removed in favor of explicitly defining each property on the component directly, allowing for usage of React.PureComponent. This also explicitly defines which properties are controlled vs uncontrolled by react-lottie.

options property has been removed, directly set all options on the component

# v1
<Lottie options={{animationData: myAnimData, loop: true }} />

#v2
<Lottie animationData={myAnimData} loop={true} />

loop property is defaulted to undefined to take on lottie-web default of false

# v1
<Lottie animationData={myAnimData} />

# v2
<Lottie animationData={myAnimData} loop={true} />

If you use isClickToPauseDisabled functionality, this has disabled by default and changed to clickToPause property

# v1
<Lottie animationData={myAnimData} isClickToPauseDisabled={true} />

# v2
<Lottie animationData={myAnimData} />
# v1
<Lottie animationData={myAnimData} isClickToPauseDisabled={false} />

# v2
<Lottie animationData={myAnimData} clickToPause={true} />

Related Projects

Contribution

Your contributions and suggestions are heartily welcome.

License

MIT