From c238740af1f3f670b6a209a691f0299871bb3ed6 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Wed, 7 Dec 2022 04:31:56 -0800 Subject: [PATCH] Add support for non support libarry scroll views Summary: we had special handling previously for nested scrollview and we previously used the indirect approach of asking for the local visible rect. New approach is to get the scroll x from the parent and apply it, will work for all scrolling view and it is a lot clearer what the intention is. Reviewed By: lblasa Differential Revision: D41772106 fbshipit-source-id: 04b5e68ecabd70548e788ed18423a360ce6c3fa7 --- .../uidebugger/descriptors/ViewDescriptor.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 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 4d9fb81c6..50a2823bc 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,7 +20,6 @@ import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import android.widget.LinearLayout -import androidx.core.widget.NestedScrollView import androidx.viewpager.widget.ViewPager import com.facebook.flipper.plugins.uidebugger.common.* import com.facebook.flipper.plugins.uidebugger.model.* @@ -156,6 +155,8 @@ object ViewDescriptor : ChainedDescriptor() { MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "scale") private val PivotAttributeId = MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "pivot") + private val ScrollAttributeId = + MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "scroll") private val LayoutParamsAttributeId = MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "layoutParams") private val LayoutDirectionAttributeId = @@ -247,28 +248,25 @@ object ViewDescriptor : ChainedDescriptor() { override fun onGetBounds(node: View): Bounds { - if (node.parent is ViewPager) { + val parent = node.parent + if (parent is ViewPager) { // override return Bounds(0, 0, node.width, node.height) } - 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 actual position. - */ - val localVisible = Rect() - node.getLocalVisibleRect(localVisible) - offsetX = localVisible.left - offsetY = localVisible.top + var xScrollOffset = 0 + var yScrollOffset = 0 + + if (parent is View) { + // NestedScrollView, HorizontalScrollView and ScrollView all set scroll x and y + // we need to account for this in the childs bounds + xScrollOffset = parent.scrollX + yScrollOffset = parent.scrollY } return Bounds( - node.left + node.translationX.toInt() - offsetX, - node.top + node.translationY.toInt() - offsetY, + node.left + node.translationX.toInt() - xScrollOffset, + node.top + node.translationY.toInt() - yScrollOffset, node.width, node.height) } @@ -317,6 +315,8 @@ object ViewDescriptor : ChainedDescriptor() { props[ScaleAttributeId] = InspectableValue.Coordinate(Coordinate(node.scaleX, node.scaleY)) props[PivotAttributeId] = InspectableValue.Coordinate(Coordinate(node.pivotX, node.pivotY)) + props[ScrollAttributeId] = InspectableValue.Coordinate(Coordinate(node.scrollX, node.scrollY)) + props[LayoutParamsAttributeId] = getLayoutParams(node) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { props[LayoutDirectionAttributeId] = LayoutDirectionMapping.toInspectable(node.layoutDirection)