Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Integrate NT debug metadata into UIDebugger for NT Components
Browse files Browse the repository at this point in the history
Summary: Lets do the same thing we did on iOS in bringing NT derived layers into the UIDebugger. This should be enough for us to deprecate the NT Layout plugin completely

Reviewed By: LukeDefeo

Differential Revision: D56630864

fbshipit-source-id: c72ec67502aebec952156e6dc6be655650fc1595
  • Loading branch information
Omar Rasheed authored and facebook-github-bot committed Apr 29, 2024
1 parent 260ac0b commit 35f7c0f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<String>?

fun getExtraHiddenAttributes(node: DebugComponent): JsonObject?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -247,7 +249,14 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto
Bounds.fromRect(node.boundsInParentDebugComponent)

override fun getTags(node: DebugComponent): Set<String> {
val tags = mutableSetOf(LithoTag)
val tags: MutableSet<String> = 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)
Expand Down Expand Up @@ -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<Metadata>,
val value: FlipperDynamic,
Expand Down

0 comments on commit 35f7c0f

Please # to comment.