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. */