From 81a41ec9762491524c6abc5a14b5361b94e8e16c Mon Sep 17 00:00:00 2001 From: Thomas Nardone Date: Wed, 21 Aug 2024 15:43:34 -0700 Subject: [PATCH] Clean up ReactViewGroup child listeners (#46139) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46139 Potential fix for IndexOutOfBounds crashes in clipping rect logic. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D61615009 fbshipit-source-id: 1208e11286ad2a84c22262462832a66396a1b35b --- .../java/com/facebook/react/views/view/ReactViewGroup.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index a20a95bd15addb..d05fba51a0c167 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -176,6 +176,13 @@ private void initView() { } /* package */ void recycleView() { + // Remove dangling listeners + if (mAllChildren != null && mChildrenLayoutChangeListener != null) { + for (int i = 0; i < mAllChildrenCount; i++) { + mAllChildren[i].removeOnLayoutChangeListener(mChildrenLayoutChangeListener); + } + } + // Set default field values initView(); mOverflowInset.setEmpty();