Basic array support

Summary:
Attributes Inspector didn't have support for inspectable arrays.

This change addresses an issue with the inspectable itself and adds basic support to it in the visualiser.

Reviewed By: LukeDefeo

Differential Revision: D41522879

fbshipit-source-id: f9cad42470541039c8157477b0fe9bc58f18f1ba
This commit is contained in:
Lorenzo Blasa
2022-11-28 10:19:20 -08:00
committed by Facebook GitHub Bot
parent 1406e291ee
commit 76b1673d15
4 changed files with 43 additions and 2 deletions

View File

@@ -134,7 +134,7 @@ object ComponentPropExtractor {
override fun isArray(array: EditorArray?): Inspectable { override fun isArray(array: EditorArray?): Inspectable {
val values = array?.value?.map { value -> toInspectable(name, value) } val values = array?.value?.map { value -> toInspectable(name, value) }
return InspectableArray(0, values ?: listOf()) return InspectableArray(values ?: listOf())
} }
override fun isPick(pick: EditorPick): Inspectable = InspectableValue.Enum(pick.selected) override fun isPick(pick: EditorPick): Inspectable = InspectableValue.Enum(pick.selected)

View File

@@ -22,7 +22,7 @@ import kotlinx.serialization.encoding.Encoder
// for native android this should probably be false. // for native android this should probably be false.
@SerialName("array") @SerialName("array")
@Serializable @Serializable
data class InspectableArray(val id: Int, val items: List<Inspectable>) : Inspectable() data class InspectableArray(val items: List<Inspectable>) : Inspectable()
// In this context, mutable means you can add / remove keys, // In this context, mutable means you can add / remove keys,
// for native android this should probably be false. // for native android this should probably be false.

View File

@@ -90,6 +90,32 @@ const ObjectAttributeInspector: React.FC<{
); );
}; };
const ArrayAttributeInspector: React.FC<{
metadata: Map<MetadataId, Metadata>;
name: string;
items: Inspectable[];
level: number;
}> = ({metadata, name, items, level}) => {
return (
<div style={RowStyle}>
{name}
{items.map(function (item, idx) {
const inspectableValue = item;
const attributeName = idx.toString();
return (
<ObjectContainer
key={name + idx}
style={{
paddingLeft: level,
}}>
{create(metadata, attributeName, inspectableValue, level + 2)}
</ObjectContainer>
);
})}
</div>
);
};
function create( function create(
metadata: Map<MetadataId, Metadata>, metadata: Map<MetadataId, Metadata>,
name: string, name: string,
@@ -164,6 +190,15 @@ function create(
<TextValue>{inspectable.value}</TextValue> <TextValue>{inspectable.value}</TextValue>
</NamedAttributeInspector> </NamedAttributeInspector>
); );
case 'array':
return (
<ArrayAttributeInspector
metadata={metadata}
name={displayableName(name)}
items={inspectable.items}
level={level}
/>
);
case 'object': case 'object':
return ( return (
<ObjectAttributeInspector <ObjectAttributeInspector

View File

@@ -129,6 +129,7 @@ export type Tag = 'Native' | 'Declarative' | 'Android' | 'Litho';
export type Inspectable = export type Inspectable =
| InspectableObject | InspectableObject
| InspectableArray
| InspectableText | InspectableText
| InspectableNumber | InspectableNumber
| InspectableColor | InspectableColor
@@ -196,6 +197,11 @@ export type InspectableObject = {
fields: Record<MetadataId, Inspectable>; fields: Record<MetadataId, Inspectable>;
}; };
export type InspectableArray = {
type: 'array';
items: Inspectable[];
};
export type InspectableUnknown = { export type InspectableUnknown = {
type: 'unknown'; type: 'unknown';
value: string; value: string;