From 9cbf35dea8b3dd805dcc543e73770714d93456db Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Mon, 10 Oct 2022 04:13:06 -0700 Subject: [PATCH] Consider local visible rect and translation when calcauating view bounds Summary: In general we want a child to know its position without having be overriden by it parent via offset child. Therefore we need to consider translation and the result of getLocalVisibleRect. Despite its name it seems to be an offset from its normal bounds after scrolling in certain types of scroll views. Reviewed By: lblasa Differential Revision: D40021836 fbshipit-source-id: 4ae9a4b202d7ba201cdb8b6bc8f13e94baf2b37e --- .../uidebugger/descriptors/ViewDescriptor.kt | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/ViewDescriptor.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/ViewDescriptor.kt index 1250f87de..0a6e8294e 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/ViewDescriptor.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/ViewDescriptor.kt @@ -10,6 +10,7 @@ package com.facebook.flipper.plugins.uidebugger.descriptors import android.annotation.SuppressLint import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.Rect import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.os.Build @@ -28,8 +29,15 @@ object ViewDescriptor : ChainedDescriptor() { override fun onGetName(node: View): String = node.javaClass.simpleName - override fun onGetBounds(node: View): Bounds = - Bounds(node.left, node.top, node.width, node.height) + override fun onGetBounds(node: View): Bounds { + val localVisible = Rect() + node.getLocalVisibleRect(localVisible) + return Bounds( + node.left - localVisible.left + node.translationX.toInt(), + node.top - localVisible.top + node.translationY.toInt(), + node.width, + node.height) + } override fun onGetTags(node: View): Set = BaseTags.NativeAndroid @@ -37,8 +45,6 @@ object ViewDescriptor : ChainedDescriptor() { node: View, attributeSections: MutableMap ) { - val positionOnScreen = IntArray(2) - node.getLocationOnScreen(positionOnScreen) val props = mutableMapOf() props["height"] = InspectableValue.Number(node.height, mutable = true) @@ -92,12 +98,27 @@ object ViewDescriptor : ChainedDescriptor() { "x" to InspectableValue.Number(node.pivotX, mutable = true), "y" to InspectableValue.Number(node.pivotY, mutable = true))) + val positionOnScreen = IntArray(2) + node.getLocationOnScreen(positionOnScreen) + props["globalPosition"] = InspectableObject( mapOf( "x" to InspectableValue.Number(positionOnScreen[0], mutable = false), "y" to InspectableValue.Number(positionOnScreen[1], mutable = false))) + val localVisible = Rect() + node.getLocalVisibleRect(localVisible) + + props["localVisible"] = + InspectableObject( + mapOf( + "x" to InspectableValue.Number(localVisible.left, mutable = true), + "y" to InspectableValue.Number(node.top, mutable = true), + "width" to InspectableValue.Number(node.width, mutable = true), + "height" to InspectableValue.Number(node.height, mutable = true)), + ) + attributeSections["View"] = InspectableObject(props.toMap()) }