diff --git a/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/ILithoDebugComponentDescriptorExtension.kt b/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/ILithoDebugComponentDescriptorExtension.kt new file mode 100644 index 00000000000..eede79d04bf --- /dev/null +++ b/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/ILithoDebugComponentDescriptorExtension.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.flipper.plugins.uidebugger.litho + +import com.facebook.inject.statics.BoundSetStatic +import com.facebook.litho.DebugComponent +import kotlinx.serialization.json.JsonObject + +@BoundSetStatic +interface ILithoDebugComponentDescriptorExtension { + fun getExtraTags(node: DebugComponent): Set? + + fun getExtraHiddenAttributes(node: DebugComponent): JsonObject? +} 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 002e178243f..9b47585f749 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 @@ -16,6 +16,7 @@ import com.facebook.flipper.plugins.uidebugger.descriptors.Id import com.facebook.flipper.plugins.uidebugger.descriptors.MetadataRegister import com.facebook.flipper.plugins.uidebugger.descriptors.NodeDescriptor import com.facebook.flipper.plugins.uidebugger.descriptors.OffsetChild +import com.facebook.flipper.plugins.uidebugger.litho.ILithoDebugComponentDescriptorExtensionStatic import com.facebook.flipper.plugins.uidebugger.litho.LithoMountableTag import com.facebook.flipper.plugins.uidebugger.litho.LithoTag import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.ComponentDataExtractor @@ -40,6 +41,7 @@ import com.facebook.litho.widget.RecyclerBinder import com.facebook.rendercore.FastMath import com.facebook.yoga.YogaEdge import java.lang.reflect.Modifier +import kotlinx.serialization.json.JsonObject typealias GlobalKey = String @@ -247,7 +249,14 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto Bounds.fromRect(node.boundsInParentDebugComponent) override fun getTags(node: DebugComponent): Set { - val tags = mutableSetOf(LithoTag) + val tags: MutableSet = mutableSetOf(LithoTag) + + for (id in ILithoDebugComponentDescriptorExtensionStatic.getKeys()) { + val extraTags = ILithoDebugComponentDescriptorExtensionStatic.getExtraTags(id, node) + if (extraTags != null) { + tags.addAll(extraTags) + } + } if (node.component.mountType != Component.MountType.NONE) { tags.add(LithoMountableTag) @@ -303,6 +312,22 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto return mountingData } + private fun mergeJsonObjects(obj1: JsonObject, obj2: JsonObject): JsonObject { + return JsonObject(obj1.toMap() + obj2.toMap()) + } + + override fun getHiddenAttributes(node: DebugComponent): JsonObject? { + var hiddenAttributes = JsonObject(mapOf()) + for (id in ILithoDebugComponentDescriptorExtensionStatic.getKeys()) { + val extraHiddenAttributes = + ILithoDebugComponentDescriptorExtensionStatic.getExtraHiddenAttributes(id, node) + if (extraHiddenAttributes != null) { + hiddenAttributes = mergeJsonObjects(hiddenAttributes, extraHiddenAttributes) + } + } + return hiddenAttributes + } + class OverrideData( val metadataPath: List, val value: FlipperDynamic,