From e92f677ee0f38651482406c5ea1f9d751b47a355 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 19 Sep 2024 07:50:35 -0700 Subject: [PATCH] Fix AnimatedEvent leaking topScrollEnded handler Summary: We automatically add this handler in `addAnimatedEventToView` but we do not remove it in `removeAnimatedEventFromView`, which causes us to leak it. This is especially bad as we attach and detach the event handler multiple times while rendering. Changelog: [Internal] Differential Revision: D63029768 --- .../facebook/react/animated/NativeAnimatedNodesManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java index 45d9e8409ab2..6fd291bbbdfc 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java @@ -556,7 +556,6 @@ public void addAnimatedEventToView( @UiThread public void removeAnimatedEventFromView( int viewTag, String eventHandlerName, int animatedValueTag) { - String eventName = normalizeEventName(eventHandlerName); ListIterator it = mEventDrivers.listIterator(); @@ -569,6 +568,11 @@ public void removeAnimatedEventFromView( break; } } + + if (eventName.equals("topScroll")) { + // Handle the custom topScrollEnded event sent by the ScrollViews when the user stops dragging + removeAnimatedEventFromView(viewTag, "topScrollEnded", animatedValueTag); + } } @Override