diff --git a/Libraries/Animation/Animated/Animated.js b/Libraries/Animation/Animated/Animated.js index f99913f50..8f3f38398 100644 --- a/Libraries/Animation/Animated/Animated.js +++ b/Libraries/Animation/Animated/Animated.js @@ -479,7 +479,13 @@ class SpringAnimation extends Animation { if (this._tension !== 0) { isDisplacement = Math.abs(this._toValue - position) <= this._restDisplacementThreshold; } + if (isOvershooting || (isVelocity && isDisplacement)) { + if (this._tension !== 0) { + // Ensure that we end up with a round value + this._onUpdate(this._toValue); + } + this.__debouncedOnEnd({finished: true}); return; } diff --git a/Libraries/Animation/Animated/__tests__/Animated-test.js b/Libraries/Animation/Animated/__tests__/Animated-test.js index cad752ff0..d27ff920c 100644 --- a/Libraries/Animation/Animated/__tests__/Animated-test.js +++ b/Libraries/Animation/Animated/__tests__/Animated-test.js @@ -127,6 +127,19 @@ describe('Animated', () => { Animated.spring(anim, {toValue: 0, velocity: 0}).start(callback); expect(callback).toBeCalled(); }); + + it('send toValue when a spring stops', () => { + var anim = new Animated.Value(0); + var listener = jest.genMockFunction(); + anim.addListener(listener); + Animated.spring(anim, {toValue: 15}).start(); + jest.runAllTimers(); + var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value; + expect(lastValue).not.toBe(15); + expect(lastValue).toBeCloseTo(15); + expect(anim.__getValue()).toBe(15); + }); + });