Skip to content

Commit

Permalink
Port HierarchicTextAttributeProvider to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
cubuspl42 committed Oct 14, 2023
1 parent 1f0496a commit 50a4fa5
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 156 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.facebook.react.internal.views.text

import com.facebook.react.uimanager.ReactAccessibilityDelegate
import com.facebook.react.views.text.ReactBaseTextShadowNode
import com.facebook.react.views.text.TextAttributes
import com.facebook.react.views.text.TextTransform

/**
* Implementation of {@link EffectiveTextAttributeProvider} that provides effective text
* attributes based on a {@link ReactBaseTextShadowNode} instance and its parent.
*/
class HierarchicTextAttributeProvider(
private val textShadowNode: ReactBaseTextShadowNode,
private val parentTextAttributes: TextAttributes?,
private val textAttributes: TextAttributes
) : EffectiveTextAttributeProvider {
override fun getTextTransform(): TextTransform = textAttributes.textTransform

override fun getRole(): ReactAccessibilityDelegate.Role? = textShadowNode.role

override fun getAccessibilityRole(): ReactAccessibilityDelegate.AccessibilityRole? =
textShadowNode.accessibilityRole

override fun isBackgroundColorSet(): Boolean = textShadowNode.isBackgroundColorSet

override fun getBackgroundColor(): Int = textShadowNode.backgroundColor

override fun isColorSet(): Boolean = textShadowNode.isColorSet

override fun getColor(): Int = textShadowNode.color

override fun getFontStyle(): Int = textShadowNode.fontStyle

override fun getFontWeight(): Int = textShadowNode.fontWeight

override fun getFontFamily(): String = textShadowNode.fontFamily

override fun getFontFeatureSettings(): String = textShadowNode.fontFeatureSettings

override fun isUnderlineTextDecorationSet(): Boolean = textShadowNode.isUnderlineTextDecorationSet

override fun isLineThroughTextDecorationSet(): Boolean =
textShadowNode.isLineThroughTextDecorationSet

override fun getTextShadowOffsetDx(): Float = textShadowNode.textShadowOffsetDx

override fun getTextShadowOffsetDy(): Float = textShadowNode.textShadowOffsetDy

override fun getTextShadowRadius(): Float = textShadowNode.textShadowRadius

override fun getTextShadowColor(): Int = textShadowNode.textShadowColor

override fun getEffectiveLetterSpacing(): Float {
val letterSpacing = textAttributes.effectiveLetterSpacing

val isParentLetterSpacingDifferent =
parentTextAttributes == null || parentTextAttributes.effectiveLetterSpacing != letterSpacing

return if (!letterSpacing.isNaN() && isParentLetterSpacingDifferent) {
letterSpacing
} else {
Float.NaN
}
}

override fun getEffectiveFontSize(): Int {
val fontSize = textAttributes.effectiveFontSize

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
}
}
}

0 comments on commit 50a4fa5

Please sign in to comment.