Skip to content
Permalink
Browse files

Fix Animated.Value value after animation if component was re-mounted (#…

…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 b3f7d53b87413abdf302c521114e4d77aa92e07f
Showing with 11 additions and 1 deletion.
  1. +11 −1 Libraries/Animated/src/nodes/AnimatedNode.js
@@ -43,6 +43,7 @@ class AnimatedNode {
/* Methods and props used by native Animated impl */
__isNative: boolean;
__nativeTag: ?number;
__shouldUpdateListenersForNewNativeTag: boolean;

constructor() {
this._listeners = {};
@@ -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',
@@ -153,6 +162,7 @@ class AnimatedNode {
this.__getNativeConfig(),
);
this.__nativeTag = nativeTag;
this.__shouldUpdateListenersForNewNativeTag = true;
}
return this.__nativeTag;
}

0 comments on commit b3f7d53

Please sign in to comment.
You can’t perform that action at this time.