diff --git a/Libraries/Animated/src/__tests__/TimingAnimation-test.js b/Libraries/Animated/src/__tests__/TimingAnimation-test.js new file mode 100644 index 00000000000000..d63f44b3928514 --- /dev/null +++ b/Libraries/Animated/src/__tests__/TimingAnimation-test.js @@ -0,0 +1,32 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @emails oncall+react_native + */ + +'use strict'; + +const TimingAnimation = require('../animations/TimingAnimation'); + +describe('Timing Animation', () => { + it('should return array of 61 items', () => { + const timingAnim = new TimingAnimation({duration: 1000}); + const config = timingAnim.__getNativeAnimationConfig(); + + expect(config.frames.length).toBe(61); + expect(config.frames[60]).toBe(1); + expect(config.frames[59]).toBeLessThan(1); + }); + + it('should cope with zero duration', () => { + const timingAnim = new TimingAnimation({duration: 0}); + const config = timingAnim.__getNativeAnimationConfig(); + + expect(config.frames.length).toBe(1); + expect(config.frames[0]).toBe(1); + }); +}); diff --git a/Libraries/Animated/src/animations/TimingAnimation.js b/Libraries/Animated/src/animations/TimingAnimation.js index b73794f1333e44..8458ef9712f678 100644 --- a/Libraries/Animated/src/animations/TimingAnimation.js +++ b/Libraries/Animated/src/animations/TimingAnimation.js @@ -66,8 +66,9 @@ class TimingAnimation extends Animation { __getNativeAnimationConfig(): any { const frameDuration = 1000.0 / 60.0; const frames = []; - for (let dt = 0.0; dt < this._duration; dt += frameDuration) { - frames.push(this._easing(dt / this._duration)); + const numFrames = Math.round(this._duration / frameDuration); + for (let frame = 0; frame < numFrames; frame++) { + frames.push(this._easing(frame / numFrames)); } frames.push(this._easing(1)); return {