Add basic drawable descriptor

Reviewed By: lblasa

Differential Revision: D39731553

fbshipit-source-id: 77a8ff244b63e2f14c671bbff6c18dbe3ec25257
This commit is contained in:
Luke De Feo
2022-09-29 05:31:18 -07:00
committed by Facebook GitHub Bot
parent 7ae2c35476
commit 740f4b3fdc
5 changed files with 80 additions and 7 deletions

View File

@@ -0,0 +1,32 @@
/*
* 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.descriptors
import android.graphics.drawable.ColorDrawable
import android.os.Build
import com.facebook.flipper.plugins.uidebugger.common.Inspectable
import com.facebook.flipper.plugins.uidebugger.common.InspectableObject
import com.facebook.flipper.plugins.uidebugger.common.InspectableValue
object ColorDrawableDescriptor : ChainedDescriptor<ColorDrawable>() {
override fun onGetName(node: ColorDrawable): String = node.javaClass.simpleName
override fun onGetData(
node: ColorDrawable,
attributeSections: MutableMap<SectionName, InspectableObject>
) {
val props = mutableMapOf<String, Inspectable>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
props.put("color", InspectableValue.Color(node.color, mutable = true))
}
attributeSections["ColorDrawable"] = InspectableObject(props.toMap())
}
}

View File

@@ -8,6 +8,8 @@
package com.facebook.flipper.plugins.uidebugger.descriptors package com.facebook.flipper.plugins.uidebugger.descriptors
import android.app.Activity import android.app.Activity
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.Window import android.view.Window
@@ -33,6 +35,8 @@ class DescriptorRegister {
mapping.register(TextView::class.java, TextViewDescriptor) mapping.register(TextView::class.java, TextViewDescriptor)
mapping.register(Button::class.java, ButtonDescriptor) mapping.register(Button::class.java, ButtonDescriptor)
mapping.register(ViewPager::class.java, ViewPagerDescriptor) mapping.register(ViewPager::class.java, ViewPagerDescriptor)
mapping.register(Drawable::class.java, DrawableDescriptor)
mapping.register(ColorDrawable::class.java, ColorDrawableDescriptor)
mapping.register(android.app.Fragment::class.java, FragmentFrameworkDescriptor) mapping.register(android.app.Fragment::class.java, FragmentFrameworkDescriptor)
mapping.register(androidx.fragment.app.Fragment::class.java, FragmentSupportDescriptor) mapping.register(androidx.fragment.app.Fragment::class.java, FragmentSupportDescriptor)

View File

@@ -0,0 +1,37 @@
/*
* 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.descriptors
import android.graphics.drawable.Drawable
import android.os.Build
import com.facebook.flipper.plugins.uidebugger.common.Inspectable
import com.facebook.flipper.plugins.uidebugger.common.InspectableObject
import com.facebook.flipper.plugins.uidebugger.common.InspectableValue
import com.facebook.flipper.plugins.uidebugger.model.Bounds
object DrawableDescriptor : ChainedDescriptor<Drawable>() {
override fun onGetName(node: Drawable): String = node.javaClass.simpleName
override fun onGetBounds(node: Drawable): Bounds =
Bounds(node.bounds.left, node.bounds.top, node.bounds.width(), node.bounds.height())
override fun onGetData(
node: Drawable,
attributeSections: MutableMap<SectionName, InspectableObject>
) {
val props = mutableMapOf<String, Inspectable>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
props.put("alpha", InspectableValue.Number(node.getAlpha(), true))
}
attributeSections["Drawable"] = InspectableObject(props.toMap())
}
override fun onGetTags(node: Drawable): Set<String> = BaseTags.NativeAndroid
}

View File

@@ -22,11 +22,14 @@ import com.facebook.flipper.plugins.uidebugger.model.Bounds
typealias SectionName = String typealias SectionName = String
object BaseTags { object BaseTags {
const val Declarative = "Declarative" const val Declarative = "Declarative"
const val Native = "Native" const val Native = "Native"
const val Accessibility = "Accessibility" const val Accessibility = "Accessibility"
const val Android = "Android" const val Android = "Android"
const val Unknown = "Unknown" const val Unknown = "Unknown"
val NativeAndroid = setOf(Android, Native)
val AccessibleNativeAndroid = setOf(Android, Native, Accessibility)
} }
interface NodeDescriptor<T> { interface NodeDescriptor<T> {

View File

@@ -26,15 +26,12 @@ import java.lang.reflect.Field
object ViewDescriptor : ChainedDescriptor<View>() { object ViewDescriptor : ChainedDescriptor<View>() {
override fun onGetName(node: View): String { override fun onGetName(node: View): String = node.javaClass.simpleName
return node.javaClass.simpleName
}
override fun onGetBounds(node: View): Bounds { override fun onGetBounds(node: View): Bounds =
return Bounds(node.left, node.top, node.width, node.height) Bounds(node.left, node.top, node.width, node.height)
}
override fun onGetTags(node: View): Set<String> = setOf(BaseTags.Native, BaseTags.Android) override fun onGetTags(node: View): Set<String> = BaseTags.NativeAndroid
override fun onGetData( override fun onGetData(
node: View, node: View,