Skip to content

Commit ca640db

Browse files
Rebase on top of text inheritance changes
1 parent c70df42 commit ca640db

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import com.facebook.react.uimanager.ViewProps;
2323
import com.facebook.react.uimanager.annotations.ReactProp;
2424
import com.facebook.yoga.YogaDirection;
25+
26+
import org.w3c.dom.Text;
27+
2528
import java.util.ArrayList;
2629
import java.util.List;
2730
import javax.annotation.Nullable;
@@ -94,7 +97,10 @@ private static void buildSpannedFromShadowNode(
9497
ReactShadowNode child = textShadowNode.getChildAt(i);
9598

9699
if (child instanceof ReactRawTextShadowNode) {
97-
sb.append(((ReactRawTextShadowNode) child).getText());
100+
sb.append(
101+
TextTransform.apply(
102+
((ReactRawTextShadowNode) child).getText(),
103+
textAttributes.getTextTransform()));
98104
} else if (child instanceof ReactBaseTextShadowNode) {
99105
buildSpannedFromShadowNode((ReactBaseTextShadowNode) child, sb, ops, textAttributes, sb.length());
100106
} else if (child instanceof ReactTextInlineImageShadowNode) {
@@ -182,13 +188,6 @@ private static void buildSpannedFromShadowNode(
182188
new SetSpanOperation(
183189
start, end, new CustomLineHeightSpan(effectiveLineHeight)));
184190
}
185-
if (textShadowNode.mTextTransform != TextTransform.UNSET) {
186-
ops.add(
187-
new SetSpanOperation(
188-
start,
189-
end,
190-
new CustomTextTransformSpan(textShadowNode.mTextTransform)));
191-
}
192191
ops.add(new SetSpanOperation(start, end, new ReactTagSpan(textShadowNode.getReactTag())));
193192
}
194193
}
@@ -207,7 +206,7 @@ protected static Spannable spannedFromShadowNode(
207206
if (text != null) {
208207
// Handle text that is provided via a prop (e.g. the `value` and `defaultValue` props on
209208
// TextInput).
210-
sb.append(text);
209+
sb.append(TextTransform.apply(text, textShadowNode.mTextAttributes.getTextTransform()));
211210
}
212211

213212
buildSpannedFromShadowNode(textShadowNode, sb, ops, null, 0);
@@ -266,7 +265,6 @@ private static int parseNumericFontWeight(String fontWeightString) {
266265
protected int mTextAlign = Gravity.NO_GRAVITY;
267266
protected int mTextBreakStrategy =
268267
(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? 0 : Layout.BREAK_STRATEGY_HIGH_QUALITY;
269-
protected TextTransform mTextTransform = TextTransform.UNSET;
270268

271269
protected float mTextShadowOffsetDx = 0;
272270
protected float mTextShadowOffsetDy = 0;
@@ -520,14 +518,16 @@ public void setTextShadowColor(int textShadowColor) {
520518

521519
@ReactProp(name = PROP_TEXT_TRANSFORM)
522520
public void setTextTransform(@Nullable String textTransform) {
523-
if (textTransform == null || "none".equals(textTransform)) {
524-
mTextTransform = TextTransform.NONE;
521+
if (textTransform == null) {
522+
mTextAttributes.setTextTransform(TextTransform.UNSET);
523+
} else if ("none".equals(textTransform)) {
524+
mTextAttributes.setTextTransform(TextTransform.NONE);
525525
} else if ("uppercase".equals(textTransform)) {
526-
mTextTransform = TextTransform.UPPERCASE;
526+
mTextAttributes.setTextTransform(TextTransform.UPPERCASE);
527527
} else if ("lowercase".equals(textTransform)) {
528-
mTextTransform = TextTransform.LOWERCASE;
528+
mTextAttributes.setTextTransform(TextTransform.LOWERCASE);
529529
} else if ("capitalize".equals(textTransform)) {
530-
mTextTransform = TextTransform.CAPITALIZE;
530+
mTextAttributes.setTextTransform(TextTransform.CAPITALIZE);
531531
} else {
532532
throw new JSApplicationIllegalArgumentException("Invalid textTransform: " + textTransform);
533533
}

ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributes.java

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class TextAttributes {
2323
private float mLineHeight = Float.NaN;
2424
private float mLetterSpacing = Float.NaN;
2525
private float mHeightOfTallestInlineImage = Float.NaN;
26+
private TextTransform mTextTransform = TextTransform.UNSET;
2627

2728
public TextAttributes() {
2829
}
@@ -38,6 +39,7 @@ public TextAttributes applyChild(TextAttributes child) {
3839
result.mLineHeight = !Float.isNaN(child.mLineHeight) ? child.mLineHeight : mLineHeight;
3940
result.mLetterSpacing = !Float.isNaN(child.mLetterSpacing) ? child.mLetterSpacing : mLetterSpacing;
4041
result.mHeightOfTallestInlineImage = !Float.isNaN(child.mHeightOfTallestInlineImage) ? child.mHeightOfTallestInlineImage : mHeightOfTallestInlineImage;
42+
result.mTextTransform = child.mTextTransform != TextTransform.UNSET ? child.mTextTransform : mTextTransform;
4143

4244
return result;
4345
}
@@ -85,6 +87,14 @@ public void setHeightOfTallestInlineImage(float value) {
8587
mHeightOfTallestInlineImage = value;
8688
}
8789

90+
public TextTransform getTextTransform() {
91+
return mTextTransform;
92+
}
93+
94+
public void setTextTransform(TextTransform textTransform) {
95+
mTextTransform = textTransform;
96+
}
97+
8898
// Getters for effective values
8999
//
90100
// In general, these return `Float.NaN` if the property doesn't have a value.
@@ -140,6 +150,7 @@ public String toString() {
140150
+ "\n getEffectiveLetterSpacing(): " + getEffectiveLetterSpacing()
141151
+ "\n getLineHeight(): " + getLineHeight()
142152
+ "\n getEffectiveLineHeight(): " + getEffectiveLineHeight()
153+
+ "\n getTextTransform(): " + getTextTransform()
143154
+ "\n}"
144155
);
145156
}

0 commit comments

Comments
 (0)