Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop prop isnt working #35

Closed
baires opened this issue Feb 3, 2017 · 7 comments
Closed

Loop prop isnt working #35

baires opened this issue Feb 3, 2017 · 7 comments

Comments

@baires
Copy link

baires commented Feb 3, 2017

I have a very simple view as you can see:

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

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'space-around',
    alignItems: 'center',
  },
  animationContainer: {
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'column',
  },
  animation: {
    width: 400,
    height: 400,
  },
});

export default class Loading extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      progress: new Animated.Value(0),
    };
  }

  componentDidMount() {
    Animated.timing(this.state.progress, {
      toValue: 1,
      duration: 5000,
    }).start();
  }

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.animationContainer}>
          <Animation
            style={styles.animation}
          // eslint-disable-next-line global-require
            source={require('./animation.json')}
            progress={this.state.progress}
            loop
          />
        </View>
      </View>
    );
  }
}

Im just trying to loop the animation, but no luck so far. Not sure if this is RN issue o lottie for iOS.

Im on

react-native-cli: 1.0.0
react-native: 0.40.0
``
@indivisable
Copy link

It works for me when using the imperative API


import React from 'react';
import Animation from 'lottie-react-native';

export default class BasicExample extends React.Component {
  componentDidMount() {
    this.animation.play();
  }

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

@baires
Copy link
Author

baires commented Feb 4, 2017

I didn't try the imperative API, just pointing that looping on the component API isn't working

@lelandrichardson
Copy link
Collaborator

At the moment loop is only applicable to the imperative API. I'm not quite sure how it would work with the Animated API, since the animation progress is controlled by an animated value (which you would be able to loop yourself if you wanted, though it's not straight-forward).

I'm happy to take suggestions on how this could/should work

@baires
Copy link
Author

baires commented Feb 4, 2017

If there was a callback when the animation ends something like onAnimationComplete we can reset the animation again.

@lelandrichardson
Copy link
Collaborator

if you're using the Animated API, this callback already exists. You would animate from 0 -> 1, and then reset

@lelandrichardson
Copy link
Collaborator

Though, I do think that the Animated API could use a loop API. I know I had talked to vjeux about this at some point. Perhaps it's time to make a PR

@baires
Copy link
Author

baires commented Feb 4, 2017

Sounds good, thanks for your feedback!

@baires baires closed this as completed Feb 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants