From a25004c86c9fe5b74a54ba913c2ce94f9b1b9b31 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 9 Apr 2024 10:10:04 -0700 Subject: [PATCH] Fix bridge mode by constructing ReactDelegate correctly. (#43999) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43999 Currently NewArch-BridgeMode is partially broken when creating views via `ReactDelegate`. That's because we're using the ctor that doesn't account for `Boolean: fabricEnabled`. That means that the `RootView` that it will be created are all having setIsFabric(FALSE). This is causing problems like whitescreens on several reload + multiple warnings such as: ``` E com.facebook.react.bridge.ReactNoCrashSoftException: Cannot get UIManager because the context doesn't contain an active CatalystInstance. ``` Fixes #43692 See for more context on this issues: https://github.com/facebook/react-native/issues/43692 Changelog: [Android] [Fixed] - Fix bridge mode by constructing ReactDelegate correctly Reviewed By: cipolleschi Differential Revision: D55921078 fbshipit-source-id: 2c21d089a49538402d546177bcdb26c8d7d5fbc1 --- .../java/com/facebook/react/ReactActivityDelegate.java | 6 +++++- .../src/main/java/com/facebook/react/ReactDelegate.java | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 82f91e7e034036..fcc796e4e981e2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -108,7 +108,11 @@ public void onCreate(Bundle savedInstanceState) { } else { mReactDelegate = new ReactDelegate( - getPlainActivity(), getReactNativeHost(), mainComponentName, launchOptions) { + getPlainActivity(), + getReactNativeHost(), + mainComponentName, + launchOptions, + isFabricEnabled()) { @Override protected ReactRootView createRootView() { ReactRootView rootView = ReactActivityDelegate.this.createRootView(); 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 1047542202632a..4cbc4107b05d48 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 @@ -44,6 +44,15 @@ public class ReactDelegate { private boolean mFabricEnabled = false; + /** + * Do not use this constructor as it's not accounting for New Architecture at all. You should + * either use {@link ReactDelegate#ReactDelegate(Activity, ReactHost, String, Bundle)} if you're + * on bridgeless mode or {@link ReactDelegate#ReactDelegate(Activity, ReactNativeHost, String, + * Bundle, boolean)} and use the last parameter to toggle paper/fabric. + * + * @deprecated Use one of the other constructors instead to account for New Architecture. + */ + @Deprecated public ReactDelegate( Activity activity, ReactNativeHost reactNativeHost,