From 4c92a0b9623719c3d3be03762b9de8aa09ad5772 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 24 Feb 2016 21:13:54 -0800 Subject: [PATCH] Support setText in RCTTextInput Summary: Examples that use defaultValue as part of their declaration (such as those examples under UIExplorerApp's TextInput) were being ignored. This patch supports having text set directly on RCTTextInput and handles it properly. Note that this patch depends on D2962643 and D2964847, without which the TextInput example will look wrong. Differential Revision: D2968002 --- .../com/facebook/react/flat/RCTTextInput.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 67e1d4772..cae296ded 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java @@ -28,10 +28,12 @@ import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.views.text.ReactTextUpdate; +import static com.facebook.react.views.text.ReactTextShadowNode.PROP_TEXT; import static com.facebook.react.views.text.ReactTextShadowNode.UNSET; public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode.MeasureFunction { + @Nullable private String mText; private int mJsEventCount = UNSET; private boolean mPaddingChanged = false; private int mNumberOfLines = UNSET; @@ -122,6 +124,12 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode notifyChanged(true); } + @ReactProp(name = PROP_TEXT) + public void setText(@Nullable String text) { + mText = text; + markUpdated(); + } + @Override public void setPadding(int spacingType, float padding) { if (getPadding().set(spacingType, padding)) { @@ -145,6 +153,13 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode return true; } + protected void performCollectText(SpannableStringBuilder builder) { + if (mText != null) { + builder.append(mText); + } + super.performCollectText(builder); + } + /** * Returns a new CharSequence that includes all the text and styling information to create Layout. */