diff --git a/Libraries/Animated/__tests__/AnimatedNative-test.js b/Libraries/Animated/__tests__/AnimatedNative-test.js index 9ce09a72d6ab6b..eade44048d873b 100644 --- a/Libraries/Animated/__tests__/AnimatedNative-test.js +++ b/Libraries/Animated/__tests__/AnimatedNative-test.js @@ -134,6 +134,28 @@ describe('Native Animated', () => { expect(opacity.__getValue()).toBe(1); }); + it('should deduct offset when saving value on unmount', () => { + NativeAnimatedModule.getValue = jest.fn((tag, saveCallback) => { + // Assume current raw value of value node is 0.5, the NativeAnimated + // getValue API returns the sum of raw value and offset, so return 1. + saveCallback(1); + }); + const opacity = new Animated.Value(0); + opacity.setOffset(0.5); + opacity.__makeNative(); + + const root = TestRenderer.create(); + const tag = opacity.__getNativeTag(); + + root.unmount(); + + expect(NativeAnimatedModule.getValue).toBeCalledWith( + tag, + expect.any(Function), + ); + expect(opacity.__getValue()).toBe(1); + }); + it('should extract offset', () => { const opacity = new Animated.Value(0); opacity.__makeNative(); diff --git a/Libraries/Animated/nodes/AnimatedValue.js b/Libraries/Animated/nodes/AnimatedValue.js index d3361b86cfbfbe..e0f31f2a4fc4c2 100644 --- a/Libraries/Animated/nodes/AnimatedValue.js +++ b/Libraries/Animated/nodes/AnimatedValue.js @@ -100,7 +100,7 @@ class AnimatedValue extends AnimatedWithChildren { __detach() { if (this.__isNative) { NativeAnimatedAPI.getValue(this.__getNativeTag(), value => { - this._value = value; + this._value = value - this._offset; }); } this.stopAnimation();