Skip to content

Commit cd83194

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Remove all listeners of AnimatedNode when detached
Summary: changelog: [internal] Removing listener on detached node leads to a red box, if the said node is `DiffClampAnimatedNode`. This is because calling `AnimatedNode.__getNativeTag()` makes native module call and creates node in native. This node is not completely initialised and red boxes because `[RCTAnimatedNode parentNodes]` is nil when it shouldn't be. The fix is make sure all listeners are removed before node is destroyed. It is logically correct thing to do. The fix is global, for all components using `DiffClampAnimatedNode`. Reviewed By: yungsters Differential Revision: D40381895 fbshipit-source-id: 4f558faf8101b70552f30e6360998e902aacbc83
1 parent b0da349 commit cd83194

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Libraries/Animated/nodes/AnimatedNode.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import type {PlatformConfig} from '../AnimatedPlatformConfig';
1414

15+
import ReactNativeFeatureFlags from '../../ReactNative/ReactNativeFeatureFlags';
1516
import NativeAnimatedHelper from '../NativeAnimatedHelper';
1617
import invariant from 'invariant';
1718

@@ -29,6 +30,9 @@ export default class AnimatedNode {
2930
__nativeAnimatedValueListener: ?any;
3031
__attach(): void {}
3132
__detach(): void {
33+
if (ReactNativeFeatureFlags.removeListenersOnDetach()) {
34+
this.removeAllListeners();
35+
}
3236
if (this.__isNative && this.__nativeTag != null) {
3337
NativeAnimatedHelper.API.dropAnimatedNode(this.__nativeTag);
3438
this.__nativeTag = undefined;

Libraries/ReactNative/ReactNativeFeatureFlags.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export type FeatureFlags = {|
4343
* to render react components driven by classes written in C++.
4444
*/
4545
enableCppRenderSystem: () => boolean,
46+
47+
removeListenersOnDetach: () => boolean,
4648
|};
4749

4850
const ReactNativeFeatureFlags: FeatureFlags = {
@@ -52,6 +54,7 @@ const ReactNativeFeatureFlags: FeatureFlags = {
5254
animatedShouldDebounceQueueFlush: () => false,
5355
animatedShouldUseSingleOp: () => false,
5456
enableCppRenderSystem: () => false,
57+
removeListenersOnDetach: () => false,
5558
};
5659

5760
module.exports = ReactNativeFeatureFlags;

0 commit comments

Comments
 (0)