From 0d0b4c947b7fa5e55d4f79b7f0892dd4525dbfa0 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Wed, 8 Jul 2015 04:17:54 -0700 Subject: [PATCH] [RN: Animated] Fix delay anims Summary: They weren't calling onEnd because of duration: 0 optimiziation. --- Libraries/Animation/Animated/Animated.js | 1 + .../Animated/__tests__/Animated-test.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Libraries/Animation/Animated/Animated.js b/Libraries/Animation/Animated/Animated.js index fd0809825..e4692d610 100644 --- a/Libraries/Animation/Animated/Animated.js +++ b/Libraries/Animation/Animated/Animated.js @@ -172,6 +172,7 @@ class TimingAnimation extends Animation { var start = () => { if (this._duration === 0) { this._onUpdate(this._toValue); + this.__debouncedOnEnd({finished: true}); } else { this._startTime = Date.now(); this._animationFrame = window.requestAnimationFrame(this.onUpdate.bind(this)); diff --git a/Libraries/Animation/Animated/__tests__/Animated-test.js b/Libraries/Animation/Animated/__tests__/Animated-test.js index bd9ef68e5..f5068dc57 100644 --- a/Libraries/Animation/Animated/__tests__/Animated-test.js +++ b/Libraries/Animation/Animated/__tests__/Animated-test.js @@ -279,6 +279,32 @@ describe('Animated Parallel', () => { }); }); +describe('Animated delays', () => { + it('should call anim after delay in sequence', () => { + var anim = {start: jest.genMockFunction(), stop: jest.genMockFunction()}; + var cb = jest.genMockFunction(); + Animated.sequence([ + Animated.delay(1000), + anim, + ]).start(cb); + jest.runAllTimers(); + expect(anim.start.mock.calls.length).toBe(1); + expect(cb).not.toBeCalled(); + anim.start.mock.calls[0][0]({finished: true}); + expect(cb).toBeCalledWith({finished: true}); + }); + it('should run stagger to end', () => { + var cb = jest.genMockFunction(); + Animated.stagger(1000, [ + Animated.delay(1000), + Animated.delay(1000), + Animated.delay(1000), + ]).start(cb); + jest.runAllTimers(); + expect(cb).toBeCalledWith({finished: true}); + }); +}); + describe('Animated Events', () => { it('should map events', () => { var value = new Animated.Value(0);