forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port
HierarchicTextAttributeProvider
to Kotlin
- Loading branch information
Showing
2 changed files
with
87 additions
and
156 deletions.
There are no files selected for viewing
156 changes: 0 additions & 156 deletions
156
...src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.java
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
...d/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |