|
| 1 | +package com.facebook.react.internal.views.text |
| 2 | + |
| 3 | +import com.facebook.react.uimanager.ReactAccessibilityDelegate |
| 4 | +import com.facebook.react.views.text.ReactBaseTextShadowNode |
| 5 | +import com.facebook.react.views.text.TextAttributes |
| 6 | +import com.facebook.react.views.text.TextTransform |
| 7 | + |
| 8 | +/** |
| 9 | + * Implementation of {@link EffectiveTextAttributeProvider} that provides effective text |
| 10 | + * attributes based on a {@link ReactBaseTextShadowNode} instance and its parent. |
| 11 | + */ |
| 12 | +class HierarchicTextAttributeProvider( |
| 13 | + private val textShadowNode: ReactBaseTextShadowNode, |
| 14 | + private val parentTextAttributes: TextAttributes?, |
| 15 | + private val textAttributes: TextAttributes |
| 16 | +) : EffectiveTextAttributeProvider { |
| 17 | + override fun getTextTransform(): TextTransform = textAttributes.textTransform |
| 18 | + |
| 19 | + override fun getRole(): ReactAccessibilityDelegate.Role? = textShadowNode.role |
| 20 | + |
| 21 | + override fun getAccessibilityRole(): ReactAccessibilityDelegate.AccessibilityRole? = |
| 22 | + textShadowNode.accessibilityRole |
| 23 | + |
| 24 | + override fun isBackgroundColorSet(): Boolean = textShadowNode.isBackgroundColorSet |
| 25 | + |
| 26 | + override fun getBackgroundColor(): Int = textShadowNode.backgroundColor |
| 27 | + |
| 28 | + override fun isColorSet(): Boolean = textShadowNode.isColorSet |
| 29 | + |
| 30 | + override fun getColor(): Int = textShadowNode.color |
| 31 | + |
| 32 | + override fun getFontStyle(): Int = textShadowNode.fontStyle |
| 33 | + |
| 34 | + override fun getFontWeight(): Int = textShadowNode.fontWeight |
| 35 | + |
| 36 | + override fun getFontFamily(): String = textShadowNode.fontFamily |
| 37 | + |
| 38 | + override fun getFontFeatureSettings(): String = textShadowNode.fontFeatureSettings |
| 39 | + |
| 40 | + override fun isUnderlineTextDecorationSet(): Boolean = textShadowNode.isUnderlineTextDecorationSet |
| 41 | + |
| 42 | + override fun isLineThroughTextDecorationSet(): Boolean = |
| 43 | + textShadowNode.isLineThroughTextDecorationSet |
| 44 | + |
| 45 | + override fun getTextShadowOffsetDx(): Float = textShadowNode.textShadowOffsetDx |
| 46 | + |
| 47 | + override fun getTextShadowOffsetDy(): Float = textShadowNode.textShadowOffsetDy |
| 48 | + |
| 49 | + override fun getTextShadowRadius(): Float = textShadowNode.textShadowRadius |
| 50 | + |
| 51 | + override fun getTextShadowColor(): Int = textShadowNode.textShadowColor |
| 52 | + |
| 53 | + override fun getEffectiveLetterSpacing(): Float { |
| 54 | + val letterSpacing = textAttributes.effectiveLetterSpacing |
| 55 | + |
| 56 | + val isParentLetterSpacingDifferent = |
| 57 | + parentTextAttributes == null || parentTextAttributes.effectiveLetterSpacing != letterSpacing |
| 58 | + |
| 59 | + return if (!letterSpacing.isNaN() && isParentLetterSpacingDifferent) { |
| 60 | + letterSpacing |
| 61 | + } else { |
| 62 | + Float.NaN |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + override fun getEffectiveFontSize(): Int { |
| 67 | + val fontSize = textAttributes.effectiveFontSize |
| 68 | + |
| 69 | + return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) { |
| 70 | + fontSize |
| 71 | + } else { |
| 72 | + EffectiveTextAttributeProvider.UNSET |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + override fun getEffectiveLineHeight(): Float { |
| 77 | + val lineHeight = textAttributes.effectiveLineHeight |
| 78 | + val isParentLineHeightDifferent = |
| 79 | + parentTextAttributes == null || parentTextAttributes.effectiveLineHeight != lineHeight |
| 80 | + |
| 81 | + return if (!lineHeight.isNaN() && isParentLineHeightDifferent) { |
| 82 | + lineHeight |
| 83 | + } else { |
| 84 | + Float.NaN |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments