Skip to content

Commit

Permalink
Make sure that AnimatedTracking is started when CompositeAnimation.st…
Browse files Browse the repository at this point in the history
…art 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
  • Loading branch information
genkikondo authored and facebook-github-bot committed Jan 27, 2022
1 parent 45244eb commit 8858c21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Libraries/Animated/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Animated/nodes/AnimatedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8858c21

Please sign in to comment.