From 8ab87c617eb782da44c8c6fad265d124905fbafe Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 26 Nov 2024 04:00:14 -0800 Subject: [PATCH] Fix stale reference to ReactViewGroup#mAllChildren (#47950) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47950 `addInArray` may reallocate `mAllChildren` so it's not correct to store this reference. Changelog: [Internal] Reviewed By: tdn120 Differential Revision: D66474532 fbshipit-source-id: 90ce2fcbf8ff236501ed47b2acc413e54ef8b82a --- .../java/com/facebook/react/views/view/ReactViewGroup.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 f38c4603708..fa956c481d7 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 @@ -622,11 +622,12 @@ public class ReactViewGroup extends ViewGroup /*package*/ void addViewWithSubviewClippingEnabled( final View child, int index, ViewGroup.LayoutParams params) { Assertions.assertCondition(mRemoveClippedSubviews); - Rect clippingRect = Assertions.assertNotNull(mClippingRect); - View[] childArray = Assertions.assertNotNull(mAllChildren); addInArray(child, index); + // we add view as "clipped" and then run {@link #updateSubviewClipStatus} to conditionally // attach it + Rect clippingRect = Assertions.assertNotNull(mClippingRect); + View[] childArray = Assertions.assertNotNull(mAllChildren); int clippedSoFar = 0; for (int i = 0; i < index; i++) { if (isViewClipped(childArray[i])) {