Refactor ReactDelegate to provide DevSupportManager (#43520)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43520

Refactor ReactDelegate to have a private `getDevSupportManager()` that can also be re-used  by `reload()`

This method conditionally provides the correct DevSupportManager in cases of Bridge & Bridgeless

Changelog:
[Internal] internal

Reviewed By: cortinico

Differential Revision: D54967130

fbshipit-source-id: 37d585de33a50b98d01803d3080c5693a8c494b9
This commit is contained in:
Arushi Kesarwani
2024-03-25 10:44:47 +00:00
committed by Nicola Corti
parent 4fe26e3b2f
commit 36d64312c8
@@ -82,6 +82,20 @@ public class ReactDelegate {
mReactNativeHost = reactNativeHost;
}
@Nullable
private DevSupportManager getDevSupportManager() {
if (ReactFeatureFlags.enableBridgelessArchitecture
&& mReactHost != null
&& mReactHost.getDevSupportManager() != null) {
return mReactHost.getDevSupportManager();
} else if (getReactNativeHost().hasInstance()
&& getReactNativeHost().getUseDeveloperSupport()) {
return getReactNativeHost().getReactInstanceManager().getDevSupportManager();
} else {
return null;
}
}
public void onHostResume() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (mActivity instanceof DefaultHardwareBackBtnHandler) {
@@ -261,15 +275,8 @@ public class ReactDelegate {
* application.
*/
public boolean shouldShowDevMenuOrReload(int keyCode, KeyEvent event) {
DevSupportManager devSupportManager = null;
if (ReactFeatureFlags.enableBridgelessArchitecture
&& mReactHost != null
&& mReactHost.getDevSupportManager() != null) {
devSupportManager = mReactHost.getDevSupportManager();
} else if (getReactNativeHost().hasInstance()
&& getReactNativeHost().getUseDeveloperSupport()) {
devSupportManager = getReactNativeHost().getReactInstanceManager().getDevSupportManager();
} else {
DevSupportManager devSupportManager = getDevSupportManager();
if (devSupportManager == null) {
return false;
}