From 827989f5724d296304fc0431d37bceb48eb23606 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 24 Feb 2016 14:21:48 -0800 Subject: [PATCH] Fix TextInput text color not applying Summary: Setting the color for a TextInput with nodes was broken. The text color was not being applied due to an optimization that prevented setting spans if begin and end were the same (which is the case for an empty TextInput). This patch depends on D2962643. Differential Revision: D2962394 --- .../facebook/react/flat/FlatTextShadowNode.java | 14 +++++++++++++- .../java/com/facebook/react/flat/RCTTextInput.java | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatTextShadowNode.java index 4432a78d5..883c667a9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatTextShadowNode.java @@ -52,12 +52,24 @@ import com.facebook.react.uimanager.ReactShadowNode; mTextEnd = builder.length(); } + /** + * Whether or not to allow empty spans to be set + * This is used to bypass an optimization in {@code applySpans} that skips applying spans if + * there is no text (since, for TextInput, for example, we want to apply the span even if there + * is no text so that newly typed text gets styled properly). + * + * @return a boolean representing whether or not we should allow empty spans + */ + /* package */ boolean shouldAllowEmptySpans() { + return false; + } + /** * Recursively visits FlatTextShadowNode and its children, * applying spans to SpannableStringBuilder. */ /* package */ final void applySpans(SpannableStringBuilder builder) { - if (mTextBegin != mTextEnd) { + if (mTextBegin != mTextEnd || shouldAllowEmptySpans()) { performApplySpans(builder, mTextBegin, mTextEnd); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java index 6050a0c4f..67e1d4772 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java @@ -140,6 +140,11 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode mPaddingChanged = false; } + @Override + boolean shouldAllowEmptySpans() { + return true; + } + /** * Returns a new CharSequence that includes all the text and styling information to create Layout. */