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:
committed by
Facebook GitHub Bot
parent
bb3b1cecef
commit
38109eccff
@@ -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)
|
||||
}
|
||||
props["color"] = InspectableValue.Color(Color.fromColor(node.color), mutable = true)
|
||||
|
||||
attributeSections["ColorDrawable"] = InspectableObject(props.toMap())
|
||||
}
|
||||
|
||||
@@ -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["alpha"] = InspectableValue.Number(node.alpha, mutable = true)
|
||||
props["state"] =
|
||||
InspectableObject(
|
||||
mapOf(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -87,9 +87,11 @@ object WindowDescriptor : ChainedDescriptor<Window>() {
|
||||
else -> {
|
||||
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
|
||||
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
|
||||
val hexColor = "#" + Integer.toHexString(typedValue.data)
|
||||
val color = android.graphics.Color.parseColor(hexColor)
|
||||
props[name] = InspectableValue.Color(Color.fromColor(color))
|
||||
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)
|
||||
|
||||
@@ -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())
|
||||
stack.add(child)
|
||||
// If there is an active child then don't traverse it
|
||||
if (activeChild == null) {
|
||||
stack.add(child)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user