From 62167bb69c91382f51c368dbf35d8c910743e714 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Tue, 25 Oct 2022 07:10:38 -0700 Subject: [PATCH] Fix bounds for children of nested scroll view Summary: Android does not set the top/left of the child of view pager. I attempted to solve this by grabbing the offset from the scrollview and passing it down via offset child. The issue is offsetchild has a lot of problems with the partial layout traversal. If the child of the scroll view is an observer root then the layout traversal with short circuit and setup a new observer for the child but we lose the offset child in the process. This solution is a little dirty but it is functional for now Reviewed By: lblasa Differential Revision: D40430778 fbshipit-source-id: 7ad53b2a4818b55515e7662272548e2ce17e6b44 --- .../uidebugger/descriptors/ViewDescriptor.kt | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 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 035b6281b..06f14d6f6 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 @@ -20,9 +20,12 @@ import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import android.widget.LinearLayout +import androidx.core.widget.NestedScrollView +import com.facebook.flipper.plugins.uidebugger.common.* import com.facebook.flipper.plugins.uidebugger.common.BitmapPool import com.facebook.flipper.plugins.uidebugger.common.EnumMapping import com.facebook.flipper.plugins.uidebugger.model.* +import com.facebook.flipper.plugins.uidebugger.model.Bounds import com.facebook.flipper.plugins.uidebugger.util.ResourcesUtil import java.lang.reflect.Field @@ -31,11 +34,24 @@ object ViewDescriptor : ChainedDescriptor() { override fun onGetName(node: View): String = node.javaClass.simpleName override fun onGetBounds(node: View): Bounds { - val localVisible = Rect() - node.getLocalVisibleRect(localVisible) + + var offsetX = 0 + var offsetY = 0 + if (node.parent is NestedScrollView) { + /** + * when a node is a child of nested scroll view android does not adjust the left/ top as the + * view scrolls. This seems to be unique to nested scroll view so we have this trick to find + * its + */ + val localVisible = Rect() + node.getLocalVisibleRect(localVisible) + offsetX = localVisible.left + offsetY = localVisible.top + } + return Bounds( - node.left - localVisible.left + node.translationX.toInt(), - node.top - localVisible.top + node.translationY.toInt(), + node.left + node.translationX.toInt() - offsetX, + node.top + node.translationY.toInt() - offsetY, node.width, node.height) } @@ -74,8 +90,9 @@ object ViewDescriptor : ChainedDescriptor() { props["localVisibleRect"] = InspectableObject( mapOf( - "position" to InspectableValue.Coordinate(Coordinate(localVisible.left, node.top)), - "size" to InspectableValue.Size(Size(node.width, node.height))), + "position" to + InspectableValue.Coordinate(Coordinate(localVisible.left, localVisible.top)), + "size" to InspectableValue.Size(Size(localVisible.width(), localVisible.height()))), ) props["rotation"] =