From b300c1979cbe9c71c2b13d0a02217bd4ca2cbeee Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Mon, 11 Jul 2016 13:31:51 -0700 Subject: [PATCH] Support TextDecorationLine in Nodes Summary: Nodes wasn't supporting text decorations to the line (strike through and underline). This patch implements that. Differential Revision: D3512711 --- .../facebook/react/flat/FontStylingSpan.java | 28 +++++++++++++++++++ .../facebook/react/flat/RCTVirtualText.java | 23 +++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FontStylingSpan.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FontStylingSpan.java index 9210e4db5..305920b1d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FontStylingSpan.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FontStylingSpan.java @@ -23,12 +23,16 @@ import android.text.style.MetricAffectingSpan; -1 /* mFontSize */, -1 /* mFontStyle */, -1 /* mFontWeight */, + false /* mHasUnderline */, + false /* mHasStrikeThrough */, null /* mFontFamily */, true /* mFrozen */); // text property private double mTextColor; private int mBackgroundColor; + private boolean mHasUnderline; + private boolean mHasStrikeThrough; // font properties private int mFontSize; @@ -48,6 +52,8 @@ import android.text.style.MetricAffectingSpan; int fontSize, int fontStyle, int fontWeight, + boolean hasUnderline, + boolean hasStrikeThrough, @Nullable String fontFamily, boolean frozen) { mTextColor = textColor; @@ -55,6 +61,8 @@ import android.text.style.MetricAffectingSpan; mFontSize = fontSize; mFontStyle = fontStyle; mFontWeight = fontWeight; + mHasUnderline = hasUnderline; + mHasStrikeThrough = hasStrikeThrough; mFontFamily = fontFamily; mFrozen = frozen; } @@ -66,6 +74,8 @@ import android.text.style.MetricAffectingSpan; mFontSize, mFontStyle, mFontWeight, + mHasUnderline, + mHasStrikeThrough, mFontFamily, false); } @@ -126,6 +136,22 @@ import android.text.style.MetricAffectingSpan; mFontFamily = fontFamily; } + /* package */ boolean hasUnderline() { + return mHasUnderline; + } + + /* package */ void setHasUnderline(boolean hasUnderline) { + mHasUnderline = hasUnderline; + } + + /* package */ boolean hasStrikeThrough() { + return mHasStrikeThrough; + } + + /* package */ void setHasStrikeThrough(boolean hasStrikeThrough) { + mHasStrikeThrough = hasStrikeThrough; + } + @Override public void updateDrawState(TextPaint ds) { if (!Double.isNaN(mTextColor)) { @@ -133,6 +159,8 @@ import android.text.style.MetricAffectingSpan; } ds.bgColor = mBackgroundColor; + ds.setUnderlineText(mHasUnderline); + ds.setStrikeThruText(mHasStrikeThrough); updateMeasureState(ds); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java index f594a1765..d0814a689 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java @@ -172,6 +172,29 @@ import com.facebook.react.uimanager.annotations.ReactProp; } } + @ReactProp(name = ViewProps.TEXT_DECORATION_LINE) + public void setTextDecorationLine(@Nullable String textDecorationLineString) { + boolean isUnderlineTextDecorationSet = false; + boolean isLineThroughTextDecorationSet = false; + if (textDecorationLineString != null) { + for (String textDecorationLineSubString : textDecorationLineString.split(" ")) { + if ("underline".equals(textDecorationLineSubString)) { + isUnderlineTextDecorationSet = true; + } else if ("line-through".equals(textDecorationLineSubString)) { + isLineThroughTextDecorationSet = true; + } + } + } + + if (isUnderlineTextDecorationSet != mFontStylingSpan.hasUnderline() || + isLineThroughTextDecorationSet != mFontStylingSpan.hasStrikeThrough()) { + FontStylingSpan span = getSpan(); + span.setHasUnderline(isUnderlineTextDecorationSet); + span.setHasStrikeThrough(isLineThroughTextDecorationSet); + notifyChanged(true); + } + } + @ReactProp(name = ViewProps.FONT_STYLE) public void setFontStyle(@Nullable String fontStyleString) { final int fontStyle;