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

@@ -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))