Skip to content

Commit

Permalink
Fix bug where old onAnimationEnd handler would be called
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed May 31, 2018
1 parent 03bfeb7 commit 386dd3f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions createAnimatableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ export default function createAnimatableComponent(WrappedComponent) {
duration,
delay,
onAnimationBegin,
onAnimationEnd,
iterationDelay,
} = this.props;
if (animation) {
const startAnimation = () => {
onAnimationBegin();
this.startAnimation(duration, 0, iterationDelay, onAnimationEnd);
this.startAnimation(duration, 0, iterationDelay, endState =>
this.props.onAnimationEnd(endState),
);
this.delayTimer = null;
};
if (delay) {
Expand All @@ -326,7 +327,6 @@ export default function createAnimatableComponent(WrappedComponent) {
easing,
transition,
onAnimationBegin,
onAnimationEnd,
} = props;

if (transition) {
Expand All @@ -338,7 +338,9 @@ export default function createAnimatableComponent(WrappedComponent) {
this.setAnimation(animation);
} else {
onAnimationBegin();
this.animate(animation, duration).then(onAnimationEnd);
this.animate(animation, duration).then(endState =>
this.props.onAnimationEnd(endState),
);
}
} else {
this.stopAnimation();
Expand Down Expand Up @@ -417,7 +419,12 @@ export default function createAnimatableComponent(WrappedComponent) {
this.props.animation &&
(iterationCount === 'infinite' || currentIteration < iterationCount)
) {
this.startAnimation(duration, currentIteration, iterationDelay, callback);
this.startAnimation(
duration,
currentIteration,
iterationDelay,
callback,
);
} else if (callback) {
callback(endState);
}
Expand Down

0 comments on commit 386dd3f

Please sign in to comment.