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 05091cc328954f..8a88ea244a8741 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 @@ -113,76 +113,85 @@ private static void buildSpannedFromShadowNode( } int end = sb.length(); if (end >= start) { - if (textShadowNode.mIsColorSet) { - ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(textShadowNode.mColor))); - } - if (textShadowNode.mIsBackgroundColorSet) { - ops.add( - new SetSpanOperation( - start, end, new BackgroundColorSpan(textShadowNode.mBackgroundColor))); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (!Float.isNaN(textShadowNode.mLetterSpacing)) { - ops.add(new SetSpanOperation( - start, - end, - new CustomLetterSpacingSpan(textShadowNode.mLetterSpacing))); - } - } - if (textShadowNode.mFontSize != UNSET) { - ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(textShadowNode.mFontSize))); - } - if (textShadowNode.mFontStyle != UNSET - || textShadowNode.mFontWeight != UNSET - || textShadowNode.mFontFamily != null) { - ops.add( - new SetSpanOperation( - start, - end, - new CustomStyleSpan( - textShadowNode.mFontStyle, - textShadowNode.mFontWeight, - textShadowNode.mFontFamily, - textShadowNode.getThemedContext().getAssets()))); - } - if (textShadowNode.mIsUnderlineTextDecorationSet) { - ops.add(new SetSpanOperation(start, end, new UnderlineSpan())); - } - if (textShadowNode.mIsLineThroughTextDecorationSet) { - ops.add(new SetSpanOperation(start, end, new StrikethroughSpan())); - } - if ( - ( - textShadowNode.mTextShadowOffsetDx != 0 || - textShadowNode.mTextShadowOffsetDy != 0 || - textShadowNode.mTextShadowRadius != 0 - ) && - Color.alpha(textShadowNode.mTextShadowColor) != 0 - ) { - ops.add( - new SetSpanOperation( - start, - end, - new ShadowStyleSpan( - textShadowNode.mTextShadowOffsetDx, - textShadowNode.mTextShadowOffsetDy, - textShadowNode.mTextShadowRadius, - textShadowNode.mTextShadowColor))); - } - if (!Float.isNaN(textShadowNode.getEffectiveLineHeight())) { - ops.add( - new SetSpanOperation( - start, end, new CustomLineHeightSpan(textShadowNode.getEffectiveLineHeight()))); - } - if (textShadowNode.mTextTransform != TextTransform.UNSET) { - ops.add( + applyStyles(textShadowNode, sb, ops, start, end); + } + } + + private static void applyStyles( + ReactBaseTextShadowNode textShadowNode, + SpannableStringBuilder sb, + List ops, + int start, + int end) { + if (textShadowNode.mIsColorSet) { + ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(textShadowNode.mColor))); + } + if (textShadowNode.mIsBackgroundColorSet) { + ops.add( new SetSpanOperation( - start, - end, - new CustomTextTransformSpan(textShadowNode.mTextTransform))); + start, end, new BackgroundColorSpan(textShadowNode.mBackgroundColor))); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (!Float.isNaN(textShadowNode.mLetterSpacing)) { + ops.add(new SetSpanOperation( + start, + end, + new CustomLetterSpacingSpan(textShadowNode.mLetterSpacing))); } - ops.add(new SetSpanOperation(start, end, new ReactTagSpan(textShadowNode.getReactTag()))); } + if (textShadowNode.mFontSize != UNSET) { + ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(textShadowNode.mFontSize))); + } + if (textShadowNode.mFontStyle != UNSET + || textShadowNode.mFontWeight != UNSET + || textShadowNode.mFontFamily != null) { + ops.add( + new SetSpanOperation( + start, + end, + new CustomStyleSpan( + textShadowNode.mFontStyle, + textShadowNode.mFontWeight, + textShadowNode.mFontFamily, + textShadowNode.getThemedContext().getAssets()))); + } + if (textShadowNode.mIsUnderlineTextDecorationSet) { + ops.add(new SetSpanOperation(start, end, new UnderlineSpan())); + } + if (textShadowNode.mIsLineThroughTextDecorationSet) { + ops.add(new SetSpanOperation(start, end, new StrikethroughSpan())); + } + if ( + ( + textShadowNode.mTextShadowOffsetDx != 0 || + textShadowNode.mTextShadowOffsetDy != 0 || + textShadowNode.mTextShadowRadius != 0 + ) && + Color.alpha(textShadowNode.mTextShadowColor) != 0 + ) { + ops.add( + new SetSpanOperation( + start, + end, + new ShadowStyleSpan( + textShadowNode.mTextShadowOffsetDx, + textShadowNode.mTextShadowOffsetDy, + textShadowNode.mTextShadowRadius, + textShadowNode.mTextShadowColor))); + } + if (!Float.isNaN(textShadowNode.getEffectiveLineHeight())) { + ops.add( + new SetSpanOperation( + start, end, new CustomLineHeightSpan(textShadowNode.getEffectiveLineHeight()))); + } + 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()))); } protected int getDefaultFontSize() { @@ -201,12 +210,15 @@ protected static Spannable spannedFromShadowNode( // a new spannable will be wiped out List ops = new ArrayList<>(); - buildSpannedFromShadowNode(textShadowNode, sb, ops); - if (text != null) { + // Handle text that is provided via a prop (e.g. the `value` and `defaultValue` props on + // TextInput). sb.append(text); + applyStyles(textShadowNode, sb, ops, 0, sb.length()); } + buildSpannedFromShadowNode(textShadowNode, sb, ops); + if (textShadowNode.mFontSize == UNSET) { int defaultFontSize = textShadowNode.getDefaultFontSize();