1.3.2 • Published 4 years ago

@rafaelns/react-lottie v1.3.2

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

Lottie for React

npm Version License

Lottie component for React

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

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

Installing

Install @rafaelns/react-lottie:

yarn add @rafaelns/react-lottie

or

npm i --save @rafaelns/react-lottie

Usage

LottieView can be used in a declarative way:

import React from 'react';
import Lottie from '@rafaelns/react-lottie';
import animation from './animation.json'

export const BasicExample = () => {
  return <Lottie source={animation} autoPlay loop />;
}

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

import React, { useRef, useEffect } from 'react';
import Lottie, { AnimationItem } from '@rafaelns/react-lottie';
import animation from '../path/to/animation.json'

export const BasicExample = () => {
  const animationRef = useRef<AnimationItem>()
  
  useEffect(() {
    animationRef.current.play();
    // Or set a specific startFrame and endFrame with:
    animationRef.current.play(30, 120);
  }, [])

  return (
    <Lottie
      animationRef={animationRef}
      source={animation}
    />
  );
}

API

You can find the full list of methods available in API document.

PropDescriptionDefault
sourceMandatory - The source of animation. JS object of an animation.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.false
speedThe speed the animation will progress. Sending a negative value will reverse the animation.1

And any other div props.

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.0.2

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago