Skip to content

Commit b3f7d53

Browse files
michalchudziakfacebook-github-bot
authored andcommitted
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
1 parent c5c79e5 commit b3f7d53

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Libraries/Animated/src/nodes/AnimatedNode.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AnimatedNode {
4343
/* Methods and props used by native Animated impl */
4444
__isNative: boolean;
4545
__nativeTag: ?number;
46+
__shouldUpdateListenersForNewNativeTag: boolean;
4647

4748
constructor() {
4849
this._listeners = {};
@@ -104,10 +105,18 @@ class AnimatedNode {
104105
}
105106

106107
_startListeningToNativeValueUpdates() {
107-
if (this.__nativeAnimatedValueListener) {
108+
if (
109+
this.__nativeAnimatedValueListener &&
110+
!this.__shouldUpdateListenersForNewNativeTag
111+
) {
108112
return;
109113
}
110114

115+
if (this.__shouldUpdateListenersForNewNativeTag) {
116+
this.__shouldUpdateListenersForNewNativeTag = false;
117+
this._stopListeningForNativeValueUpdates();
118+
}
119+
111120
NativeAnimatedAPI.startListeningToAnimatedNodeValue(this.__getNativeTag());
112121
this.__nativeAnimatedValueListener = NativeAnimatedHelper.nativeEventEmitter.addListener(
113122
'onAnimatedValueUpdate',
@@ -153,6 +162,7 @@ class AnimatedNode {
153162
this.__getNativeConfig(),
154163
);
155164
this.__nativeTag = nativeTag;
165+
this.__shouldUpdateListenersForNewNativeTag = true;
156166
}
157167
return this.__nativeTag;
158168
}

0 commit comments

Comments
 (0)