Make node bounds mandatory in protocol

Summary: This makes life on the desktop easier as 99% of the time bounds were there but we were dealing with non sensical non null branches.

Reviewed By: lblasa

Differential Revision: D41218325

fbshipit-source-id: e490d3775720c1c55dcb8f4a2a85520294f5e2a9
This commit is contained in:
Luke De Feo
2022-11-14 07:05:58 -08:00
committed by Facebook GitHub Bot
parent a4d3167fae
commit 1398e2aa8a
7 changed files with 9 additions and 62 deletions

View File

@@ -1,51 +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.descriptors
import android.graphics.Bitmap
import com.facebook.flipper.plugins.uidebugger.descriptors.*
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
/** a drawable or view that is mounted, along with the correct descriptor */
class MountedObject(val obj: Any, val descriptor: NodeDescriptor<Any>)
object MountedObjectDescriptor : NodeDescriptor<MountedObject> {
override fun getBounds(node: MountedObject): Bounds? {
val bounds = node.descriptor.getBounds(node.obj)
bounds?.let { b ->
/**
* When we ask android for the bounds the x,y offset is w.r.t to the nearest android parent
* view group. From UI debuggers perspective using the raw android offset will double the
* total offset of this native view as the offset is included by the litho components between
* the mounted view and its native parent
*/
return Bounds(0, 0, b.width, b.height)
}
return null
}
override fun getName(node: MountedObject): String = node.descriptor.getName(node.obj)
override fun getQualifiedName(node: MountedObject): String =
node.descriptor.getQualifiedName(node.obj)
override fun getChildren(node: MountedObject): List<Any> = node.descriptor.getChildren(node.obj)
override fun getActiveChild(node: MountedObject): Any? = node.descriptor.getActiveChild(node.obj)
override fun getData(node: MountedObject): Map<MetadataId, InspectableObject> =
node.descriptor.getData(node.obj)
override fun getTags(node: MountedObject): Set<String> = node.descriptor.getTags(node.obj)
override fun getSnapshot(node: MountedObject, bitmap: Bitmap?): Bitmap? =
node.descriptor.getSnapshot(node.obj, bitmap)
}

View File

@@ -67,8 +67,9 @@ abstract class ChainedDescriptor<T> : NodeDescriptor<T> {
abstract fun onGetName(node: T): String
final override fun getBounds(node: T): Bounds? {
return onGetBounds(node) ?: mSuper?.getBounds(node)
final override fun getBounds(node: T): Bounds {
val bounds = onGetBounds(node) ?: mSuper?.getBounds(node)
return bounds ?: Bounds(0, 0, 0, 0)
}
open fun onGetBounds(node: T): Bounds? = null

View File

@@ -34,7 +34,7 @@ object BaseTags {
interface NodeDescriptor<T> {
/** Should be w.r.t the direct parent */
fun getBounds(node: T): Bounds?
fun getBounds(node: T): Bounds
/**
* The name used to identify this node in the inspector. Does not need to be unique. A good

View File

@@ -28,7 +28,7 @@ object ObjectDescriptor : NodeDescriptor<Any> {
override fun getData(node: Any) = mutableMapOf<MetadataId, InspectableObject>()
override fun getBounds(node: Any): Bounds? = null
override fun getBounds(node: Any): Bounds = Bounds(0, 0, 0, 0)
override fun getTags(node: Any): Set<String> = setOf(BaseTags.Unknown)

View File

@@ -21,12 +21,9 @@ class OffsetChild(val child: Any, val descriptor: NodeDescriptor<Any>, val x: In
object OffsetChildDescriptor : NodeDescriptor<OffsetChild> {
override fun getBounds(node: OffsetChild): Bounds? {
override fun getBounds(node: OffsetChild): Bounds {
val bounds = node.descriptor.getBounds(node.child)
bounds?.let { b ->
return Bounds(node.x, node.y, b.width, b.height)
}
return null
return Bounds(node.x, node.y, bounds.width, bounds.height)
}
override fun getName(node: OffsetChild): String = node.descriptor.getName(node.child)

View File

@@ -15,7 +15,7 @@ data class Node(
val qualifiedName: String,
val name: String,
val attributes: Map<MetadataId, InspectableObject>,
val bounds: Bounds?,
val bounds: Bounds,
val tags: Set<String>,
val children: List<Id>,
val activeChild: Id?,

View File

@@ -59,7 +59,7 @@ class PartialLayoutTraversal(
descriptor.getQualifiedName(node),
descriptor.getName(node),
emptyMap(),
null,
descriptor.getBounds(node),
emptySet(),
emptyList(),
null))