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
This commit is contained in:
Luke De Feo
2022-12-07 04:31:56 -08:00
committed by Facebook GitHub Bot
parent e195c7c3fd
commit c238740af1

View File

@@ -20,7 +20,6 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.widget.NestedScrollView
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.facebook.flipper.plugins.uidebugger.common.* import com.facebook.flipper.plugins.uidebugger.common.*
import com.facebook.flipper.plugins.uidebugger.model.* import com.facebook.flipper.plugins.uidebugger.model.*
@@ -156,6 +155,8 @@ object ViewDescriptor : ChainedDescriptor<View>() {
MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "scale") MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "scale")
private val PivotAttributeId = private val PivotAttributeId =
MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "pivot") MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "pivot")
private val ScrollAttributeId =
MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "scroll")
private val LayoutParamsAttributeId = private val LayoutParamsAttributeId =
MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "layoutParams") MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "layoutParams")
private val LayoutDirectionAttributeId = private val LayoutDirectionAttributeId =
@@ -247,28 +248,25 @@ object ViewDescriptor : ChainedDescriptor<View>() {
override fun onGetBounds(node: View): Bounds { override fun onGetBounds(node: View): Bounds {
if (node.parent is ViewPager) { val parent = node.parent
if (parent is ViewPager) {
// override // override
return Bounds(0, 0, node.width, node.height) return Bounds(0, 0, node.width, node.height)
} }
var offsetX = 0 var xScrollOffset = 0
var offsetY = 0 var yScrollOffset = 0
if (node.parent is NestedScrollView) {
/** if (parent is View) {
* when a node is a child of nested scroll view android does not adjust the left/ top as the // NestedScrollView, HorizontalScrollView and ScrollView all set scroll x and y
* view scrolls. This seems to be unique to nested scroll view so we have this trick to find // we need to account for this in the childs bounds
* its actual position. xScrollOffset = parent.scrollX
*/ yScrollOffset = parent.scrollY
val localVisible = Rect()
node.getLocalVisibleRect(localVisible)
offsetX = localVisible.left
offsetY = localVisible.top
} }
return Bounds( return Bounds(
node.left + node.translationX.toInt() - offsetX, node.left + node.translationX.toInt() - xScrollOffset,
node.top + node.translationY.toInt() - offsetY, node.top + node.translationY.toInt() - yScrollOffset,
node.width, node.width,
node.height) node.height)
} }
@@ -317,6 +315,8 @@ object ViewDescriptor : ChainedDescriptor<View>() {
props[ScaleAttributeId] = InspectableValue.Coordinate(Coordinate(node.scaleX, node.scaleY)) props[ScaleAttributeId] = InspectableValue.Coordinate(Coordinate(node.scaleX, node.scaleY))
props[PivotAttributeId] = InspectableValue.Coordinate(Coordinate(node.pivotX, node.pivotY)) props[PivotAttributeId] = InspectableValue.Coordinate(Coordinate(node.pivotX, node.pivotY))
props[ScrollAttributeId] = InspectableValue.Coordinate(Coordinate(node.scrollX, node.scrollY))
props[LayoutParamsAttributeId] = getLayoutParams(node) props[LayoutParamsAttributeId] = getLayoutParams(node)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
props[LayoutDirectionAttributeId] = LayoutDirectionMapping.toInspectable(node.layoutDirection) props[LayoutDirectionAttributeId] = LayoutDirectionMapping.toInspectable(node.layoutDirection)