diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PausedInDebuggerOverlayDialogManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PausedInDebuggerOverlayDialogManager.java deleted file mode 100644 index 4fe80f05bf3..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PausedInDebuggerOverlayDialogManager.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.Dialog; -import android.content.Context; -import android.graphics.drawable.ColorDrawable; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.widget.TextView; -import androidx.annotation.Nullable; -import androidx.core.util.Supplier; -import com.facebook.infer.annotation.Assertions; -import com.facebook.react.R; -import com.facebook.react.bridge.UiThreadUtil; -import com.facebook.react.devsupport.interfaces.DevSupportManager; -import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager; - -/* internal */ class PausedInDebuggerOverlayDialogManager - implements PausedInDebuggerOverlayManager { - - private final Supplier mContextSupplier; - private @Nullable Dialog mPausedInDebuggerDialog; - - public PausedInDebuggerOverlayDialogManager(Supplier contextSupplier) { - mContextSupplier = contextSupplier; - } - - @Override - public void showPausedInDebuggerOverlay( - String message, DevSupportManager.PausedInDebuggerOverlayCommandListener listener) { - UiThreadUtil.runOnUiThread( - () -> { - if (mPausedInDebuggerDialog != null) { - mPausedInDebuggerDialog.dismiss(); - } - @Nullable Context context = mContextSupplier.get(); - if (context == null) { - return; - } - - View dialogView = - LayoutInflater.from(context).inflate(R.layout.paused_in_debugger_view, null); - View resumeButton = Assertions.assertNotNull(dialogView.findViewById(R.id.button)); - resumeButton.setOnClickListener((v) -> listener.onResume()); - TextView buttonText = Assertions.assertNotNull(dialogView.findViewById(R.id.button_text)); - buttonText.setText(message); - - mPausedInDebuggerDialog = new Dialog(context, R.style.NoAnimationDialog); - mPausedInDebuggerDialog.setContentView(dialogView); - mPausedInDebuggerDialog.setCancelable(false); - - Window dialogWindow = mPausedInDebuggerDialog.getWindow(); - if (dialogWindow != null) { - WindowManager.LayoutParams layoutParams = dialogWindow.getAttributes(); - layoutParams.dimAmount = 0.2f; - - dialogWindow.setAttributes(layoutParams); - dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); - dialogWindow.setGravity(Gravity.TOP); - dialogWindow.setElevation(0); - dialogWindow.setBackgroundDrawable( - new ColorDrawable(android.graphics.Color.TRANSPARENT)); - dialogWindow.setBackgroundDrawableResource(R.drawable.paused_in_debugger_background); - } - - mPausedInDebuggerDialog.show(); - }); - } - - @Override - public void hidePausedInDebuggerOverlay() { - UiThreadUtil.runOnUiThread( - () -> { - if (mPausedInDebuggerDialog != null) { - mPausedInDebuggerDialog.dismiss(); - mPausedInDebuggerDialog = null; - } - }); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PausedInDebuggerOverlayDialogManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PausedInDebuggerOverlayDialogManager.kt new file mode 100644 index 00000000000..5228a0d08cd --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PausedInDebuggerOverlayDialogManager.kt @@ -0,0 +1,70 @@ +/* + * 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.Dialog +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.view.Gravity +import android.view.LayoutInflater +import android.view.View +import android.view.WindowManager +import android.widget.TextView +import androidx.core.util.Supplier +import com.facebook.react.R +import com.facebook.react.bridge.UiThreadUtil +import com.facebook.react.devsupport.interfaces.DevSupportManager +import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager + +internal class PausedInDebuggerOverlayDialogManager( + private val contextSupplier: Supplier +) : PausedInDebuggerOverlayManager { + private var pausedInDebuggerDialog: Dialog? = null + + override fun showPausedInDebuggerOverlay( + message: String, + listener: DevSupportManager.PausedInDebuggerOverlayCommandListener + ) { + UiThreadUtil.runOnUiThread { + pausedInDebuggerDialog?.dismiss() + val context = contextSupplier.get() ?: return@runOnUiThread + + val dialogView: View = + LayoutInflater.from(context).inflate(R.layout.paused_in_debugger_view, null) + dialogView.findViewById(R.id.button).setOnClickListener { listener.onResume() } + dialogView.findViewById(R.id.button_text).text = message + + pausedInDebuggerDialog = + Dialog(context, R.style.NoAnimationDialog).apply { + setContentView(dialogView) + setCancelable(false) + } + + pausedInDebuggerDialog?.window?.let { dialogWindow -> + val layoutParams: WindowManager.LayoutParams = dialogWindow.attributes + layoutParams.dimAmount = 0.2f + + dialogWindow.attributes = layoutParams + dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialogWindow.setGravity(Gravity.TOP) + dialogWindow.setElevation(0f) + dialogWindow.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + dialogWindow.setBackgroundDrawableResource(R.drawable.paused_in_debugger_background) + } + pausedInDebuggerDialog?.show() + } + } + + override fun hidePausedInDebuggerOverlay() { + UiThreadUtil.runOnUiThread { + pausedInDebuggerDialog?.dismiss() + pausedInDebuggerDialog = null + } + } +}