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
This commit is contained in:
Nicola Corti
2024-09-27 01:49:38 -07:00
committed by Facebook GitHub Bot
parent 7176d11ce4
commit 12dda31bc1
@@ -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 {