Active children and fragments bug

Summary:
Getting the active child was only ever returning the actual active View.

This is correct. However, if the View is backed by a Fragment, then the child is reported as Fragment instead of the actual View.

This was an issue as effectively, the reported children (fragments) were never going to match the active child (view).

Additionally in this change, report back the name of the node even if not active.

Reviewed By: LukeDefeo

Differential Revision: D40632526

fbshipit-source-id: 3560b193b370f19ceabe66980fe23f55ec887274
This commit is contained in:
Lorenzo Blasa
2022-10-25 03:09:00 -07:00
committed by Facebook GitHub Bot
parent bb3b1cecef
commit 38109eccff
6 changed files with 43 additions and 24 deletions

View File

@@ -8,7 +8,6 @@
package com.facebook.flipper.plugins.uidebugger.descriptors
import android.graphics.drawable.ColorDrawable
import android.os.Build
import com.facebook.flipper.plugins.uidebugger.model.Color
import com.facebook.flipper.plugins.uidebugger.model.Inspectable
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
@@ -23,9 +22,7 @@ object ColorDrawableDescriptor : ChainedDescriptor<ColorDrawable>() {
attributeSections: MutableMap<SectionName, InspectableObject>
) {
val props = mutableMapOf<String, Inspectable>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
props["color"] = InspectableValue.Color(Color.fromColor(node.color), mutable = true)
}
attributeSections["ColorDrawable"] = InspectableObject(props.toMap())
}

View File

@@ -108,10 +108,7 @@ object ViewDescriptor : ChainedDescriptor<View>() {
fromDrawable(node.foreground)?.let { foreground -> props["foreground"] = foreground }
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
props["alpha"] = InspectableValue.Number(node.alpha, mutable = true)
}
props["state"] =
InspectableObject(
mapOf(

View File

@@ -28,6 +28,7 @@ object ViewGroupDescriptor : ChainedDescriptor<ViewGroup>() {
for (i in 0..count) {
val child: View = node.getChildAt(i)
val fragment = FragmentTracker.getFragment(child)
if (fragment != null) {
children.add(fragment)
} else children.add(child)

View File

@@ -8,6 +8,7 @@
package com.facebook.flipper.plugins.uidebugger.descriptors
import androidx.viewpager.widget.ViewPager
import com.facebook.flipper.plugins.uidebugger.core.FragmentTracker
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
@@ -15,7 +16,14 @@ object ViewPagerDescriptor : ChainedDescriptor<ViewPager>() {
override fun onGetName(node: ViewPager): String = node.javaClass.simpleName
override fun onGetActiveChild(node: ViewPager): Any? = node.getChildAt(node.currentItem)
override fun onGetActiveChild(node: ViewPager): Any? {
val child = node.getChildAt(node.currentItem)
val fragment = FragmentTracker.getFragment(child)
if (fragment != null) {
return fragment
}
return child
}
override fun onGetData(
node: ViewPager,

View File

@@ -87,9 +87,11 @@ object WindowDescriptor : ChainedDescriptor<Window>() {
else -> {
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
try {
val hexColor = "#" + Integer.toHexString(typedValue.data)
val color = android.graphics.Color.parseColor(hexColor)
props[name] = InspectableValue.Color(Color.fromColor(color))
} catch (e: Exception) {}
} else if (typedValue.type >= TypedValue.TYPE_FIRST_INT &&
typedValue.type <= TypedValue.TYPE_LAST_INT) {
props[name] = InspectableValue.Number(typedValue.data)

View File

@@ -38,6 +38,8 @@ class PartialLayoutTraversal(
val stack = mutableListOf<Any>()
stack.add(root)
val shallow = mutableSetOf<Any>()
while (stack.isNotEmpty()) {
val node = stack.removeLast()
@@ -49,28 +51,40 @@ class PartialLayoutTraversal(
}
val descriptor = descriptorRegister.descriptorForClassUnsafe(node::class.java).asAny()
if (shallow.contains(node)) {
visited.add(
Node(
node.nodeId(),
descriptor.getName(node),
emptyMap(),
null,
emptySet(),
emptyList(),
null))
shallow.remove(node)
continue
}
val children = descriptor.getChildren(node)
val activeChild = descriptor.getActiveChild(node)
var activeChildId: Id? = null
if (activeChild != null) {
activeChildId = activeChild.nodeId()
}
val childrenIds = mutableListOf<Id>()
children.forEach { child ->
// It might make sense one day to remove id from the descriptor since its always the
// hash code
val childDescriptor =
descriptorRegister.descriptorForClassUnsafe(child::class.java).asAny()
childrenIds.add(child.nodeId())
// If there is an active child then don't traverse it
if (activeChild == null) {
stack.add(child)
// If there is an active child then don't traverse it
if (activeChild != null && activeChild != child) {
shallow.add(child)
}
}
var activeChildId: Id? = null
if (activeChild != null) {
stack.add(activeChild)
activeChildId = activeChild.nodeId()
}
val attributes = descriptor.getData(node)
val bounds = descriptor.getBounds(node)
val tags = descriptor.getTags(node)