mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Convert com.facebook.react.devsupport.PausedInDebuggerOverlayDialogManager to Kotlin (#49088)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49088 Just another Kotlin migration for the devsupport package. Changelog: [Internal] [Changed] - Reviewed By: huntie Differential Revision: D68954221 fbshipit-source-id: 40dd1227f6cd042b1ea47b1e5b77347a3cdcb136
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7e12060420
commit
e0da0fe710
-89
@@ -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<Context> mContextSupplier;
|
||||
private @Nullable Dialog mPausedInDebuggerDialog;
|
||||
|
||||
public PausedInDebuggerOverlayDialogManager(Supplier<Context> 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+70
@@ -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<Context?>
|
||||
) : 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<View>(R.id.button).setOnClickListener { listener.onResume() }
|
||||
dialogView.findViewById<TextView>(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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user