mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Fix Animated.Value value after animation if component was re-mounted (#24571)
Summary: Fixes https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/24571 Differential Revision: D15237431 Pulled By: cpojer fbshipit-source-id: 1fe4e290ab45dfe6d1d364d8d7384aabf18d6610
This commit is contained in:
committed by
Facebook Github Bot
parent
c5c79e5d71
commit
b3f7d53b87
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user