Skip to content

Commit 8858c21

Browse files
genkikondofacebook-github-bot
authored andcommitted
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
1 parent 45244eb commit 8858c21

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Libraries/Animated/__tests__/Animated-test.js

+13
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,19 @@ describe('Animated tests', () => {
782782
value1.setValue(1492);
783783
expect(value2.__getValue()).toBe(7);
784784
});
785+
786+
it('should start tracking immediately on animation start', () => {
787+
const value1 = new Animated.Value(42);
788+
const value2 = new Animated.Value(0);
789+
Animated.timing(value2, {
790+
toValue: value1,
791+
duration: 0,
792+
useNativeDriver: false,
793+
}).start();
794+
expect(value2.__getValue()).toBe(42);
795+
value1.setValue(7);
796+
expect(value2.__getValue()).toBe(7);
797+
});
785798
});
786799

787800
describe('Animated Vectors', () => {

Libraries/Animated/nodes/AnimatedValue.js

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ class AnimatedValue extends AnimatedWithChildren {
270270
track(tracking: AnimatedTracking): void {
271271
this.stopTracking();
272272
this._tracking = tracking;
273+
// Make sure that the tracking animation starts executing
274+
this._tracking && this._tracking.update();
273275
}
274276

275277
_updateValue(value: number, flush: boolean): void {

0 commit comments

Comments
 (0)