Cannot change onFinish or onCancel callbacks on an animation
laaglu opened this issue · 2 comments
Attempting to change the value of onFinish or onCancel on an animation results in an unexpected behavior: The new callback is not called and the callback set by the previous change of the onFinish property is called. Furthermore, it is not possible to reset onFinish or onCancel (make them null again) once they have been set.
I think there is a lifecycle management problem. The values of onFinish or onCancel are set in playable.attachHandlersToPlayer and taken from this.props. If one updates the props on the Animation, componentWillReceiveProps will be called. This calls in turn indirectly invokes playable.attachHandlersToPlayer. At that stage alas, the new props have not yet been set and playable.attachHandlersToPlayer sets onFinish and onCancel to the current props values, not the new ones. It also checks onFinish and onCancel for nullity which prevents resetting these props. This explains the current incorrect behavior.
I have prototyped a fix, as this problem was blocking for me. However it is a bit ugly, I have uploaded it to a branch in my repo if you want to have a look at it though.
@laaglu thanks I see the issue. If you have a fix already, please PR. It would be great if you could write a test that verifies the correct behavior as well. If you don't have time to PR, I can address this as soon as I can. Thanks for your help, I really appreciate it! 👍
I have made a PR with the fix. It only fixes Animation.js, because it is the only part of the library I currently use but the problem may exist in other parts of the library (AnimationGroup ?).