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
This commit is contained in:
Ahmed El-Helw 2016-02-24 21:13:54 -08:00
parent a9c88bce14
commit 4c92a0b962
1 changed files with 15 additions and 0 deletions

View File

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