Skip to content

Commit

Permalink
EffectiveTextAttributeProvider: Use Kotlin-style getters
Browse files Browse the repository at this point in the history
  • Loading branch information
cubuspl42 committed Oct 14, 2023
1 parent 50a4fa5 commit 8b95108
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

0 comments on commit 8b95108

Please sign in to comment.