Skip to content

Commit

Permalink
Fix Animated.Value value after animation if component was re-mounted (#…
Browse files Browse the repository at this point in the history
…24571)

Summary:
Fixes #23712

Currently, It seems like `__nativeAnimatedValueListener` is not listening to the correct `onAnimatedValueUpdate` events if component was re-mounted. In this PR I'm attaching a new listener if the native view tag has changed.

[General] [Fixed] - Fixed Animated.Value value after animation if component was re-mounted
Pull Request resolved: #24571

Differential Revision: D15237431

Pulled By: cpojer

fbshipit-source-id: 1fe4e290ab45dfe6d1d364d8d7384aabf18d6610
  • Loading branch information
michalchudziak authored and facebook-github-bot committed May 7, 2019
1 parent c5c79e5 commit b3f7d53
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Libraries/Animated/src/nodes/AnimatedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AnimatedNode {
/* Methods and props used by native Animated impl */
__isNative: boolean;
__nativeTag: ?number;
__shouldUpdateListenersForNewNativeTag: boolean;

constructor() {
this._listeners = {};
Expand Down Expand Up @@ -104,10 +105,18 @@ class AnimatedNode {
}

_startListeningToNativeValueUpdates() {
if (this.__nativeAnimatedValueListener) {
if (
this.__nativeAnimatedValueListener &&
!this.__shouldUpdateListenersForNewNativeTag
) {
return;
}

if (this.__shouldUpdateListenersForNewNativeTag) {
this.__shouldUpdateListenersForNewNativeTag = false;
this._stopListeningForNativeValueUpdates();
}

NativeAnimatedAPI.startListeningToAnimatedNodeValue(this.__getNativeTag());
this.__nativeAnimatedValueListener = NativeAnimatedHelper.nativeEventEmitter.addListener(
'onAnimatedValueUpdate',
Expand Down Expand Up @@ -153,6 +162,7 @@ class AnimatedNode {
this.__getNativeConfig(),
);
this.__nativeTag = nativeTag;
this.__shouldUpdateListenersForNewNativeTag = true;
}
return this.__nativeTag;
}
Expand Down

0 comments on commit b3f7d53

Please sign in to comment.