Skip to content

Commit

Permalink
fix(play): take into account previous state of animation
Browse files Browse the repository at this point in the history
Closes #37.
  • Loading branch information
colinmeinke committed Jul 25, 2016
1 parent 12d44d0 commit ad721e8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core/play/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { currentState } from '../helpers';
import { events, state } from '../shape';

const init = ( playable, options ) => {
const { timeline, state } = playable;
const { timeline, state = {}} = playable;
const { animation = {}} = state;
const { duration: durationDefault, keyframes } = timeline;

const now = Date.now();
Expand All @@ -18,19 +19,19 @@ const init = ( playable, options ) => {
update,
} = {
...optionDefaults,
...animation,
...options,
};

let { currentProgress, currentReverse, iterationsComplete } = currentState( playable );

let { currentProgress, currentReverse, iterationsComplete } = currentState( animation );
let reverse = currentReverse;
let reverseChanged = false;

if ( typeof options.reverse !== 'undefined' ) {
currentReverse = options.reverse;
reverse = options.reverse;

if ( state.animation.started ) {
if ( animation.started ) {
reverseChanged = options.reverse !== currentReverse;
}
}
Expand All @@ -46,8 +47,8 @@ const init = ( playable, options ) => {

let iterations = reverse ? initialProgress : 1 - initialProgress;

if ( state.animation.started ) {
iterations = state.animation.iterations - iterationsComplete;
if ( animation.started ) {
iterations = animation.iterations - iterationsComplete;
}

if ( typeof options.iterations !== 'undefined' ) {
Expand All @@ -58,7 +59,7 @@ const init = ( playable, options ) => {
start();
}

playable.state.animation = {
state.animation = {
alternate,
currentProgress,
currentReverse,
Expand Down

0 comments on commit ad721e8

Please sign in to comment.