Skip to content

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

Libraries/Components/TextInput/AndroidTextInputNativeComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
698698
inlineImageLeft: true,
699699
editable: true,
700700
fontVariant: true,
701+
android_errorMessage: true,
701702
borderBottomRightRadius: true,
702703
borderBottomColor: {process: require('../../StyleSheet/processColor')},
703704
borderRadius: true,

ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class ViewProps {
8484
public static final String BACKGROUND_COLOR = "backgroundColor";
8585
public static final String FOREGROUND_COLOR = "foregroundColor";
8686
public static final String COLOR = "color";
87-
public static final String ERROR_MESSAGE = "errorMessage";
87+
public static final String ANDROID_ERROR_MESSAGE = "android_errorMessage";
8888
public static final String FONT_SIZE = "fontSize";
8989
public static final String FONT_WEIGHT = "fontWeight";
9090
public static final String FONT_STYLE = "fontStyle";

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class ReactEditText extends AppCompatEditText
105105
private boolean mDetectScrollMovement = false;
106106
private boolean mOnKeyPress = false;
107107
private TextAttributes mTextAttributes;
108+
private @Nullable String mErrorMessage;
108109
private boolean mTypefaceDirty = false;
109110
private @Nullable String mFontFamily = null;
110111
private int mFontWeight = UNSET;
@@ -144,6 +145,7 @@ public ReactEditText(Context context) {
144145
mKeyListener = new InternalKeyListener();
145146
mScrollWatcher = null;
146147
mTextAttributes = new TextAttributes();
148+
mErrorMessage = null;
147149

148150
applyTextAttributes();
149151

@@ -235,6 +237,11 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
235237
return super.onKeyUp(keyCode, event);
236238
}
237239

240+
public void setErrorMessage(String error) {
241+
mErrorMessage = error;
242+
setError(error);
243+
}
244+
238245
@Override
239246
protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
240247
super.onScrollChanged(horiz, vert, oldHoriz, oldVert);
@@ -565,6 +572,9 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
565572
// try to update state if the wrapper is available. Temporarily disable
566573
// to prevent an infinite loop.
567574
getText().replace(0, length(), spannableStringBuilder);
575+
if (mErrorMessage != null && getError() != mErrorMessage) {
576+
setError(mErrorMessage);
577+
}
568578
}
569579
mDisableTextDiffing = false;
570580

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ public void updateExtraData(ReactEditText view, Object extraData) {
372372
}
373373
}
374374

375-
@ReactProp(name = ViewProps.ERROR_MESSAGE)
376-
public void setAndroidErrorMessage(ReactEditText view, String error) {
377-
view.setError(error);
375+
@ReactProp(name = ViewProps.ANDROID_ERROR_MESSAGE)
376+
public void setErrorMessage(ReactEditText view, String error) {
377+
view.setErrorMessage(error);
378378
}
379379

380380
@ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = ViewDefaults.FONT_SIZE_SP)

packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ function ErrorExample(): React.Node {
483483
Type error in the below TextInput to display an error message.
484484
</Text>
485485
<TextInput
486-
errorMessage={error}
486+
android_errorMessage={error}
487487
onBlur={() => setError('onBlur')}
488488
onEndEditing={() => setError('onEndEditing')}
489489
onChangeText={newText => {

0 commit comments

Comments
 (0)