Skip to content

Commit

Permalink
Fixed behavior when onFinish and onCancel props are changed on an Ani…
Browse files Browse the repository at this point in the history
…mation
  • Loading branch information
Lukas Laag committed Dec 15, 2016
1 parent cc531e7 commit 629ab97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Animation extends Animatable {
/**
* Start the animation and set the player in the state
*/
startAnimation() {
return this.setPlayer(this.node.animate(this.keyframes, this.timing));
startAnimation(props) {
return this.setPlayer(this.node.animate(this.keyframes, this.timing), props);
}

componentWillReceiveProps(nextProps) {
Expand All @@ -35,7 +35,7 @@ class Animation extends Animatable {
this.timing = newTiming;
this.keyframes = keyframes;
// start the new animation with the new config
this.startAnimation();
this.startAnimation(nextProps);
}
}

Expand Down
16 changes: 5 additions & 11 deletions src/mixins/playable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ export default {
const { detachHandlersFromPlayer } = this;
detachHandlersFromPlayer(player);
},
attachHandlersToPlayer(player) {
if (this.props.onFinish) {
player.onfinish = this.props.onFinish;
}

if (this.props.onCancel) {
player.oncancel = this.props.onCancel;
}

attachHandlersToPlayer(player, props) {
player.onfinish = props.onFinish;
player.oncancel = props.onCancel;
},
detachHandlersFromPlayer(player) {
player.onfinish = null;
Expand Down Expand Up @@ -44,15 +38,15 @@ export default {
break;
}
},
setPlayer(player) {
setPlayer(player, props) {
// cancel existing animation
if (this.state.player) {
this.state.player.cancel();
}
this.setState({ player });

// attach native handlers
this.attachHandlersToPlayer(player);
this.attachHandlersToPlayer(player, props || this.props);

return player;
},
Expand Down

0 comments on commit 629ab97

Please sign in to comment.