From 8858c2112421be5212c024f9e404e66437a41389 Mon Sep 17 00:00:00 2001 From: Genki Kondo Date: Wed, 26 Jan 2022 21:21:28 -0800 Subject: [PATCH] Make sure that AnimatedTracking is started when CompositeAnimation.start is called Summary: In Animated, when a toValue of AnimatedValue (as opposed to a number) is passed in, the [AnimatedValue starts tracking via AnimatedTracking](https://www.internalfb.com/code/fbsource/[b688f3747a706236fce300636978ed1ca5e4081a]/xplat/js/react-native-github/Libraries/Animated/AnimatedImplementation.js?lines=142) but it doesn't actually start animating even if start() is called on the animation. This behavior is inconsistent with a toValue of a number, which executes immediately on start(). This diff adds a call to AnimatedTracking.update within AnimatedValue.track, which starts the tracking animation. Changelog: [General][Fixed] - Fixes execution of animation when a toValue of AnimatedValue is used. Reviewed By: JoshuaGross Differential Revision: D33800373 fbshipit-source-id: 85ee6f51bc2bb2e078b586b076a8d1dfe92c1155 --- Libraries/Animated/__tests__/Animated-test.js | 13 +++++++++++++ Libraries/Animated/nodes/AnimatedValue.js | 2 ++ 2 files changed, 15 insertions(+) diff --git a/Libraries/Animated/__tests__/Animated-test.js b/Libraries/Animated/__tests__/Animated-test.js index 014a6186828546..7a91b85ece58d8 100644 --- a/Libraries/Animated/__tests__/Animated-test.js +++ b/Libraries/Animated/__tests__/Animated-test.js @@ -782,6 +782,19 @@ describe('Animated tests', () => { value1.setValue(1492); expect(value2.__getValue()).toBe(7); }); + + it('should start tracking immediately on animation start', () => { + const value1 = new Animated.Value(42); + const value2 = new Animated.Value(0); + Animated.timing(value2, { + toValue: value1, + duration: 0, + useNativeDriver: false, + }).start(); + expect(value2.__getValue()).toBe(42); + value1.setValue(7); + expect(value2.__getValue()).toBe(7); + }); }); describe('Animated Vectors', () => { diff --git a/Libraries/Animated/nodes/AnimatedValue.js b/Libraries/Animated/nodes/AnimatedValue.js index 7cfc7b940a3f54..c0e8f7341cc4a7 100644 --- a/Libraries/Animated/nodes/AnimatedValue.js +++ b/Libraries/Animated/nodes/AnimatedValue.js @@ -270,6 +270,8 @@ class AnimatedValue extends AnimatedWithChildren { track(tracking: AnimatedTracking): void { this.stopTracking(); this._tracking = tracking; + // Make sure that the tracking animation starts executing + this._tracking && this._tracking.update(); } _updateValue(value: number, flush: boolean): void {