From 8140244f0a69958a915b85c6618c300d25e98117 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Mon, 10 Oct 2022 04:13:06 -0700 Subject: [PATCH] Fix null reference error in text view descriptor Summary: Thanks java / google Reviewed By: lblasa Differential Revision: D40021844 fbshipit-source-id: 19d7d04bf8c637964ef6bea5b28224d7b5134c3f --- .../descriptors/TextViewDescriptor.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/TextViewDescriptor.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/TextViewDescriptor.kt index 35e4c35b9..22b07fa5e 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/TextViewDescriptor.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/descriptors/TextViewDescriptor.kt @@ -21,7 +21,6 @@ object TextViewDescriptor : ChainedDescriptor() { node: TextView, attributeSections: MutableMap ) { - val typeface = node.typeface val props = mutableMapOf( @@ -29,18 +28,21 @@ object TextViewDescriptor : ChainedDescriptor() { "textSize" to InspectableValue.Number(node.textSize, false), "textColor" to InspectableValue.Color(node.getTextColors().getDefaultColor(), false)) - val typeFace = - mutableMapOf( - "isBold" to InspectableValue.Boolean(typeface.isBold, false), - "isItalic" to InspectableValue.Boolean(typeface.isItalic, false), - ) + val typeface = node.typeface + if (typeface != null) { + val typeFaceProp = + mutableMapOf( + "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) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + typeFaceProp["weight"] = InspectableValue.Number(typeface.weight, false) + } + + props["typeface"] = InspectableObject(typeFaceProp) } - 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)