forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate react/devsupport/LogBox*.java to Kotlin (facebook#43730)
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
1 parent
2bdbe2e
commit edf7500
Showing
7 changed files
with
154 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
...s/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialog.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...ges/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
93 changes: 0 additions & 93 deletions
93
...ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialogSurfaceDelegate.java
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
...e/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxDialogSurfaceDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
90 changes: 0 additions & 90 deletions
90
...s/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...ges/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |