diff --git a/Libraries/Animated/nodes/AnimatedNode.js b/Libraries/Animated/nodes/AnimatedNode.js index 388052a004c..890e9e865bc 100644 --- a/Libraries/Animated/nodes/AnimatedNode.js +++ b/Libraries/Animated/nodes/AnimatedNode.js @@ -12,6 +12,7 @@ import type {PlatformConfig} from '../AnimatedPlatformConfig'; +import ReactNativeFeatureFlags from '../../ReactNative/ReactNativeFeatureFlags'; import NativeAnimatedHelper from '../NativeAnimatedHelper'; import invariant from 'invariant'; @@ -29,6 +30,9 @@ export default class AnimatedNode { __nativeAnimatedValueListener: ?any; __attach(): void {} __detach(): void { + if (ReactNativeFeatureFlags.removeListenersOnDetach()) { + this.removeAllListeners(); + } if (this.__isNative && this.__nativeTag != null) { NativeAnimatedHelper.API.dropAnimatedNode(this.__nativeTag); this.__nativeTag = undefined; diff --git a/Libraries/ReactNative/ReactNativeFeatureFlags.js b/Libraries/ReactNative/ReactNativeFeatureFlags.js index 629137ce35b..1e5845c77dc 100644 --- a/Libraries/ReactNative/ReactNativeFeatureFlags.js +++ b/Libraries/ReactNative/ReactNativeFeatureFlags.js @@ -43,6 +43,8 @@ export type FeatureFlags = {| * to render react components driven by classes written in C++. */ enableCppRenderSystem: () => boolean, + + removeListenersOnDetach: () => boolean, |}; const ReactNativeFeatureFlags: FeatureFlags = { @@ -52,6 +54,7 @@ const ReactNativeFeatureFlags: FeatureFlags = { animatedShouldDebounceQueueFlush: () => false, animatedShouldUseSingleOp: () => false, enableCppRenderSystem: () => false, + removeListenersOnDetach: () => false, }; module.exports = ReactNativeFeatureFlags;