From db0e1fd8b3e4a200635fd26451a930c78f76c991 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 17 Sep 2018 14:28:42 +1000 Subject: [PATCH] update calculate total time duration with reverse duration seconds --- src/animateGroup.js | 1 + src/utils/calculateTotalDuration.js | 7 ++++++- test/utils/calculateTotalDuration.test.js | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/animateGroup.js b/src/animateGroup.js index 3e2abb2..4639b66 100644 --- a/src/animateGroup.js +++ b/src/animateGroup.js @@ -92,6 +92,7 @@ export default class AnimateGroup extends React.PureComponent { previous + calculateTotalDuration({ ...this.animations[id], + play, restAttributes, }); diff --git a/src/utils/calculateTotalDuration.js b/src/utils/calculateTotalDuration.js index 247c895..0510e80 100644 --- a/src/utils/calculateTotalDuration.js +++ b/src/utils/calculateTotalDuration.js @@ -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; }; diff --git a/test/utils/calculateTotalDuration.test.js b/test/utils/calculateTotalDuration.test.js index 1216b29..1479d83 100644 --- a/test/utils/calculateTotalDuration.test.js +++ b/test/utils/calculateTotalDuration.test.js @@ -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); }); });