Improve Textview descriptor
Summary: Also removed button descriptor as android doesnt expose anything usefull Reviewed By: lblasa Differential Revision: D39732772 fbshipit-source-id: 38d5d2290abf7103650e4260ae1169d8d53b1d9b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
740f4b3fdc
commit
277d730f77
@@ -1,23 +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.descriptors
|
||||
|
||||
import android.widget.Button
|
||||
import com.facebook.flipper.plugins.uidebugger.common.InspectableObject
|
||||
|
||||
object ButtonDescriptor : ChainedDescriptor<Button>() {
|
||||
|
||||
override fun onGetName(node: Button): String {
|
||||
return node.javaClass.simpleName
|
||||
}
|
||||
|
||||
override fun onGetData(
|
||||
node: Button,
|
||||
attributeSections: MutableMap<SectionName, InspectableObject>
|
||||
) {}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.facebook.flipper.plugins.uidebugger.common.UIDebuggerException
|
||||
@@ -33,7 +32,6 @@ class DescriptorRegister {
|
||||
mapping.register(ViewGroup::class.java, ViewGroupDescriptor)
|
||||
mapping.register(View::class.java, ViewDescriptor)
|
||||
mapping.register(TextView::class.java, TextViewDescriptor)
|
||||
mapping.register(Button::class.java, ButtonDescriptor)
|
||||
mapping.register(ViewPager::class.java, ViewPagerDescriptor)
|
||||
mapping.register(Drawable::class.java, DrawableDescriptor)
|
||||
mapping.register(ColorDrawable::class.java, ColorDrawableDescriptor)
|
||||
|
||||
@@ -7,17 +7,47 @@
|
||||
|
||||
package com.facebook.flipper.plugins.uidebugger.descriptors
|
||||
|
||||
import android.os.Build
|
||||
import android.widget.TextView
|
||||
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 TextViewDescriptor : ChainedDescriptor<TextView>() {
|
||||
|
||||
override fun onGetName(node: TextView): String {
|
||||
return node.javaClass.simpleName
|
||||
}
|
||||
override fun onGetName(node: TextView): String = node.javaClass.simpleName
|
||||
|
||||
override fun onGetData(
|
||||
node: TextView,
|
||||
attributeSections: MutableMap<SectionName, InspectableObject>
|
||||
) {}
|
||||
) {
|
||||
val typeface = node.typeface
|
||||
|
||||
val props =
|
||||
mutableMapOf<String, Inspectable>(
|
||||
"text" to InspectableValue.Text(node.text.toString(), false),
|
||||
"textSize" to InspectableValue.Number(node.textSize, false),
|
||||
"textColor" to InspectableValue.Color(node.getTextColors().getDefaultColor(), false))
|
||||
|
||||
val typeFace =
|
||||
mutableMapOf<String, InspectableValue>(
|
||||
"isBold" to InspectableValue.Boolean(typeface.isBold, false),
|
||||
"isItalic" to InspectableValue.Boolean(typeface.isItalic, false),
|
||||
)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
typeFace["weight"] = InspectableValue.Number(typeface.weight, false)
|
||||
}
|
||||
|
||||
props["typeface"] = InspectableObject(typeFace)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
props["minLines"] = InspectableValue.Number(node.minLines, false)
|
||||
props["maxLines"] = InspectableValue.Number(node.maxLines, false)
|
||||
props["minWidth"] = InspectableValue.Number(node.minWidth, false)
|
||||
props["maxWidth"] = InspectableValue.Number(node.maxWidth, false)
|
||||
}
|
||||
|
||||
attributeSections.put("TextView", InspectableObject(props))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,23 @@
|
||||
package com.facebook.flipper.plugins.uidebugger.descriptors
|
||||
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.facebook.flipper.plugins.uidebugger.common.InspectableObject
|
||||
import com.facebook.flipper.plugins.uidebugger.common.InspectableValue
|
||||
|
||||
object ViewPagerDescriptor : ChainedDescriptor<ViewPager>() {
|
||||
|
||||
override fun onGetName(node: ViewPager): String = node.javaClass.simpleName
|
||||
|
||||
override fun onGetActiveChild(node: ViewPager): Any? = node.getChildAt(node.currentItem)
|
||||
|
||||
override fun onGetData(
|
||||
node: ViewPager,
|
||||
attributeSections: MutableMap<SectionName, InspectableObject>
|
||||
) {
|
||||
val props =
|
||||
InspectableObject(
|
||||
mapOf("currentItemIndex" to InspectableValue.Number(node.currentItem, false)))
|
||||
|
||||
attributeSections.put("ViewPager", props)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user