diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index cd2b25044bd..d1e4b4eb10e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -111,6 +111,12 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie // Set default field values initView(); + // If the view is still attached to a parent, we need to remove it from the parent + // before we can recycle it. + if (getParent() != null) { + ((ViewGroup) getParent()).removeView(this); + } + BackgroundStyleApplicator.reset(this); // Defaults for these fields: 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 da20629d4fa..65349b852e2 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 @@ -193,6 +193,12 @@ public class ReactViewGroup extends ViewGroup // Remove any children removeAllViews(); + // If the view is still attached to a parent, we need to remove it from the parent + // before we can recycle it. + if (getParent() != null) { + ((ViewGroup) getParent()).removeView(this); + } + // Reset background, borders updateBackgroundDrawable(null);