From 0446a16925c540a18e9e5f16abcdd6c900aa372d Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Tue, 25 Jul 2023 08:44:05 -0700 Subject: [PATCH] Hide JS executor in Dev Menu when unimplemented (#38622) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38622 Fixes exception thrown when `getJavaScriptExecutorFactory()` is not implemented on bridgeless. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D47755422 fbshipit-source-id: 260b204703a4d16714d8d45071000a1c45d94fde --- .../devsupport/DevSupportManagerBase.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java index d1f2b994f3d8b0..cbf8de9325376d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java @@ -510,16 +510,19 @@ public void onOptionSelected() { title.setGravity(Gravity.CENTER); title.setTextSize(16); title.setTypeface(title.getTypeface(), Typeface.BOLD); + header.addView(title); - final TextView jsExecutorLabel = new TextView(context); - jsExecutorLabel.setText( - context.getString(R.string.catalyst_dev_menu_sub_header, getJSExecutorDescription())); - jsExecutorLabel.setPadding(0, 20, 0, 0); - jsExecutorLabel.setGravity(Gravity.CENTER); - jsExecutorLabel.setTextSize(14); + String jsExecutorDescription = getJSExecutorDescription(); - header.addView(title); - header.addView(jsExecutorLabel); + if (jsExecutorDescription != null) { + final TextView jsExecutorLabel = new TextView(context); + jsExecutorLabel.setText( + context.getString(R.string.catalyst_dev_menu_sub_header, jsExecutorDescription)); + jsExecutorLabel.setPadding(0, 20, 0, 0); + jsExecutorLabel.setGravity(Gravity.CENTER); + jsExecutorLabel.setTextSize(14); + header.addView(jsExecutorLabel); + } mDevOptionsDialog = new AlertDialog.Builder(context) @@ -539,7 +542,11 @@ public void onOptionSelected() { } private String getJSExecutorDescription() { - return getReactInstanceDevHelper().getJavaScriptExecutorFactory().toString(); + try { + return getReactInstanceDevHelper().getJavaScriptExecutorFactory().toString(); + } catch (IllegalStateException e) { + return null; + } } /**