cdvntr / react-native-confetti

Raining confetti made with react native animations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callback when confetti finishes?

techrah opened this issue · comments

Hello. Thank you for this awesome component. Works great so far!

I was wondering if there is any way to know (programatically) when the confetti animation is over. Perusing the code, I don't see any callback for this. I need to know this in order to update app state at appropriate time. During the animation, I need the state of a component to say in a "completed" state but after the animation, it needs to be in its "reset" state.

(I'm willing to submit a PR for this.)

Checked the source code for you. Don't know how to quote source code directly, but in confetti.js line 42, there exist a onComplete call back which I believe you can use to know when the animation has finished.

I tested it for you, but it seams like each confetti (default: 100) equals one Animated. Which means that the callback onComplete will occur 100times equal to the confettiCount prop. So if you want to work around this, I suggest you to just add a state counter that increments for each onComplete-callback and when it equals conffetiCount means it is finished.

Beware of state updates since that will trigger rerendering.

Thanks @kievu. I created my own fork and implemented the desired behaviour. I've create PR #16 to highlight the changes. I've been using it for about a month now and it's been working well.