From 12dda31bc12f4a04ec9df70d30328b1001bb2cec Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 27 Sep 2024 01:49:38 -0700 Subject: [PATCH] fix: ReactDelegate crashing New Architecture apps by invoking `setContentView` (#46671) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46671 Fixes https://github.com/facebook/react-native/issues/46566 Currently `ReactFragment` and `ReactDelegate` don't work in OSS + New Architecture because we call `Activity.setContentView` on the host activity. That result on us replacing the whole activity layout, even when the user wants to use a Fragment. As we do have `ReactActivityDelegate` that already does this: https://github.com/facebook/react-native/blob/94b77938435693792e57c96d76691d58d7361530/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java#L138 So this call is unncessary. I've also updated the relative documentation here: https://github.com/facebook/react-native-website/pull/4232 Changelog: [Android] [Fixed] - fix: ReactDelegate/ReactFragment crashing on New Architecture apps Reviewed By: rozele Differential Revision: D63464367 fbshipit-source-id: acbfbf7d68eb79657b811a5a9a0d3f72660ec94a --- .../src/main/java/com/facebook/react/ReactDelegate.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java index c7b8ce77297..090b55f59ee 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java @@ -288,10 +288,7 @@ public class ReactDelegate { // With Bridgeless enabled, create and start the surface if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) { if (mReactSurface == null) { - // Create a ReactSurface mReactSurface = mReactHost.createSurface(mActivity, appKey, mLaunchOptions); - // Set main Activity's content view - mActivity.setContentView(mReactSurface.getView()); } mReactSurface.start(); } else {