From b4100ef24681a73d4ac6370c917c2154b36a31af Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 24 Feb 2016 14:21:47 -0800 Subject: [PATCH] Fix spannable flags in RCTVirtualText Summary: The spannable flags for RCTVirtualText were always being set to INCLUSIVE_EXCLUSIVE - this is different than the behavior that is found in ReactTextShadowNode, which sets EXCLUSIVE_INCLUSIVE as the default flag unless the text is at the beginning. This is needed to fix various problems with TextInput, including the handling of empty spans (see also D2962394 which depends on this patch), and making the behavior consistent when styled children of a TextInput are changed. Differential Revision: D2962643 --- .../java/com/facebook/react/flat/RCTVirtualText.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 b30cfb9f7..bcfdeeb4d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java @@ -50,11 +50,17 @@ import com.facebook.react.uimanager.ViewProps; protected void performApplySpans(SpannableStringBuilder builder, int begin, int end) { mFontStylingSpan.freeze(); + // All spans will automatically extend to the right of the text, but not the left - except + // for spans that start at the beginning of the text. + final int flag = begin == 0 ? + Spannable.SPAN_INCLUSIVE_INCLUSIVE : + Spannable.SPAN_EXCLUSIVE_INCLUSIVE; + builder.setSpan( mFontStylingSpan, begin, end, - Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + flag); if (mShadowStyleSpan.getColor() != 0 && mShadowStyleSpan.getRadius() != 0) { mShadowStyleSpan.freeze(); @@ -63,7 +69,7 @@ import com.facebook.react.uimanager.ViewProps; mShadowStyleSpan, begin, end, - Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + flag); } for (int i = 0, childCount = getChildCount(); i < childCount; ++i) {