diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java index dd1db9681ec675..867f6eaf3346cb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java @@ -22,6 +22,9 @@ import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.yoga.YogaDirection; + +import org.w3c.dom.Text; + import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; @@ -94,7 +97,10 @@ private static void buildSpannedFromShadowNode( ReactShadowNode child = textShadowNode.getChildAt(i); if (child instanceof ReactRawTextShadowNode) { - sb.append(((ReactRawTextShadowNode) child).getText()); + sb.append( + TextTransform.apply( + ((ReactRawTextShadowNode) child).getText(), + textAttributes.getTextTransform())); } else if (child instanceof ReactBaseTextShadowNode) { buildSpannedFromShadowNode((ReactBaseTextShadowNode) child, sb, ops, textAttributes, sb.length()); } else if (child instanceof ReactTextInlineImageShadowNode) { @@ -182,13 +188,6 @@ private static void buildSpannedFromShadowNode( new SetSpanOperation( start, end, new CustomLineHeightSpan(effectiveLineHeight))); } - if (textShadowNode.mTextTransform != TextTransform.UNSET) { - ops.add( - new SetSpanOperation( - start, - end, - new CustomTextTransformSpan(textShadowNode.mTextTransform))); - } ops.add(new SetSpanOperation(start, end, new ReactTagSpan(textShadowNode.getReactTag()))); } } @@ -207,7 +206,7 @@ protected static Spannable spannedFromShadowNode( if (text != null) { // Handle text that is provided via a prop (e.g. the `value` and `defaultValue` props on // TextInput). - sb.append(text); + sb.append(TextTransform.apply(text, textShadowNode.mTextAttributes.getTextTransform())); } buildSpannedFromShadowNode(textShadowNode, sb, ops, null, 0); @@ -266,7 +265,6 @@ private static int parseNumericFontWeight(String fontWeightString) { protected int mTextAlign = Gravity.NO_GRAVITY; protected int mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? 0 : Layout.BREAK_STRATEGY_HIGH_QUALITY; - protected TextTransform mTextTransform = TextTransform.UNSET; protected float mTextShadowOffsetDx = 0; protected float mTextShadowOffsetDy = 0; @@ -520,14 +518,16 @@ public void setTextShadowColor(int textShadowColor) { @ReactProp(name = PROP_TEXT_TRANSFORM) public void setTextTransform(@Nullable String textTransform) { - if (textTransform == null || "none".equals(textTransform)) { - mTextTransform = TextTransform.NONE; + if (textTransform == null) { + mTextAttributes.setTextTransform(TextTransform.UNSET); + } else if ("none".equals(textTransform)) { + mTextAttributes.setTextTransform(TextTransform.NONE); } else if ("uppercase".equals(textTransform)) { - mTextTransform = TextTransform.UPPERCASE; + mTextAttributes.setTextTransform(TextTransform.UPPERCASE); } else if ("lowercase".equals(textTransform)) { - mTextTransform = TextTransform.LOWERCASE; + mTextAttributes.setTextTransform(TextTransform.LOWERCASE); } else if ("capitalize".equals(textTransform)) { - mTextTransform = TextTransform.CAPITALIZE; + mTextAttributes.setTextTransform(TextTransform.CAPITALIZE); } else { throw new JSApplicationIllegalArgumentException("Invalid textTransform: " + textTransform); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributes.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributes.java index a9f35e1496effe..9e1e0b10d62840 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributes.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributes.java @@ -23,6 +23,7 @@ public class TextAttributes { private float mLineHeight = Float.NaN; private float mLetterSpacing = Float.NaN; private float mHeightOfTallestInlineImage = Float.NaN; + private TextTransform mTextTransform = TextTransform.UNSET; public TextAttributes() { } @@ -38,6 +39,7 @@ public TextAttributes applyChild(TextAttributes child) { result.mLineHeight = !Float.isNaN(child.mLineHeight) ? child.mLineHeight : mLineHeight; result.mLetterSpacing = !Float.isNaN(child.mLetterSpacing) ? child.mLetterSpacing : mLetterSpacing; result.mHeightOfTallestInlineImage = !Float.isNaN(child.mHeightOfTallestInlineImage) ? child.mHeightOfTallestInlineImage : mHeightOfTallestInlineImage; + result.mTextTransform = child.mTextTransform != TextTransform.UNSET ? child.mTextTransform : mTextTransform; return result; } @@ -85,6 +87,14 @@ public void setHeightOfTallestInlineImage(float value) { mHeightOfTallestInlineImage = value; } + public TextTransform getTextTransform() { + return mTextTransform; + } + + public void setTextTransform(TextTransform textTransform) { + mTextTransform = textTransform; + } + // Getters for effective values // // In general, these return `Float.NaN` if the property doesn't have a value. @@ -140,6 +150,7 @@ public String toString() { + "\n getEffectiveLetterSpacing(): " + getEffectiveLetterSpacing() + "\n getLineHeight(): " + getLineHeight() + "\n getEffectiveLineHeight(): " + getEffectiveLineHeight() + + "\n getTextTransform(): " + getTextTransform() + "\n}" ); }