diff --git a/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/descriptors/DebugComponentDescriptor.kt b/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/descriptors/DebugComponentDescriptor.kt index ffaeedd65..960fe56b6 100644 --- a/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/descriptors/DebugComponentDescriptor.kt +++ b/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/descriptors/DebugComponentDescriptor.kt @@ -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 { @@ -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> { return Deferred { val attributeSections = mutableMapOf() + 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 { + + val lithoView = node.lithoView + val mountingData = mutableMapOf() + + 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 + } }