mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-12 22:39:06 +08:00
Added support for textDecorationLine style prop on Android
Summary:As suggested by kmagiera in #3819, I've implemented `textDecorationLine` style for Android in `ReactTextShadowNode` using span operations so we can support nested Text components.  Closes https://github.com/facebook/react-native/pull/5105 Differential Revision: D3167756 Pulled By: andreicoman11 fb-gh-sync-id: 122701a53d50f47f89b49e1f343c97db5fa2323d fbshipit-source-id: 122701a53d50f47f89b49e1f343c97db5fa2323d
This commit is contained in:
committed by
Facebook Github Bot 9
parent
eac617d6ee
commit
2039be9d32
@@ -22,6 +22,8 @@ import android.os.Build;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.AbsoluteSizeSpan;
|
||||
import android.text.style.StrikethroughSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Choreographer;
|
||||
import android.widget.TextView;
|
||||
@@ -279,6 +281,60 @@ public class ReactTextTest {
|
||||
assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextDecorationLineUnderlineApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
|
||||
StrikethroughSpan[] strikeThroughSpans =
|
||||
text.getSpans(0, text.length(), StrikethroughSpan.class);
|
||||
assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
|
||||
assertThat(strikeThroughSpans).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextDecorationLineLineThroughApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
UnderlineSpan[] underlineSpans =
|
||||
text.getSpans(0, text.length(), UnderlineSpan.class);
|
||||
StrikethroughSpan strikeThroughSpan =
|
||||
getSingleSpan(textView, StrikethroughSpan.class);
|
||||
assertThat(underlineSpans).hasSize(0);
|
||||
assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextDecorationLineUnderlineLineThroughApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
UnderlineSpan underlineSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
|
||||
StrikethroughSpan strikeThroughSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
|
||||
assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
|
||||
assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackgroundColorStyleApplied() {
|
||||
UIManagerModule uiManager = getUIManagerModule();
|
||||
|
||||
Reference in New Issue
Block a user