Skip to content

Commit 1465c8f

Browse files
Adrián Cuestafacebook-github-bot
Adrián Cuesta
authored andcommitted
Add support to URI keyboard type in Android (#31781)
Summary: Android react-native `TextInput` component does nothing if prop `keyboardType` is `url` value. This PR solves that problem. ## Changelog [Android] [Added] - Add support to URI keyboard type in Android Pull Request resolved: #31781 Test Plan: Before change: {F630980679} After Change: {F630986399} Reviewed By: lunaleaps Differential Revision: D29517822 Pulled By: sshic fbshipit-source-id: 1bda29584a3799570f34e772b5589b59ac80c524
1 parent 2970de9 commit 1465c8f

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

Libraries/Components/TextInput/AndroidTextInputNativeComponent.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export type KeyboardType =
3737
| 'phone-pad'
3838
| 'number-pad'
3939
| 'decimal-pad'
40+
| 'url'
4041
// iOS-only
4142
| 'ascii-capable'
4243
| 'numbers-and-punctuation'
43-
| 'url'
4444
| 'name-phone-pad'
4545
| 'twitter'
4646
| 'web-search'
@@ -244,6 +244,7 @@ export type NativeProps = $ReadOnly<{|
244244
* - `decimal-pad`
245245
* - `email-address`
246246
* - `phone-pad`
247+
* - `url`
247248
*
248249
* *Android Only*
249250
*

Libraries/Components/TextInput/TextInput.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ export type KeyboardType =
146146
| 'phone-pad'
147147
| 'number-pad'
148148
| 'decimal-pad'
149+
| 'url'
149150
// iOS-only
150151
| 'ascii-capable'
151152
| 'numbers-and-punctuation'
152-
| 'url'
153153
| 'name-phone-pad'
154154
| 'twitter'
155155
| 'web-search'
@@ -501,14 +501,14 @@ export type Props = $ReadOnly<{|
501501
* - `decimal-pad`
502502
* - `email-address`
503503
* - `phone-pad`
504+
* - `url`
504505
*
505506
* *iOS Only*
506507
*
507508
* The following values work on iOS only:
508509
*
509510
* - `ascii-capable`
510511
* - `numbers-and-punctuation`
511-
* - `url`
512512
* - `name-phone-pad`
513513
* - `twitter`
514514
* - `web-search`

Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ module.exports = {
136136
* - `decimal-pad`
137137
* - `email-address`
138138
* - `phone-pad`
139+
* - `url`
139140
*
140141
* *iOS Only*
141142
*
142143
* The following values work on iOS only:
143144
*
144145
* - `ascii-capable`
145146
* - `numbers-and-punctuation`
146-
* - `url`
147147
* - `name-phone-pad`
148148
* - `twitter`
149149
* - `web-search`
@@ -162,10 +162,10 @@ module.exports = {
162162
'numeric',
163163
'phone-pad',
164164
'number-pad',
165+
'url',
165166
// iOS-only
166167
'ascii-capable',
167168
'numbers-and-punctuation',
168-
'url',
169169
'name-phone-pad',
170170
'decimal-pad',
171171
'twitter',

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

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
108108
private static final String KEYBOARD_TYPE_NUMBER_PAD = "number-pad";
109109
private static final String KEYBOARD_TYPE_PHONE_PAD = "phone-pad";
110110
private static final String KEYBOARD_TYPE_VISIBLE_PASSWORD = "visible-password";
111+
private static final String KEYBOARD_TYPE_URI = "url";
111112
private static final InputFilter[] EMPTY_FILTERS = new InputFilter[0];
112113
private static final int UNSET = -1;
113114

@@ -774,6 +775,8 @@ public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
774775
// This will supercede secureTextEntry={false}. If it doesn't, due to the way
775776
// the flags work out, the underlying field will end up a URI-type field.
776777
flagsToSet = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
778+
} else if (KEYBOARD_TYPE_URI.equalsIgnoreCase(keyboardType)) {
779+
flagsToSet = InputType.TYPE_TEXT_VARIATION_URI;
777780
}
778781

779782
updateStagedInputTypeFlag(view, InputType.TYPE_MASK_CLASS, flagsToSet);

ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public void testNumLines() {
221221
public void testKeyboardType() {
222222
ReactEditText view = mManager.createViewInstance(mThemedContext);
223223
int numberPadTypeFlags = InputType.TYPE_CLASS_NUMBER;
224+
int urlTypeFlags = InputType.TYPE_TEXT_VARIATION_URI;
224225
int decimalPadTypeFlags = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
225226
int numericTypeFlags =
226227
InputType.TYPE_CLASS_NUMBER
@@ -246,6 +247,9 @@ public void testKeyboardType() {
246247
mManager.updateProperties(view, buildStyles("keyboardType", "number-pad"));
247248
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(numberPadTypeFlags);
248249

250+
mManager.updateProperties(view, buildStyles("keyboardType", "url"));
251+
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(urlTypeFlags);
252+
249253
mManager.updateProperties(view, buildStyles("keyboardType", "decimal-pad"));
250254
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(decimalPadTypeFlags);
251255

ReactCommon/react/renderer/components/textinput/iostextinput/conversions.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ inline void fromRawValue(const RawValue &value, KeyboardType &result) {
163163
result = KeyboardType::NumberPad;
164164
return;
165165
}
166+
if (string == "url") {
167+
result = KeyboardType::URL;
168+
return;
169+
}
166170
if (string == "decimal-pad") {
167171
result = KeyboardType::DecimalPad;
168172
return;
@@ -177,10 +181,6 @@ inline void fromRawValue(const RawValue &value, KeyboardType &result) {
177181
result = KeyboardType::NumbersAndPunctuation;
178182
return;
179183
}
180-
if (string == "url") {
181-
result = KeyboardType::URL;
182-
return;
183-
}
184184
if (string == "name-phone-pad") {
185185
result = KeyboardType::NamePhonePad;
186186
return;

0 commit comments

Comments
 (0)