npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lottie-react-component

v1.0.0

Published

Render your lottie animations in React, with full typescript support

Downloads

695

Readme

Lottie for React

npm Version License

Lottie component for React with runtime animation control and full typescript support.

Introduction

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

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

This library is a lottie-react-web fork that adds native typescript support, esm and cjs compatibility, and a rewrite with hooks

Getting Started

Get started with Lottie by installing the node module with yarn or npm:

yarn add lottie-react-component

or

npm i --save lottie-react-component

Usage

<Lottie> component can be used in a declarative way:

import React from "react";
import Lottie from "lottie-react-component";
import animation from "./animation.json";

const App = () => <Lottie animationData={animation} loop />;

export default App;

By default it will automatically play the animation in loop.

Lottie's animation control can be set via props. Here is an example of a toggle animation that reacts on click:

import React, { Component } from 'react';
import Lottie from 'lottie-react-component'
import toggleAnimation from './toggleAnimation.json'

export default const App = () => {
  const [isToggled, setIsToggled] = useState(false);

  return  (
    <div
      onClick={() => {
        setIsToggled(t => !t);
      }}
    >
      <Lottie
        direction={isToggled ? 1 : -1}
        animationData={toggleAnimation}
        loop={false}
      />
    </div>
  )
}

export default App

API

These are all props available:

Props

| Prop | Description | Default | | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- | | animationData | Mandatory - The source of the animation. | — | | assetsPath | Mandatory - The root path for external assets. | images | | loop | Play animation non-stop in a loop. | true | | autoplay | Automatically play animation when it is instantiated. | true | | renderer | The method for rendering the animation. | svg | | rendererSettings | Customize bodymovin aspect ratio configurations. | — | | animationControl | This is where you can change the animation at runtime. A key value pair of a After Effects property path and the a custom value to apply to it. See details below. | — | | width | Sets the width of the animation container. | 100% | | height | Sets the heigth of the animation container. | 100% | | isStopped | A boolean flag indicating whether or not the animation is stopped. | false | | isPaused | A boolean flag indicating whether or not the animation is paused. | false | | speed | An integer indicating the speed of the animation ( 1 is 100%.) | 1 | | direction | An integer indicating wether the animation progresses in the usual (1) or reverse (-1) direction | 1 | | ariaRole | A string indicating the animation container ariaRole property | "button" | | ariaLabel | A string indicating the animation container ariaLabel property | "animation" | | title | A string indicating the animation container title property | "" |

Changing animation at runtime

You can target an specific After Effects layer property and change it at runtime by passing setting a property object on the <Lottie> prop. Example:

import React from "react";
import Lottie from "lottie-react-component";
import animation from "./animation.json";

const Animation = ({ x, y }) => (
  <Lottie
    animationData={animation}
    animationControl={{
      "Square,Transform,Position": [x, y],
    }}
  />
);

export default Animation;

This will override the Position value of the layer JoyStkCtrl01 at runtime.

Lottie is compatible with Joystick 'n Sliders After Effects plugin, so you can create amazing animations easily.