Port visibility and mount state for litho mountables
Summary: Based off D41224546 Reviewed By: mihaelao Differential Revision: D41582451 fbshipit-source-id: 8792d40e47b2049e63a22a51363c093be310fe78
This commit is contained in:
committed by
Facebook GitHub Bot
parent
edf7dd1b8f
commit
0414e145a9
@@ -13,10 +13,13 @@ import com.facebook.flipper.plugins.uidebugger.litho.LithoTag
|
||||
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.ComponentDataExtractor
|
||||
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.LayoutPropExtractor
|
||||
import com.facebook.flipper.plugins.uidebugger.model.Bounds
|
||||
import com.facebook.flipper.plugins.uidebugger.model.Inspectable
|
||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
|
||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
|
||||
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
|
||||
import com.facebook.flipper.plugins.uidebugger.util.Deferred
|
||||
import com.facebook.flipper.plugins.uidebugger.util.MaybeDeferred
|
||||
import com.facebook.litho.Component
|
||||
import com.facebook.litho.DebugComponent
|
||||
|
||||
class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescriptor<DebugComponent> {
|
||||
@@ -66,18 +69,31 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
|
||||
|
||||
private val LayoutId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_LAYOUT, NAMESPACE, "Litho Layout")
|
||||
|
||||
private val UserPropsId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "Litho Props")
|
||||
|
||||
private val StateId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "Litho State")
|
||||
|
||||
private val MountingDataId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "Mount State")
|
||||
|
||||
private val isMountedAttributeId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "mounted")
|
||||
|
||||
private val isVisibleAttributeId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "visible")
|
||||
|
||||
override fun getAttributes(
|
||||
node: DebugComponent
|
||||
): MaybeDeferred<Map<MetadataId, InspectableObject>> {
|
||||
return Deferred {
|
||||
val attributeSections = mutableMapOf<MetadataId, InspectableObject>()
|
||||
|
||||
val mountingData = getMountingData(node)
|
||||
attributeSections[MountingDataId] = InspectableObject(mountingData)
|
||||
|
||||
val layoutProps = LayoutPropExtractor.getProps(node)
|
||||
attributeSections[LayoutId] = InspectableObject(layoutProps.toMap())
|
||||
|
||||
@@ -116,4 +132,36 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
private fun getMountingData(node: DebugComponent): Map<Id, Inspectable> {
|
||||
|
||||
val lithoView = node.lithoView
|
||||
val mountingData = mutableMapOf<MetadataId, Inspectable>()
|
||||
|
||||
if (lithoView == null) {
|
||||
return mountingData
|
||||
}
|
||||
|
||||
val mountState = lithoView.mountDelegateTarget ?: return mountingData
|
||||
val componentTree = lithoView.componentTree ?: return mountingData
|
||||
|
||||
val component = node.component
|
||||
|
||||
if (component.mountType != Component.MountType.NONE) {
|
||||
val renderUnit = DebugComponent.getRenderUnit(node, componentTree)
|
||||
if (renderUnit != null) {
|
||||
val renderUnitId = renderUnit.id
|
||||
val isMounted = mountState.getContentById(renderUnitId) != null
|
||||
mountingData[isMountedAttributeId] = InspectableValue.Boolean(isMounted)
|
||||
}
|
||||
}
|
||||
|
||||
val visibilityOutput = DebugComponent.getVisibilityOutput(node, componentTree)
|
||||
if (visibilityOutput != null) {
|
||||
val isVisible = DebugComponent.isVisible(node, lithoView)
|
||||
mountingData[isVisibleAttributeId] = InspectableValue.Boolean(isVisible)
|
||||
}
|
||||
|
||||
return mountingData
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user