Skip to content

Commit 31bfa40

Browse files
committed
rename android_errorMessage to errorMessageAndroid
Following same implementation used with underlineColorAndroid https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/TextInput/TextInput.js#L470 https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js#L203 While with other components (for example prop android_ripple), we use the android_ prefix to denote platform specific props. facebook#29157 (comment) https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/Pressable/Pressable.js#L177 In the case of TextInput we already have Platform Logic that detects Android/iOS platform. https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/TextInput/TextInput.js#L1268 For this reason TextInput component does not use android_ props and instead uses this naming convention underlineColorAndroid. To be noted that the prop underlineColorAndroid is passed to both iOS and Android version, while other props have platform specific logic for android and iOS. https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/TextInput/TextInput.js#L1334 https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/TextInput/TextInput.js#L1293 Example of a prop that have a specific value on Android and is different from iOS https://github.com/fabriziobertoglio1987/react-native/blob/15810e96d90e18dbd424666338fdec0127d403ed/Libraries/Components/TextInput/TextInput.js#L1271 I decided to follow the same solution used in underlineColorAndroid.
1 parent 97c2dff commit 31bfa40

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

Libraries/Components/TextInput/AndroidTextInputNativeComponent.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ export type NativeProps = $ReadOnly<{|
163163
'off',
164164
>,
165165

166+
/**
167+
* String to be read by screenreaders to indicate an error state. If this value is
168+
* not null, an error will be announced. You can use onChangeText or onBlur to
169+
* detect an error and set this prop. Once the error is gone, set this to null
170+
* to clear the error
171+
*/
172+
errorMessageAndroid?: ?Stringish,
173+
166174
/**
167175
* Sets the return key to the label. Use it instead of `returnKeyType`.
168176
* @platform android
@@ -698,7 +706,7 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
698706
inlineImageLeft: true,
699707
editable: true,
700708
fontVariant: true,
701-
android_errorMessage: true,
709+
errorMessageAndroid: true,
702710
borderBottomRightRadius: true,
703711
borderBottomColor: {process: require('../../StyleSheet/processColor')},
704712
borderRadius: true,

Libraries/Components/TextInput/TextInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ type AndroidProps = $ReadOnly<{|
408408
* detect an error and set this prop. Once the error is gone, set this to null
409409
* to clear the error
410410
*/
411-
android_errorMessage?: ?Stringish,
411+
errorMessageAndroid?: ?Stringish,
412412

413413
importantForAutofill?: ?(
414414
| 'auto'

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ 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 ANDROID_ERROR_MESSAGE = "android_errorMessage";
8887
public static final String FONT_SIZE = "fontSize";
8988
public static final String FONT_WEIGHT = "fontWeight";
9089
public static final String FONT_STYLE = "fontStyle";

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

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

376-
@ReactProp(name = ViewProps.ANDROID_ERROR_MESSAGE)
377-
public void setErrorMessage(ReactEditText view, String error) {
376+
@ReactProp(name = "errorMessageAndroid")
377+
public void setErrorMessage(ReactEditText view, @Nullable String error) {
378378
view.setError(error);
379379
}
380380

@@ -1328,9 +1328,7 @@ public Object updateState(
13281328

13291329
@Nullable
13301330
String errorMessage =
1331-
props.hasKey(ViewProps.ANDROID_ERROR_MESSAGE)
1332-
? props.getString(ViewProps.ANDROID_ERROR_MESSAGE)
1333-
: null;
1331+
props.hasKey("errorMessageAndroid") ? props.getString("errorMessageAndroid") : null;
13341332

13351333
return ReactTextUpdate.buildReactTextUpdateFromState(
13361334
spanned,

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-
android_errorMessage={error}
486+
errorMessageAndroid={error}
487487
onBlur={() => setError('onBlur')}
488488
onEndEditing={() => setError('onEndEditing')}
489489
onChangeText={newText => {

0 commit comments

Comments
 (0)