diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialogSurfaceDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialogSurfaceDelegate.kt index e48d7eca5bfada..8adc330ad3314b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialogSurfaceDelegate.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialogSurfaceDelegate.kt @@ -61,11 +61,10 @@ internal class LogBoxDialogSurfaceDelegate(private val devSupportManager: DevSup } override fun hide() { - if (!isShowing) { - return + if (isShowing) { + dialog?.dismiss() } (reactRootView?.parent as ViewGroup?)?.removeView(reactRootView) - dialog?.dismiss() dialog = null } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.kt index 325a8645bce935..933f6b4f3420aa 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.kt @@ -23,20 +23,18 @@ public class LogBoxModule( devSupportManager.createSurfaceDelegate(NAME) ?: LogBoxDialogSurfaceDelegate(devSupportManager) - /** - * LogBoxModule can be rendered in different surface. By default, it will use LogBoxDialog to wrap - * the content of logs. In other platform (for example VR), a surfaceDelegate can be provided so - * that the content can be wrapped in custom surface. - */ - init { - UiThreadUtil.runOnUiThread { surfaceDelegate.createContentView("LogBox") } - } - override fun show() { - if (!surfaceDelegate.isContentViewReady) { - return + UiThreadUtil.runOnUiThread { + if (!surfaceDelegate.isContentViewReady) { + /** + * LogBoxModule can be rendered in different surface. By default, it will use LogBoxDialog + * to wrap the content of logs. In other platform (for example VR), a surfaceDelegate can be + * provided so that the content can be wrapped in custom surface. + */ + surfaceDelegate.createContentView("LogBox") + } + surfaceDelegate.show() } - UiThreadUtil.runOnUiThread { surfaceDelegate.show() } } override fun hide() {