Skip to content

Commit

Permalink
update calculate total time duration with reverse duration seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill authored and Bill committed Sep 17, 2018
1 parent 7276e0d commit db0e1fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/animateGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default class AnimateGroup extends React.PureComponent<Props, State> {
previous +
calculateTotalDuration({
...this.animations[id],
play,
restAttributes,
});

Expand Down
7 changes: 6 additions & 1 deletion src/utils/calculateTotalDuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ export default ({
durationSeconds = 0,
delaySeconds = 0,
overlaySeconds = 0,
reverseDurationSeconds = 0,
play,
}: {
durationSeconds?: number,
delaySeconds?: number,
overlaySeconds?: number,
reverseDurationSeconds?: number,
play: boolean,
}): number => {
const duration = parseFloat(durationSeconds) + parseFloat(delaySeconds);
const duration =
parseFloat(play ? durationSeconds : reverseDurationSeconds || durationSeconds) + parseFloat(delaySeconds);
const withEarlySeconds = duration - parseFloat(overlaySeconds);
return withEarlySeconds * 1000;
};
20 changes: 18 additions & 2 deletions test/utils/calculateTotalDuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ import calculateTotalDuration from '../../src/utils/calculateTotalDuration';

describe('calculateTotalDuration', () => {
it('should return correctly seconds', () => {
expect(calculateTotalDuration({ durationSeconds: 1, delaySeconds: 1, overlaySeconds: 1 })).toEqual(1000);
expect(calculateTotalDuration({ durationSeconds: 1, delaySeconds: 1, overlaySeconds: 1, play: true })).toEqual(
1000,
);

expect(calculateTotalDuration({ durationSeconds: 2, delaySeconds: 1, overlaySeconds: 1 })).toEqual(2000);
expect(calculateTotalDuration({ durationSeconds: 2, delaySeconds: 1, overlaySeconds: 1, play: true })).toEqual(
2000,
);
});

it('should return correctly seconds when play on reverse', () => {
expect(
calculateTotalDuration({
durationSeconds: 1,
reverseDurationSeconds: 2,
delaySeconds: 1,
overlaySeconds: 1,
play: false,
}),
).toEqual(2000);
});
});

0 comments on commit db0e1fd

Please sign in to comment.