From b92446d6d1270b3f2a8ffe4096e3a3715427438f Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Wed, 8 May 2024 08:48:15 -0700 Subject: [PATCH] Remove usage of ultralight from NT uidebugger Summary: using Ultralight is problematic for uidebugger since UIDebugger is used in contexts where ultralight isnt (Open source & flipper / litho sample apps in buck) The new approach is a tad hacky, we add a descriptor that handles debug component (the litho wrapper for litho Component class), this new descriptor can also handle NT if the underlying component is an NT component, this is recognised by the WrappedNTComponent class. If so we add the additional parts for the desktop. This descriptor is manually added in apps that have NT, currently just fb4a The hacky part is we overrite the original descriptor in the registry, but given how DebugComponent works and is used regardless of if we are NT / Litho i dont see a better way Differential Revision: D57105063 fbshipit-source-id: 63e291c22c566ff52277013fe1b945f8c41464c1 --- ...ILithoDebugComponentDescriptorExtension.kt | 19 -------------- .../litho/UIDebuggerLithoSupport.kt | 11 ++++++-- .../descriptors/DebugComponentDescriptor.kt | 25 +------------------ 3 files changed, 10 insertions(+), 45 deletions(-) delete mode 100644 android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/ILithoDebugComponentDescriptorExtension.kt 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 deleted file mode 100644 index eede79d04bf..00000000000 --- a/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/ILithoDebugComponentDescriptorExtension.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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/UIDebuggerLithoSupport.kt b/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/UIDebuggerLithoSupport.kt index b43e8de4c12..edfc368ba28 100644 --- a/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/UIDebuggerLithoSupport.kt +++ b/android/plugins/litho/src/main/java/com/facebook/flipper/plugins/uidebugger/litho/UIDebuggerLithoSupport.kt @@ -10,7 +10,11 @@ package com.facebook.flipper.plugins.uidebugger.litho import com.facebook.flipper.plugins.uidebugger.core.ConnectionListener import com.facebook.flipper.plugins.uidebugger.core.UIDContext import com.facebook.flipper.plugins.uidebugger.descriptors.DescriptorRegister -import com.facebook.flipper.plugins.uidebugger.litho.descriptors.* +import com.facebook.flipper.plugins.uidebugger.litho.descriptors.ComponentTreeDescriptor +import com.facebook.flipper.plugins.uidebugger.litho.descriptors.DebugComponentDescriptor +import com.facebook.flipper.plugins.uidebugger.litho.descriptors.LithoViewDescriptor +import com.facebook.flipper.plugins.uidebugger.litho.descriptors.MatrixDrawableDescriptor +import com.facebook.flipper.plugins.uidebugger.litho.descriptors.TextDrawableDescriptor import com.facebook.flipper.plugins.uidebugger.model.FrameworkEvent import com.facebook.flipper.plugins.uidebugger.model.FrameworkEventMetadata import com.facebook.litho.ComponentTree @@ -137,9 +141,12 @@ object UIDebuggerLithoSupport { event.attributeOrNull(attributeName)?.let { attributes[attributeName] = it.toString() } } + lateinit var DebugComponentDescritpor: DebugComponentDescriptor + private fun addDescriptors(register: DescriptorRegister) { register.register(LithoView::class.java, LithoViewDescriptor) - register.register(DebugComponent::class.java, DebugComponentDescriptor(register)) + DebugComponentDescritpor = DebugComponentDescriptor(register) + register.register(DebugComponent::class.java, DebugComponentDescritpor) register.register(TextDrawable::class.java, TextDrawableDescriptor) register.register(MatrixDrawable::class.java, MatrixDrawableDescriptor) register.register(ComponentTree::class.java, ComponentTreeDescriptor(register)) 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 9b47585f749..2aa0234b054 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,7 +16,6 @@ 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 @@ -250,14 +249,6 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto override fun getTags(node: DebugComponent): Set { 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) } @@ -312,21 +303,7 @@ 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 - } + override fun getHiddenAttributes(node: DebugComponent): JsonObject? = null class OverrideData( val metadataPath: List,