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

Commit

Permalink
Remove usage of ultralight from NT uidebugger
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed May 8, 2024
1 parent 2a83b08 commit b92446d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 45 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,9 +141,12 @@ object UIDebuggerLithoSupport {
event.attributeOrNull<Any?>(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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -250,14 +249,6 @@ class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescripto

override fun getTags(node: DebugComponent): Set<String> {
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 @@ -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<Metadata>,
Expand Down

0 comments on commit b92446d

Please sign in to comment.