From 51a63f4a5efe3f4386deda40a8a6eec209ff3c99 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Tue, 25 Jul 2023 09:00:04 -0700 Subject: [PATCH] Hide JS executor in Dev Menu when unimplemented Summary: Fixes exception thrown when `getJavaScriptExecutorFactory()` is not implemented on bridgeless. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D47755422 fbshipit-source-id: 80170db521ab02c4f23c9ddf3c2f5b0381df020b --- .../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; + } } /**