Skip to content

Commit

Permalink
Migrate react/devsupport/LogBox*.java to Kotlin (facebook#43730)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#43730

# Changelog:
[Internal] -

As in the title, converts corresponding type declarations in `react/devsupport/LogBox*.java` to Kotlin.

Differential Revision: https://internalfb.com/D55574528
  • Loading branch information
rshest authored and facebook-github-bot committed Mar 31, 2024
1 parent 2bdbe2e commit edf7500
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 210 deletions.
6 changes: 5 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2212,14 +2212,18 @@ public abstract interface class com/facebook/react/devsupport/JSDebuggerWebSocke
public abstract fun onSuccess (Ljava/lang/String;)V
}

public class com/facebook/react/devsupport/LogBoxModule : com/facebook/fbreact/specs/NativeLogBoxSpec {
public final class com/facebook/react/devsupport/LogBoxModule : com/facebook/fbreact/specs/NativeLogBoxSpec {
public static final field Companion Lcom/facebook/react/devsupport/LogBoxModule$Companion;
public static final field NAME Ljava/lang/String;
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Lcom/facebook/react/devsupport/interfaces/DevSupportManager;)V
public fun hide ()V
public fun invalidate ()V
public fun show ()V
}

public final class com/facebook/react/devsupport/LogBoxModule$Companion {
}

public class com/facebook/react/devsupport/PackagerStatusCheck {
public fun <init> ()V
public fun <init> (Lokhttp3/OkHttpClient;)V
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.devsupport

import android.app.Activity
import android.app.Dialog
import android.view.View
import android.view.Window
import com.facebook.react.R

/** Dialog for displaying JS errors in LogBox. */
internal class LogBoxDialog(context: Activity, reactRootView: View?) :
Dialog(context, R.style.Theme_Catalyst_LogBox) {
init {
requestWindowFeature(Window.FEATURE_NO_TITLE)
if (reactRootView != null) {
setContentView(reactRootView)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.devsupport

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import com.facebook.infer.annotation.Assertions
import com.facebook.react.common.SurfaceDelegate
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.util.RNLog.e

/**
* The implementation of SurfaceDelegate with [Activity]. This is the default SurfaceDelegate for
* Mobile.
*/
internal class LogBoxDialogSurfaceDelegate(private val devSupportManager: DevSupportManager) :
SurfaceDelegate {
private var reactRootView: View? = null
private var dialog: LogBoxDialog? = null

override fun createContentView(appKey: String) {
Assertions.assertCondition(
appKey == "LogBox", "This surface manager can only create LogBox React application")
reactRootView = devSupportManager.createRootView("LogBox")
if (reactRootView == null) {
e("Unable to launch logbox because react was unable to create the root view")
}
}

override fun isContentViewReady(): Boolean = reactRootView != null

override fun destroyContentView() {
if (reactRootView != null) {
devSupportManager.destroyRootView(reactRootView)
reactRootView = null
}
}

override fun show() {
if (isShowing || !isContentViewReady) {
return
}
val context = devSupportManager.currentActivity
if (context == null || context.isFinishing) {
e(
"Unable to launch logbox because react activity " +
"is not available, here is the error that logbox would've displayed: ")
return
}
dialog = LogBoxDialog(context, reactRootView)
dialog.setCancelable(false)
dialog.show()
}

override fun hide() {
if (!isShowing) {
return
}
(reactRootView?.parent as ViewGroup)?.removeView(reactRootView)
dialog?.dismiss()
dialog = null
}

override fun isShowing(): Boolean = dialog?.isShowing ?: false
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.devsupport

import com.facebook.fbreact.specs.NativeLogBoxSpec
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.common.SurfaceDelegate
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.module.annotations.ReactModule

@ReactModule(name = NativeLogBoxSpec.NAME)
public class LogBoxModule(
reactContext: ReactApplicationContext?,
private val devSupportManager: DevSupportManager
) : NativeLogBoxSpec(reactContext) {
private val surfaceDelegate: SurfaceDelegate =
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 { surfaceDelegate.show() }
}

override fun hide() {
UiThreadUtil.runOnUiThread { surfaceDelegate.hide() }
}

override fun invalidate() {
UiThreadUtil.runOnUiThread { surfaceDelegate.destroyContentView() }
}

public companion object {
public const val NAME: String = "LogBox"
}
}

0 comments on commit edf7500

Please sign in to comment.