Litho state support
Reviewed By: lblasa Differential Revision: D41581347 fbshipit-source-id: 262670053c586676be4f9465854ec79f95699d33
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b701d76668
commit
cffe42a93a
@@ -10,7 +10,7 @@ package com.facebook.flipper.plugins.uidebugger.litho.descriptors
|
||||
import android.graphics.Bitmap
|
||||
import com.facebook.flipper.plugins.uidebugger.descriptors.*
|
||||
import com.facebook.flipper.plugins.uidebugger.litho.LithoTag
|
||||
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.ComponentPropExtractor
|
||||
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.InspectableObject
|
||||
@@ -69,6 +69,9 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
|
||||
private val UserPropsId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "Litho Props")
|
||||
|
||||
private val StateId =
|
||||
MetadataRegister.register(MetadataRegister.TYPE_ATTRIBUTE, NAMESPACE, "Litho State")
|
||||
|
||||
override fun getData(node: DebugComponent): MaybeDeferred<Map<MetadataId, InspectableObject>> {
|
||||
return Deferred {
|
||||
val attributeSections = mutableMapOf<MetadataId, InspectableObject>()
|
||||
@@ -77,7 +80,14 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
|
||||
attributeSections[LayoutId] = InspectableObject(layoutProps.toMap())
|
||||
|
||||
if (!node.canResolve()) {
|
||||
val props = ComponentPropExtractor.getProps(node.component)
|
||||
val stateContainer = node.stateContainer
|
||||
if (stateContainer != null) {
|
||||
attributeSections[StateId] =
|
||||
ComponentDataExtractor.getState(stateContainer, node.component.simpleName)
|
||||
}
|
||||
|
||||
val props = ComponentDataExtractor.getProps(node.component)
|
||||
|
||||
attributeSections[UserPropsId] = InspectableObject(props.toMap())
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ import com.facebook.flipper.plugins.uidebugger.descriptors.MetadataRegister
|
||||
import com.facebook.flipper.plugins.uidebugger.model.*
|
||||
import com.facebook.litho.Component
|
||||
import com.facebook.litho.SpecGeneratedComponent
|
||||
import com.facebook.litho.StateContainer
|
||||
import com.facebook.litho.annotations.Prop
|
||||
import com.facebook.litho.annotations.ResType
|
||||
import com.facebook.litho.annotations.State
|
||||
import com.facebook.litho.editor.EditorRegistry
|
||||
import com.facebook.litho.editor.model.EditorArray
|
||||
import com.facebook.litho.editor.model.EditorBool
|
||||
@@ -25,10 +27,8 @@ import com.facebook.litho.editor.model.EditorShape
|
||||
import com.facebook.litho.editor.model.EditorString
|
||||
import com.facebook.litho.editor.model.EditorValue
|
||||
import com.facebook.litho.editor.model.EditorValue.EditorVisitor
|
||||
import com.facebook.yoga.*
|
||||
|
||||
object ComponentPropExtractor {
|
||||
private const val NAMESPACE = "ComponentPropExtractor"
|
||||
object ComponentDataExtractor {
|
||||
|
||||
fun getProps(component: Component): Map<MetadataId, Inspectable> {
|
||||
val props = mutableMapOf<MetadataId, Inspectable>()
|
||||
@@ -79,6 +79,25 @@ object ComponentPropExtractor {
|
||||
return props
|
||||
}
|
||||
|
||||
fun getState(stateContainer: StateContainer, componentName: String): InspectableObject {
|
||||
|
||||
val stateFields = mutableMapOf<MetadataId, Inspectable>()
|
||||
for (field in stateContainer.javaClass.declaredFields) {
|
||||
field.isAccessible = true
|
||||
val stateAnnotation = field.getAnnotation(State::class.java)
|
||||
val isKStateField = field.name == "mStates"
|
||||
if (stateAnnotation != null || isKStateField) {
|
||||
val id = getMetadataId(componentName, field.name)
|
||||
val editorValue: EditorValue? = EditorRegistry.read(field.type, field, stateContainer)
|
||||
if (editorValue != null) {
|
||||
stateFields[id] = toInspectable(field.name, editorValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return InspectableObject(stateFields)
|
||||
}
|
||||
|
||||
private fun getMetadataId(
|
||||
namespace: String,
|
||||
key: String,
|
||||
Reference in New Issue
Block a user