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 a173a8b71ab..dd1e5ca616d 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 @@ -45,7 +45,7 @@ internal class LogBoxDialogSurfaceDelegate(private val devSupportManager: DevSup } override fun show() { - if (isShowing() || !isContentViewReady()) { + if (isShowing()) { return } val context = devSupportManager.currentActivity @@ -56,6 +56,14 @@ internal class LogBoxDialogSurfaceDelegate(private val devSupportManager: DevSup ) return } + + if (!isContentViewReady()) { + createContentView("LogBox") + } + if (!isContentViewReady()) { + return + } + dialog = LogBoxDialog(context, reactRootView) dialog?.let { dialog -> dialog.setCancelable(false) @@ -69,6 +77,7 @@ internal class LogBoxDialogSurfaceDelegate(private val devSupportManager: DevSup } (reactRootView?.parent as ViewGroup?)?.removeView(reactRootView) dialog = null + destroyContentView() } override fun isShowing(): Boolean = dialog?.isShowing ?: false diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImplDevHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImplDevHelper.kt index 322bbb81376..d293887d6c6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImplDevHelper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImplDevHelper.kt @@ -70,7 +70,14 @@ internal class ReactHostImplDevHelper(private val delegate: ReactHostImpl) : } override fun destroyRootView(rootView: View) { - // Not implemented, only referenced by BridgeDevSupportManager + val surface = (rootView as? ReactSurfaceView)?.surface ?: return + // stop() synchronously removes the surface from ReactHostImpl.attachedSurfaces via + // detachSurface(), then asynchronously tears down the React component tree. + // detach() severs the surface's back-reference to the host. + // clear() removes child views from the ReactSurfaceView. + surface.stop() + surface.detach() + surface.clear() } override fun reload(reason: String) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt index 7b66a0238a6..1ab36cda87d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt @@ -36,7 +36,7 @@ import kotlin.math.max * rendering a React component. */ @OptIn(FrameworkAPI::class, UnstableReactNativeAPI::class) -public class ReactSurfaceView(context: Context?, private val surface: ReactSurfaceImpl) : +public class ReactSurfaceView(context: Context?, internal val surface: ReactSurfaceImpl) : ReactRootView(context) { private val jsTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this) private var jsPointerDispatcher: JSPointerDispatcher? = null