Coder Social home page Coder Social logo

react-lottie-player's Introduction

Fully declarative React Lottie player

Inspired by several existing packages wrapping lottie-web for React, I created this package because I wanted something that just works and is simple to use. None of the alternatives properly handle changes of props like playing/pausing/segments. This lead to lots of hacks to get the animations to play correctly.

react-lottie-player is a complete rewrite using modern hooks ๐ŸŽฃ for more readable code, an easy to use, seamless and fully declarative control of the lottie player.

Does not leak memory like lottie-web if you use repeaters.

Tests NPM JavaScript Style Guide

Install

npm install --save react-lottie-player

Usage

import React from 'react'
import Lottie from 'react-lottie-player'
// Alternatively:
// import Lottie from 'react-lottie-player/dist/LottiePlayerLight'


import lottieJson from './my-lottie.json'

export default function Example() {
  return (
    <Lottie
      loop
      animationData={lottieJson}
      play
      style={{ width: 150, height: 150 }}
    />
  )
}

Example

Open live example

View example code

Lazy loading example

const MyComponent = () => {
  const [animationData, setAnimationData] = useState();

  useEffect(() => {
    import('./animation.json').then(setAnimationData);
  }, []);

  if (!animationData) return <div>Loading...</div>;
  return <Lottie animationData={animationData} />;
}

See also #11

LottiePlayerLight

The default lottie player uses eval. If you don't want eval to be used in your code base, you can instead import react-lottie-player/dist/LottiePlayerLight. For more discussion see #39.

Lottie animation track scrolling div

See example/App.js (ScrollTest) in live example.

Resize mode: cover

If you want the animation to fill the whole container, you can pass this prop. See also #55:

<Lottie rendererSettings={{ preserveAspectRatio: 'xMidYMid slice' }} />

API

See https://github.com/airbnb/lottie-web

View PropTypes

Releasing

  • Commit & wait for CI tests
  • np

Credits

License

MIT ยฉ mifi


Made with โค๏ธ in ๐Ÿ‡ณ๐Ÿ‡ด

More apps by mifi.no

Follow me on GitHub, YouTube, IG, Twitter for more awesome content!

react-lottie-player's People

Contributors

mifi avatar dependabot[bot] avatar simonpkerr avatar mpeyper avatar kcirtaptrick avatar hood avatar davidlpc1 avatar rodbs avatar vgpena avatar kb-ig avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.