chenglou / react-tween-state

React animation.
Other
1.74k stars 70 forks source link

call onEnd with nextTick in case component is unmounted #20

Closed pstoica closed 9 years ago

pstoica commented 9 years ago

I had a situation where I unmounted a component in the onEnd function. I was invoking the animation from a container. Maybe weird, but it works.

Anyway, this still runs after onEnd is invoked, causing a race condition since the component is unmounted:

    this.setState({
      tweenQueue: newTweenQueue,
    });

    requestAnimationFrame(this._rafCb);

This PR should fix this!

chenglou commented 9 years ago

Can you give me an example snippet of your code please?

pstoica commented 9 years ago
    var hideOverlay = () => {
      this.setState({
        isOverlayShown: false,
        isOverlayHiding: false
      });
    };   

    this.setState({ isOverlayHiding: true });

    overlay.hideAnimation(hideOverlay);

hideOverlay is the onEnd function. This is kludgy and I read your animation gist afterwards. It would probably be better to use ReactTransitionGroup + react-tween-state for now instead of managing animated children like this?

chenglou commented 9 years ago

@pstoica Oh geez sorry for the wait. I thought I had an email reminder for this but apparently not. #24 raised the same problem. It's now solved in a different way. You get to keep your sync callback, whatever the implications of that is.

I'll close this now. Can you try the new release (0.0.5)? If it doesn't work then reopen the issue please.

Sorry again!

pstoica commented 9 years ago

No worries, that looks like a good fix. I'm pretty sure it'll work for my case. Thanks for your help!