Code Monkey home page Code Monkey logo

Comments (10)

saddacracker avatar saddacracker commented on May 17, 2024 12

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();
    }
  }

from lottie-react-native.

matthieupinte avatar matthieupinte commented on May 17, 2024 5

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

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

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

from lottie-react-native.

agrosner avatar agrosner commented on May 17, 2024 4
 <Animation
   loop
   source={source}
   ref={(animation) => animation.play()}
 />

This seems to work even better

from lottie-react-native.

mjsisley avatar mjsisley commented on May 17, 2024 3

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.

from lottie-react-native.

xeroxoid avatar xeroxoid commented on May 17, 2024 1

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

from lottie-react-native.

lelandrichardson avatar lelandrichardson commented on May 17, 2024

Great idea.

from lottie-react-native.

eneskaya avatar eneskaya commented on May 17, 2024

Nice, works great πŸ‘

from lottie-react-native.

femontanha avatar femontanha commented on May 17, 2024

@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 }
/>

from lottie-react-native.

eneskaya avatar eneskaya commented on May 17, 2024

@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
    />
}

from lottie-react-native.

eneskaya avatar eneskaya commented on May 17, 2024

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

from lottie-react-native.

Related Issues (20)

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.