mirror of
https://github.com/status-im/react-native.git
synced 2025-03-01 09:30:33 +00:00
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:
parent
a9c88bce14
commit
4c92a0b962
@ -28,10 +28,12 @@ import com.facebook.react.uimanager.ViewProps;
|
|||||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||||
import com.facebook.react.views.text.ReactTextUpdate;
|
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;
|
import static com.facebook.react.views.text.ReactTextShadowNode.UNSET;
|
||||||
|
|
||||||
public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode.MeasureFunction {
|
public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode.MeasureFunction {
|
||||||
|
|
||||||
|
@Nullable private String mText;
|
||||||
private int mJsEventCount = UNSET;
|
private int mJsEventCount = UNSET;
|
||||||
private boolean mPaddingChanged = false;
|
private boolean mPaddingChanged = false;
|
||||||
private int mNumberOfLines = UNSET;
|
private int mNumberOfLines = UNSET;
|
||||||
@ -122,6 +124,12 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
|
|||||||
notifyChanged(true);
|
notifyChanged(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = PROP_TEXT)
|
||||||
|
public void setText(@Nullable String text) {
|
||||||
|
mText = text;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPadding(int spacingType, float padding) {
|
public void setPadding(int spacingType, float padding) {
|
||||||
if (getPadding().set(spacingType, padding)) {
|
if (getPadding().set(spacingType, padding)) {
|
||||||
@ -145,6 +153,13 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
|
|||||||
return true;
|
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.
|
* Returns a new CharSequence that includes all the text and styling information to create Layout.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user