Skip to content

Commit 1f0496a

Browse files
committed
Move HierarchicTextAttributeProvider to the internal package
1 parent b19f346 commit 1f0496a

File tree

2 files changed

+222
-147
lines changed

2 files changed

+222
-147
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package com.facebook.react.internal.views.text;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.internal.views.text.EffectiveTextAttributeProvider;
6+
import com.facebook.react.uimanager.ReactAccessibilityDelegate;
7+
import com.facebook.react.views.text.ReactBaseTextShadowNode;
8+
import com.facebook.react.views.text.TextAttributes;
9+
import com.facebook.react.views.text.TextTransform;
10+
11+
/**
12+
* Implementation of {@link EffectiveTextAttributeProvider} that provides effective text
13+
* attributes based on a {@link ReactBaseTextShadowNode} instance and its parent.
14+
*/
15+
public class HierarchicTextAttributeProvider implements EffectiveTextAttributeProvider {
16+
final private ReactBaseTextShadowNode textShadowNode;
17+
final private TextAttributes parentTextAttributes;
18+
final private TextAttributes textAttributes;
19+
20+
public HierarchicTextAttributeProvider(
21+
ReactBaseTextShadowNode textShadowNode,
22+
TextAttributes parentTextAttributes,
23+
TextAttributes textAttributes
24+
) {
25+
this.textShadowNode = textShadowNode;
26+
this.parentTextAttributes = parentTextAttributes;
27+
this.textAttributes = textAttributes;
28+
}
29+
30+
@Override
31+
@NonNull
32+
public TextTransform getTextTransform() {
33+
return textAttributes.getTextTransform();
34+
}
35+
36+
@org.jetbrains.annotations.Nullable
37+
@Override
38+
public ReactAccessibilityDelegate.Role getRole() {
39+
return textShadowNode.getRole();
40+
}
41+
42+
@Override
43+
public ReactAccessibilityDelegate.AccessibilityRole getAccessibilityRole() {
44+
return textShadowNode.getAccessibilityRole();
45+
}
46+
47+
@Override
48+
public boolean isBackgroundColorSet() {
49+
return textShadowNode.isBackgroundColorSet();
50+
}
51+
52+
@Override
53+
public int getBackgroundColor() {
54+
return textShadowNode.getBackgroundColor();
55+
}
56+
57+
@Override
58+
public boolean isColorSet() {
59+
return textShadowNode.isColorSet();
60+
}
61+
62+
@Override
63+
public int getColor() {
64+
return textShadowNode.getColor();
65+
}
66+
67+
@Override
68+
public int getFontStyle() {
69+
return textShadowNode.getFontStyle();
70+
}
71+
72+
@Override
73+
public int getFontWeight() {
74+
return textShadowNode.getFontWeight();
75+
}
76+
77+
@Override
78+
public String getFontFamily() {
79+
return textShadowNode.getFontFamily();
80+
}
81+
82+
@Override
83+
public String getFontFeatureSettings() {
84+
return textShadowNode.getFontFeatureSettings();
85+
}
86+
87+
@Override
88+
public boolean isUnderlineTextDecorationSet() {
89+
return textShadowNode.isUnderlineTextDecorationSet();
90+
}
91+
92+
@Override
93+
public boolean isLineThroughTextDecorationSet() {
94+
return textShadowNode.isLineThroughTextDecorationSet();
95+
}
96+
97+
@Override
98+
public float getTextShadowOffsetDx() {
99+
return textShadowNode.getTextShadowOffsetDx();
100+
}
101+
102+
@Override
103+
public float getTextShadowOffsetDy() {
104+
return textShadowNode.getTextShadowOffsetDy();
105+
}
106+
107+
@Override
108+
public float getTextShadowRadius() {
109+
return textShadowNode.getTextShadowRadius();
110+
}
111+
112+
@Override
113+
public int getTextShadowColor() {
114+
return textShadowNode.getTextShadowColor();
115+
}
116+
117+
@Override
118+
public float getEffectiveLetterSpacing() {
119+
final float letterSpacing = textAttributes.getEffectiveLetterSpacing();
120+
121+
if (!Float.isNaN(letterSpacing)
122+
&& (parentTextAttributes == null
123+
|| parentTextAttributes.getEffectiveLetterSpacing() != letterSpacing)) {
124+
return letterSpacing;
125+
} else {
126+
return Float.NaN;
127+
}
128+
}
129+
130+
@Override
131+
public int getEffectiveFontSize() {
132+
final int fontSize = textAttributes.getEffectiveFontSize();
133+
134+
if (
135+
// `getEffectiveFontSize` always returns a value so don't need to check for anything like
136+
// `Float.NaN`.
137+
parentTextAttributes == null
138+
|| parentTextAttributes.getEffectiveFontSize() != fontSize) {
139+
return fontSize;
140+
} else {
141+
return UNSET;
142+
}
143+
}
144+
145+
@Override
146+
public float getEffectiveLineHeight() {
147+
final float lineHeight = textAttributes.getEffectiveLineHeight();
148+
if (!Float.isNaN(lineHeight)
149+
&& (parentTextAttributes == null
150+
|| parentTextAttributes.getEffectiveLineHeight() != lineHeight)) {
151+
return lineHeight;
152+
} else {
153+
return Float.NaN;
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)