1.0.2 • Published 1 year ago

taro-lottie v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

taro-lottie

Lottie component for Taro, reference lottie-react-native add web and miniprogram support, base on lottie-web and lottie-miniprogram.

Installing

yarn add taro-lottie

Extra Installing For React Native

Install lottie-react-native (latest) and lottie-ios (3.4.0):

yarn add lottie-react-native
yarn add lottie-ios@3.4.0

Go to your ios folder and run:

pod install

Basic Usage

import LottieView, { LottieViewType } from 'taro-lottie'
import lottieData from './lottieData.json'

export default class Lottie extends Component {
  animation: LottieViewType | null = null
  // miniprogram needs to init after page onReady event
  onReady(){
    this.animation?.init()
  }
  render() {
    return (
      <LottieView
        ref={ animation => {
          this.animation = animation;
        }}
        style={
          {
            width: 100,
            height: 100
          }
        }
        autoPlay={true}
        loop={true}
        source={lottieData}
      />
    );
  }
}

Component API

Based on lottie-react-native project, under the Apache License 2.0.

PropDescriptionDefaultPlatform
sourceMandatory - 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')NoneAll
progressA number between 0 and 1, or an Animated number between 0 and 1. This number represents the normalized progress of the animation. If you update this prop, the animation will correspondingly update to the frame at that progress value. This prop is not required if you are using the imperative API.0All
speedThe speed the animation will progress. Sending a negative value will reverse the animation1All
durationThe duration of the animation in ms. Takes precedence over speed when set. This only works when source is an actual JS object of an animation.undefinedRN
loopA boolean flag indicating whether or not the animation should loop.trueAll
autoPlayA boolean flag indicating whether or not the animation should start automatically when mounted. This only affects the imperative API.falseAll
autoSizeA boolean flag indicating whether or not the animation should size itself automatically according to the width in the animation's JSON. This only works when source is an actual JS object of an animation.falseRN
resizeModeDetermines how to resize the animated view when the frame doesn't match the raw image dimensions. Supports cover, contain and center.containRN
styleStyle attributes for the view, as expected in a standard View, aside from border stylingNoneAll
imageAssetsFolderNeeded for Android to work properly with assets, iOS will ignore it.NoneAndroid
onAnimationFinishA callback function which will be called when animation is finished. This callback is called with a boolean isCancelled argument, indicating if the animation actually completed playing, or if it was cancelled, for instance by calling play() or reset() while is was still playing. Note that this callback will be called only when loop is set to false.NoneAll
renderModeOnly Android, a String flag to set whether or not to render with HARDWARE or SOFTWARE accelerationAUTOMATICAndroid
cacheCompositionOnly Android, a boolean flag indicating whether or not the animation should do caching.trueAndroid
colorFiltersAn array of objects denoting layers by KeyPath and a new color filter value (as hex string).[]RN
textFiltersAndroidOnly Android, an array of objects denoting text values to find and replace.[]Android
textFiltersIOSOnly iOS, an array of objects denoting text layers by KeyPath and a new string value.[]iOS

Methods (Imperative API):

Based on lottie-react-native project, under the Apache License 2.0.

MethodDescription
playPlay the animation all the way through, at the speed specified as a prop. It can also play a section of the animation when called as play(startFrame, endFrame).
resetReset the animation back to 0 progress.
pausePauses the animation.
resumeResumes the paused animation.
initInit the animation. Required for miniprogram

More

View more documentation, FAQ, help, examples, and more at airbnb.io/lottie

Example1

Example2

Example3

Community

Example4

License

MIT License

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1-0

2 years ago

0.0.1

2 years ago