mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
convert DebuggingOverlay to Kotlin (#43819)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43819 convert Java to Kotlin: `react/views/debuggingoverlay/DebuggingOverlay.java` Changelog: [Internal] internal Reviewed By: makovkastar Differential Revision: D55662115 fbshipit-source-id: 45fd36efdb93a598224af0fb6c9d33ac5e5cad27
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9876adba4a
commit
49c40812ca
@@ -5872,12 +5872,12 @@ public class com/facebook/react/views/common/ViewUtils {
|
||||
public static fun getTestId (Landroid/view/View;)Ljava/lang/String;
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/debuggingoverlay/DebuggingOverlay : android/view/View {
|
||||
public final class com/facebook/react/views/debuggingoverlay/DebuggingOverlay : android/view/View {
|
||||
public fun <init> (Landroid/content/Context;)V
|
||||
public fun clearElementsHighlights ()V
|
||||
public final fun clearElementsHighlights ()V
|
||||
public fun onDraw (Landroid/graphics/Canvas;)V
|
||||
public fun setHighlightedElementsRectangles (Ljava/util/List;)V
|
||||
public fun setTraceUpdates (Ljava/util/List;)V
|
||||
public final fun setHighlightedElementsRectangles (Ljava/util/List;)V
|
||||
public final fun setTraceUpdates (Ljava/util/List;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/debuggingoverlay/DebuggingOverlayManager : com/facebook/react/uimanager/SimpleViewManager {
|
||||
|
||||
-97
@@ -1,97 +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.views.debuggingoverlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.view.View;
|
||||
import androidx.annotation.UiThread;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class DebuggingOverlay extends View {
|
||||
|
||||
private final Paint mTraceUpdatePaint = new Paint();
|
||||
private HashMap<Integer, TraceUpdate> mTraceUpdatesToDisplayMap = new HashMap();
|
||||
private HashMap<Integer, Runnable> mTraceUpdateIdToCleanupRunnableMap = new HashMap();
|
||||
|
||||
private final Paint mHighlightedElementsPaint = new Paint();
|
||||
private List<RectF> mHighlightedElementsRectangles = new ArrayList<>();
|
||||
|
||||
public DebuggingOverlay(Context context) {
|
||||
super(context);
|
||||
|
||||
mTraceUpdatePaint.setStyle(Paint.Style.STROKE);
|
||||
mTraceUpdatePaint.setStrokeWidth(6);
|
||||
|
||||
mHighlightedElementsPaint.setStyle(Paint.Style.FILL);
|
||||
mHighlightedElementsPaint.setColor(0xCCC8E6FF);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setTraceUpdates(List<TraceUpdate> traceUpdates) {
|
||||
for (TraceUpdate traceUpdate : traceUpdates) {
|
||||
int traceUpdateId = traceUpdate.getId();
|
||||
if (mTraceUpdateIdToCleanupRunnableMap.containsKey(traceUpdateId)) {
|
||||
UiThreadUtil.removeOnUiThread(mTraceUpdateIdToCleanupRunnableMap.get(traceUpdateId));
|
||||
mTraceUpdateIdToCleanupRunnableMap.remove(traceUpdateId);
|
||||
}
|
||||
|
||||
mTraceUpdatesToDisplayMap.put(traceUpdateId, traceUpdate);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void setHighlightedElementsRectangles(List<RectF> elementsRectangles) {
|
||||
mHighlightedElementsRectangles = elementsRectangles;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void clearElementsHighlights() {
|
||||
mHighlightedElementsRectangles.clear();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
// Draw border outside of the given overlays to be aligned with web trace highlights
|
||||
for (TraceUpdate traceUpdate : mTraceUpdatesToDisplayMap.values()) {
|
||||
mTraceUpdatePaint.setColor(traceUpdate.getColor());
|
||||
canvas.drawRect(traceUpdate.getRectangle(), mTraceUpdatePaint);
|
||||
|
||||
int traceUpdateId = traceUpdate.getId();
|
||||
Runnable block =
|
||||
() -> {
|
||||
mTraceUpdatesToDisplayMap.remove(traceUpdateId);
|
||||
mTraceUpdateIdToCleanupRunnableMap.remove(traceUpdateId);
|
||||
|
||||
invalidate();
|
||||
};
|
||||
|
||||
if (!mTraceUpdateIdToCleanupRunnableMap.containsKey(traceUpdateId)) {
|
||||
mTraceUpdateIdToCleanupRunnableMap.put(traceUpdateId, block);
|
||||
UiThreadUtil.runOnUiThread(block, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
for (RectF elementRectangle : mHighlightedElementsRectangles) {
|
||||
canvas.drawRect(elementRectangle, mHighlightedElementsPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.views.debuggingoverlay
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.view.View
|
||||
import androidx.annotation.UiThread
|
||||
import com.facebook.react.bridge.UiThreadUtil
|
||||
|
||||
public class DebuggingOverlay(context: Context) : View(context) {
|
||||
private val traceUpdatePaint = Paint()
|
||||
private val traceUpdatesToDisplayMap = hashMapOf<Int, TraceUpdate>()
|
||||
private val traceUpdateIdToCleanupRunnableMap = hashMapOf<Int, Runnable>()
|
||||
|
||||
private val highlightedElementsPaint = Paint()
|
||||
private var highlightedElementsRectangles = mutableListOf<RectF>()
|
||||
|
||||
init {
|
||||
traceUpdatePaint.style = Paint.Style.STROKE
|
||||
traceUpdatePaint.strokeWidth = 6f
|
||||
highlightedElementsPaint.style = Paint.Style.FILL
|
||||
highlightedElementsPaint.color = 0xCCC8E6FF.toInt()
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public fun setTraceUpdates(traceUpdates: List<TraceUpdate>) {
|
||||
for (traceUpdate in traceUpdates) {
|
||||
val traceUpdateId = traceUpdate.id
|
||||
if (traceUpdateIdToCleanupRunnableMap.containsKey(traceUpdateId)) {
|
||||
UiThreadUtil.removeOnUiThread(traceUpdateIdToCleanupRunnableMap[traceUpdateId])
|
||||
traceUpdateIdToCleanupRunnableMap.remove(traceUpdateId)
|
||||
}
|
||||
|
||||
traceUpdatesToDisplayMap[traceUpdateId] = traceUpdate
|
||||
}
|
||||
|
||||
invalidate()
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public fun setHighlightedElementsRectangles(elementsRectangles: MutableList<RectF>) {
|
||||
highlightedElementsRectangles = elementsRectangles
|
||||
invalidate()
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public fun clearElementsHighlights() {
|
||||
highlightedElementsRectangles.clear()
|
||||
invalidate()
|
||||
}
|
||||
|
||||
public override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
|
||||
// Draw border outside of the given overlays to be aligned with web trace highlights
|
||||
for (traceUpdate in traceUpdatesToDisplayMap.values) {
|
||||
traceUpdatePaint.color = traceUpdate.color
|
||||
canvas.drawRect(traceUpdate.rectangle, traceUpdatePaint)
|
||||
|
||||
val traceUpdateId = traceUpdate.id
|
||||
val block = Runnable {
|
||||
traceUpdatesToDisplayMap.remove(traceUpdateId)
|
||||
traceUpdateIdToCleanupRunnableMap.remove(traceUpdateId)
|
||||
|
||||
invalidate()
|
||||
}
|
||||
|
||||
if (!traceUpdateIdToCleanupRunnableMap.containsKey(traceUpdateId)) {
|
||||
traceUpdateIdToCleanupRunnableMap[traceUpdateId] = block
|
||||
UiThreadUtil.runOnUiThread(block, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
for (elementRectangle in highlightedElementsRectangles) {
|
||||
canvas.drawRect(elementRectangle, highlightedElementsPaint)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user