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
This commit is contained in:
Luke De Feo
2022-10-25 07:10:38 -07:00
committed by Facebook GitHub Bot
parent a0d1013b94
commit 62167bb69c

View File

@@ -20,9 +20,12 @@ 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 com.facebook.flipper.plugins.uidebugger.common.*
import com.facebook.flipper.plugins.uidebugger.common.BitmapPool import com.facebook.flipper.plugins.uidebugger.common.BitmapPool
import com.facebook.flipper.plugins.uidebugger.common.EnumMapping import com.facebook.flipper.plugins.uidebugger.common.EnumMapping
import com.facebook.flipper.plugins.uidebugger.model.* import com.facebook.flipper.plugins.uidebugger.model.*
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.util.ResourcesUtil import com.facebook.flipper.plugins.uidebugger.util.ResourcesUtil
import java.lang.reflect.Field import java.lang.reflect.Field
@@ -31,11 +34,24 @@ object ViewDescriptor : ChainedDescriptor<View>() {
override fun onGetName(node: View): String = node.javaClass.simpleName override fun onGetName(node: View): String = node.javaClass.simpleName
override fun onGetBounds(node: View): Bounds { override fun onGetBounds(node: View): Bounds {
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() val localVisible = Rect()
node.getLocalVisibleRect(localVisible) node.getLocalVisibleRect(localVisible)
offsetX = localVisible.left
offsetY = localVisible.top
}
return Bounds( return Bounds(
node.left - localVisible.left + node.translationX.toInt(), node.left + node.translationX.toInt() - offsetX,
node.top - localVisible.top + node.translationY.toInt(), node.top + node.translationY.toInt() - offsetY,
node.width, node.width,
node.height) node.height)
} }
@@ -74,8 +90,9 @@ object ViewDescriptor : ChainedDescriptor<View>() {
props["localVisibleRect"] = props["localVisibleRect"] =
InspectableObject( InspectableObject(
mapOf( mapOf(
"position" to InspectableValue.Coordinate(Coordinate(localVisible.left, node.top)), "position" to
"size" to InspectableValue.Size(Size(node.width, node.height))), InspectableValue.Coordinate(Coordinate(localVisible.left, localVisible.top)),
"size" to InspectableValue.Size(Size(localVisible.width(), localVisible.height()))),
) )
props["rotation"] = props["rotation"] =