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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop animation property #21

Closed
eneskaya opened this issue Feb 2, 2017 · 10 comments
Closed

Loop animation property #21

eneskaya opened this issue Feb 2, 2017 · 10 comments

Comments

@eneskaya
Copy link

eneskaya commented Feb 2, 2017

First of all: 馃憤 馃憤 馃憤

Would be nice to have a convenient way of starting looped animations! So not only calling play() but also loop()

@lelandrichardson
Copy link
Collaborator

Great idea.

@eneskaya
Copy link
Author

eneskaya commented Feb 6, 2017

Nice, works great 馃憤

@femontanha
Copy link

@eneskaya do you know how I do a loop? I tried to add this loop property but doesn't work

<Animation
  source={ json }
  progress={ this.state.progress }
  loop={ true }
/>

@eneskaya
Copy link
Author

eneskaya commented Feb 6, 2017

@femontanha It only works with the imperative API, so be sure NOT to use progress prop. Instead do something like this:

...

componentDidMount() {
    this.animation.start();
}

render() {
    <Animation
        source={json}
        style={{width: 100, height: 100}}
        ref={(animation) => this.animation = animation} // the ref to the LottieAnimation component 
        loop
    />
}

@eneskaya eneskaya closed this as completed Feb 6, 2017
@xeroxoid
Copy link

xeroxoid commented Mar 30, 2017

@eneskaya can you please post the whole snippet. I cant seem to figure out how you referenced initialized the animation.

@eneskaya
Copy link
Author

eneskaya commented Apr 4, 2017

@xeroxoid what do you mean, how I initialized the animation? (sorry for late reply)

@saddacracker
Copy link

saddacracker commented Apr 20, 2017

Echoing @xeroxoid. I get a reference error when I use the imperative API.

undefined is not an object (evaluating 'this.animation.start')

Turns out the Animation is not initialized when the componentDidMount is run so I used a timer. Definitely open to suggestions.

  componentDidMount() {
      this.initAnimation();
  }

  initAnimation(){
    if (!this.animation){
      setTimeout(() => {
        this.initAnimation();
      }, 100);
    } else {
        this.animation.play();
    }
  }

@agrosner
Copy link

agrosner commented Oct 3, 2017

 <Animation
   loop
   source={source}
   ref={(animation) => animation.play()}
 />

This seems to work even better

@mjsisley
Copy link

Thoughts on allowing loop to take a number as an option?

For cases where you want the animation to loop some amount of times less than infinity.

@matthieupinte
Copy link

matthieupinte commented Nov 23, 2017

@agrosner is working but need to add a check (plz don鈥檛 ask me why ^^) :

<Animation
  loop
  source={source}
  ref={animation => {
    if (animation) animation.play()
  }}
/>

"lottie-react-native": "^2.2.7"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants