From 8b951086e46c78dfd6cff3c7524f79c2e52c6af7 Mon Sep 17 00:00:00 2001 From: Jakub Trzebiatowski Date: Sat, 14 Oct 2023 15:30:57 +0200 Subject: [PATCH] `EffectiveTextAttributeProvider`: Use Kotlin-style getters --- .../text/EffectiveTextAttributeProvider.kt | 40 +++---- .../text/HierarchicTextAttributeProvider.kt | 108 ++++++++++-------- 2 files changed, 83 insertions(+), 65 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt index 756e79d8a0b3c4..f97bdd17ed4e73 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/EffectiveTextAttributeProvider.kt @@ -13,46 +13,46 @@ interface EffectiveTextAttributeProvider { const val UNSET = ReactFontManager.TypefaceStyle.UNSET } - fun getTextTransform(): TextTransform + val textTransform: TextTransform - fun getEffectiveLetterSpacing(): Float + val effectiveLetterSpacing: Float /** * @return The effective font size, or {@link #UNSET} if not set */ - fun getEffectiveFontSize(): Int + val effectiveFontSize: Int - fun getRole(): Role? + val role: Role? - fun getAccessibilityRole(): ReactAccessibilityDelegate.AccessibilityRole? + val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole? - fun isBackgroundColorSet(): Boolean + val isBackgroundColorSet: Boolean - fun getBackgroundColor(): Int + val backgroundColor: Int - fun isColorSet(): Boolean + val isColorSet: Boolean - fun getColor(): Int + val color: Int - fun getFontStyle(): Int + val fontStyle: Int - fun getFontWeight(): Int + val fontWeight: Int - fun getFontFamily(): String? + val fontFamily: String? - fun getFontFeatureSettings(): String? + val fontFeatureSettings: String? - fun isUnderlineTextDecorationSet(): Boolean + val isUnderlineTextDecorationSet: Boolean - fun isLineThroughTextDecorationSet(): Boolean + val isLineThroughTextDecorationSet: Boolean - fun getTextShadowOffsetDx(): Float + val textShadowOffsetDx: Float - fun getTextShadowOffsetDy(): Float + val textShadowOffsetDy: Float - fun getTextShadowRadius(): Float + val textShadowRadius: Float - fun getTextShadowColor(): Int + val textShadowColor: Int - fun getEffectiveLineHeight(): Float + val effectiveLineHeight: Float } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt index df03537a21cfe4..ab3c4836122b77 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt @@ -14,74 +14,92 @@ class HierarchicTextAttributeProvider( private val parentTextAttributes: TextAttributes?, private val textAttributes: TextAttributes ) : EffectiveTextAttributeProvider { - override fun getTextTransform(): TextTransform = textAttributes.textTransform + override val textTransform: TextTransform + get() = textAttributes.textTransform - override fun getRole(): ReactAccessibilityDelegate.Role? = textShadowNode.role + override val role: ReactAccessibilityDelegate.Role? + get() = textShadowNode.role - override fun getAccessibilityRole(): ReactAccessibilityDelegate.AccessibilityRole? = - textShadowNode.accessibilityRole + override val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole? + get() = textShadowNode.accessibilityRole - override fun isBackgroundColorSet(): Boolean = textShadowNode.isBackgroundColorSet + override val isBackgroundColorSet: Boolean + get() = textShadowNode.isBackgroundColorSet - override fun getBackgroundColor(): Int = textShadowNode.backgroundColor + override val backgroundColor: Int + get() = textShadowNode.backgroundColor - override fun isColorSet(): Boolean = textShadowNode.isColorSet + override val isColorSet: Boolean + get() = textShadowNode.isColorSet - override fun getColor(): Int = textShadowNode.color + override val color: Int + get() = textShadowNode.color - override fun getFontStyle(): Int = textShadowNode.fontStyle + override val fontStyle: Int + get() = textShadowNode.fontStyle - override fun getFontWeight(): Int = textShadowNode.fontWeight + override val fontWeight: Int + get() = textShadowNode.fontWeight - override fun getFontFamily(): String = textShadowNode.fontFamily + override val fontFamily: String + get() = textShadowNode.fontFamily - override fun getFontFeatureSettings(): String = textShadowNode.fontFeatureSettings + override val fontFeatureSettings: String + get() = textShadowNode.fontFeatureSettings - override fun isUnderlineTextDecorationSet(): Boolean = textShadowNode.isUnderlineTextDecorationSet + override val isUnderlineTextDecorationSet: Boolean + get() = textShadowNode.isUnderlineTextDecorationSet - override fun isLineThroughTextDecorationSet(): Boolean = - textShadowNode.isLineThroughTextDecorationSet + override val isLineThroughTextDecorationSet: Boolean + get() = textShadowNode.isLineThroughTextDecorationSet - override fun getTextShadowOffsetDx(): Float = textShadowNode.textShadowOffsetDx + override val textShadowOffsetDx: Float + get() = textShadowNode.textShadowOffsetDx - override fun getTextShadowOffsetDy(): Float = textShadowNode.textShadowOffsetDy + override val textShadowOffsetDy: Float + get() = textShadowNode.textShadowOffsetDy - override fun getTextShadowRadius(): Float = textShadowNode.textShadowRadius + override val textShadowRadius: Float + get() = textShadowNode.textShadowRadius - override fun getTextShadowColor(): Int = textShadowNode.textShadowColor + override val textShadowColor: Int + get() = textShadowNode.textShadowColor - override fun getEffectiveLetterSpacing(): Float { - val letterSpacing = textAttributes.effectiveLetterSpacing + override val effectiveLetterSpacing: Float + get() { + val letterSpacing = textAttributes.effectiveLetterSpacing - val isParentLetterSpacingDifferent = - parentTextAttributes == null || parentTextAttributes.effectiveLetterSpacing != letterSpacing + val isParentLetterSpacingDifferent = + parentTextAttributes == null || parentTextAttributes.effectiveLetterSpacing != letterSpacing - return if (!letterSpacing.isNaN() && isParentLetterSpacingDifferent) { - letterSpacing - } else { - Float.NaN + return if (!letterSpacing.isNaN() && isParentLetterSpacingDifferent) { + letterSpacing + } else { + Float.NaN + } } - } - override fun getEffectiveFontSize(): Int { - val fontSize = textAttributes.effectiveFontSize + override val effectiveFontSize: Int + get() { + val fontSize = textAttributes.effectiveFontSize - return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) { - fontSize - } else { - EffectiveTextAttributeProvider.UNSET + return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) { + fontSize + } else { + EffectiveTextAttributeProvider.UNSET + } } - } - override fun getEffectiveLineHeight(): Float { - val lineHeight = textAttributes.effectiveLineHeight - val isParentLineHeightDifferent = - parentTextAttributes == null || parentTextAttributes.effectiveLineHeight != lineHeight - - return if (!lineHeight.isNaN() && isParentLineHeightDifferent) { - lineHeight - } else { - Float.NaN + override val effectiveLineHeight: Float + get() { + val lineHeight = textAttributes.effectiveLineHeight + val isParentLineHeightDifferent = + parentTextAttributes == null || parentTextAttributes.effectiveLineHeight != lineHeight + + return if (!lineHeight.isNaN() && isParentLineHeightDifferent) { + lineHeight + } else { + Float.NaN + } } - } }