Skip to content

Commit

Permalink
Add box data to native android
Browse files Browse the repository at this point in the history
Summary:
This powers the UIDebuggers box visualiser.

The android box model doesnt include padding so its just 0

Reviewed By: lblasa

Differential Revision: D53812666

fbshipit-source-id: 802c85ac5cbac9e0258433878205b8332489364c
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Feb 19, 2024
1 parent b1e8665 commit 3c9096a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.facebook.flipper.plugins.uidebugger.descriptors

import com.facebook.flipper.core.FlipperDynamic
import com.facebook.flipper.plugins.uidebugger.model.Bounds
import com.facebook.flipper.plugins.uidebugger.model.BoxData
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
import com.facebook.flipper.plugins.uidebugger.model.Metadata
import com.facebook.flipper.plugins.uidebugger.model.MetadataId
Expand Down Expand Up @@ -42,6 +43,10 @@ abstract class ChainedDescriptor<T> : NodeDescriptor<T> {
return mSuper
}

final override fun getBoxData(node: T): BoxData? = onGetBoxData(node) ?: mSuper?.getBoxData(node)

open fun onGetBoxData(node: T): BoxData? = null

final override fun getActiveChild(node: T): Any? {
// ask each descriptor in the chain for an active child, if none available look up the chain
// until no more super descriptors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,33 @@ object ViewDescriptor : ChainedDescriptor<View>() {
}
}

private val emptyBox = listOf(0f, 0f, 0f, 0f)

override fun onGetBoxData(node: View): BoxData {

val layoutParams = node.layoutParams
val margin =
if (layoutParams is ViewGroup.MarginLayoutParams) {
listOf(
layoutParams.topMargin.toFloat(),
layoutParams.rightMargin.toFloat(),
layoutParams.bottomMargin.toFloat(),
layoutParams.leftMargin.toFloat())
} else {
emptyBox
}

val padding =
listOf<Float>(
node.paddingLeft.toFloat(),
node.paddingRight.toFloat(),
node.paddingTop.toFloat(),
node.paddingBottom.toFloat(),
)

return BoxData(margin, emptyBox, padding)
}

override fun onGetInlineAttributes(node: View, attributes: MutableMap<String, String>) {
val id = node.id
if (id == View.NO_ID) {
Expand Down

0 comments on commit 3c9096a

Please sign in to comment.