Lottie-react-native: Feature request: Play in reverse

Created on 23 Mar 2017  路  3Comments  路  Source: lottie-react-native/lottie-react-native

The API does not yet include an option to play in reverse. This would enable reuse of animations instead of being required to export a reversed version of the same animation through Bodymovin.

enhancement

Most helpful comment

You can play it reversed by animating the progress value to go from 1 to 0.

import React from 'react';
import { Animated } from 'react-native';
import Animation from 'lottie-react-native';

export default class BasicExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      progress: new Animated.Value(1), // <-- Start from the end of animation
    };
  }

  componentDidMount() {
    Animated.timing(this.state.progress, {
      toValue: 0, // <-- Animate to the beginning of animation
      duration: 5000,
    }).start();
  }

  render() {
    return (
      <Animation
        style={{
          width: 200,
          height: 200,
        }}
        source={require('../path/to/animation.json')}
        progress={this.state.progress}
      />
    );
  }
}

All 3 comments

You can play it reversed by animating the progress value to go from 1 to 0.

import React from 'react';
import { Animated } from 'react-native';
import Animation from 'lottie-react-native';

export default class BasicExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      progress: new Animated.Value(1), // <-- Start from the end of animation
    };
  }

  componentDidMount() {
    Animated.timing(this.state.progress, {
      toValue: 0, // <-- Animate to the beginning of animation
      duration: 5000,
    }).start();
  }

  render() {
    return (
      <Animation
        style={{
          width: 200,
          height: 200,
        }}
        source={require('../path/to/animation.json')}
        progress={this.state.progress}
      />
    );
  }
}

@AWrightIV You can also set the speed to a negative value.

@gpeal I was looking into this and i noticed that setting speed to negative does nothing on ios is this a bug? on android it works perfectly btw

Was this page helpful?
0 / 5 - 0 ratings

Related issues

snydercreative picture snydercreative  路  4Comments

ASkyBig picture ASkyBig  路  4Comments

androsanta picture androsanta  路  5Comments

duringg picture duringg  路  5Comments

AlirezaAkbarix picture AlirezaAkbarix  路  3Comments