Add Id to node descriptor interface

Summary:
There were 2 situations where the UI hadn't changed but we were sending a nodes with a different Id accross traversals which confuses things on the desktop

1. By removing the litho observer we are repeatidly scanning the entire hierachy on scroll or when a video plays. The debug component that represents litho views are not stable, they are generated each time even if the underlying component is the same
2. Offset child is generated by us each time and the old id refered to the generated offset child not the underlying object

This diff addresses these 2 cases by allowing a descriptor to choose the ID.

The nodeId convience method was used in a lot of places. For the places where the id ended up in the protocol we have migrated to the descriptors getID. In some other places it is only used internally or for logging.  In this case I have renamed the method and changed the return type from Id to int so it cant be accidently used in the protocol

Reviewed By: lblasa

Differential Revision: D41307239

fbshipit-source-id: 655b230180a6d02d66888e86b2293eead3385455
This commit is contained in:
Luke De Feo
2022-11-16 10:38:23 -08:00
committed by Facebook GitHub Bot
parent f6060d0046
commit 0ebedc9c49
9 changed files with 55 additions and 27 deletions

View File

@@ -13,7 +13,6 @@ import android.view.ViewTreeObserver
import com.facebook.flipper.plugins.uidebugger.LogTag
import com.facebook.flipper.plugins.uidebugger.core.Context
import com.facebook.flipper.plugins.uidebugger.descriptors.ViewDescriptor
import com.facebook.flipper.plugins.uidebugger.descriptors.nodeId
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.LithoViewDescriptor
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.model.Coordinate
@@ -21,6 +20,7 @@ import com.facebook.flipper.plugins.uidebugger.observers.CoordinateUpdate
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserver
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverBuilder
import com.facebook.flipper.plugins.uidebugger.scheduler.throttleLatest
import com.facebook.flipper.plugins.uidebugger.util.objectIdentity
import com.facebook.litho.LithoView
import com.facebook.rendercore.extensions.ExtensionState
import com.facebook.rendercore.extensions.MountExtension
@@ -56,10 +56,10 @@ class LithoViewTreeObserver(val context: Context) : TreeObserver<LithoView>() {
@SuppressLint("PrivateApi")
override fun subscribe(node: Any) {
Log.d(LogTag, "Subscribing to litho view ${node.nodeId()}")
nodeRef = node as LithoView
Log.d(LogTag, "Subscribing to litho view ${nodeRef?.objectIdentity()}")
val lithoDebuggerExtension = LithoDebuggerExtension(this)
node.registerUIDebugger(lithoDebuggerExtension)
@@ -69,7 +69,8 @@ class LithoViewTreeObserver(val context: Context) : TreeObserver<LithoView>() {
val bounds = ViewDescriptor.onGetBounds(node)
if (bounds != lastBounds) {
context.treeObserverManager.enqueueUpdate(
CoordinateUpdate(this.type, node.nodeId(), Coordinate(bounds.x, bounds.y)))
CoordinateUpdate(
this.type, LithoViewDescriptor.getId(node), Coordinate(bounds.x, bounds.y)))
lastBounds = bounds
}
}
@@ -89,7 +90,7 @@ class LithoViewTreeObserver(val context: Context) : TreeObserver<LithoView>() {
}
override fun unsubscribe() {
Log.d(LogTag, "Unsubscribing from litho view ${nodeRef?.nodeId()}")
Log.d(LogTag, "Unsubscribing from litho view ${nodeRef?.objectIdentity()}")
nodeRef?.viewTreeObserver?.removeOnPreDrawListener(preDrawListener)
nodeRef?.unregisterUIDebugger()
nodeRef = null
@@ -107,7 +108,7 @@ class LithoDebuggerExtension(val observer: LithoViewTreeObserver) : MountExtensi
* mounting includes adding updating or removing views from the heriachy
*/
override fun afterMount(state: ExtensionState<Void?>) {
Log.i(LogTag, "After mount called for litho view ${observer.nodeRef?.nodeId()}")
Log.i(LogTag, "After mount called for litho view ${observer.nodeRef?.objectIdentity()}")
observer.lastBounds = ViewDescriptor.onGetBounds(state.rootHost)
observer.processUpdate(observer.context, state.rootHost as Any)
}

View File

@@ -20,6 +20,12 @@ import com.facebook.litho.DebugComponent
class DebugComponentDescriptor(val register: DescriptorRegister) : NodeDescriptor<DebugComponent> {
private val NAMESPACE = "DebugComponent"
/*
* Debug component is generated on the fly so use the underlying component instance which is
* immutable
*/
override fun getId(node: DebugComponent): Id = System.identityHashCode(node.component)
override fun getName(node: DebugComponent): String = node.component.simpleName
override fun getQualifiedName(node: com.facebook.litho.DebugComponent): String =