Skip to content

Commit

Permalink
Add support to URI keyboard type in Android (#31781)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Adrián Cuesta authored and facebook-github-bot committed Jul 16, 2021
1 parent 2970de9 commit 1465c8f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export type KeyboardType =
| 'phone-pad'
| 'number-pad'
| 'decimal-pad'
| 'url'
// iOS-only
| 'ascii-capable'
| 'numbers-and-punctuation'
| 'url'
| 'name-phone-pad'
| 'twitter'
| 'web-search'
Expand Down Expand Up @@ -244,6 +244,7 @@ export type NativeProps = $ReadOnly<{|
* - `decimal-pad`
* - `email-address`
* - `phone-pad`
* - `url`
*
* *Android Only*
*
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ export type KeyboardType =
| 'phone-pad'
| 'number-pad'
| 'decimal-pad'
| 'url'
// iOS-only
| 'ascii-capable'
| 'numbers-and-punctuation'
| 'url'
| 'name-phone-pad'
| 'twitter'
| 'web-search'
Expand Down Expand Up @@ -501,14 +501,14 @@ export type Props = $ReadOnly<{|
* - `decimal-pad`
* - `email-address`
* - `phone-pad`
* - `url`
*
* *iOS Only*
*
* The following values work on iOS only:
*
* - `ascii-capable`
* - `numbers-and-punctuation`
* - `url`
* - `name-phone-pad`
* - `twitter`
* - `web-search`
Expand Down
4 changes: 2 additions & 2 deletions Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ module.exports = {
* - `decimal-pad`
* - `email-address`
* - `phone-pad`
* - `url`
*
* *iOS Only*
*
* The following values work on iOS only:
*
* - `ascii-capable`
* - `numbers-and-punctuation`
* - `url`
* - `name-phone-pad`
* - `twitter`
* - `web-search`
Expand All @@ -162,10 +162,10 @@ module.exports = {
'numeric',
'phone-pad',
'number-pad',
'url',
// iOS-only
'ascii-capable',
'numbers-and-punctuation',
'url',
'name-phone-pad',
'decimal-pad',
'twitter',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
private static final String KEYBOARD_TYPE_NUMBER_PAD = "number-pad";
private static final String KEYBOARD_TYPE_PHONE_PAD = "phone-pad";
private static final String KEYBOARD_TYPE_VISIBLE_PASSWORD = "visible-password";
private static final String KEYBOARD_TYPE_URI = "url";
private static final InputFilter[] EMPTY_FILTERS = new InputFilter[0];
private static final int UNSET = -1;

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

updateStagedInputTypeFlag(view, InputType.TYPE_MASK_CLASS, flagsToSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void testNumLines() {
public void testKeyboardType() {
ReactEditText view = mManager.createViewInstance(mThemedContext);
int numberPadTypeFlags = InputType.TYPE_CLASS_NUMBER;
int urlTypeFlags = InputType.TYPE_TEXT_VARIATION_URI;
int decimalPadTypeFlags = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
int numericTypeFlags =
InputType.TYPE_CLASS_NUMBER
Expand All @@ -246,6 +247,9 @@ public void testKeyboardType() {
mManager.updateProperties(view, buildStyles("keyboardType", "number-pad"));
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(numberPadTypeFlags);

mManager.updateProperties(view, buildStyles("keyboardType", "url"));
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(urlTypeFlags);

mManager.updateProperties(view, buildStyles("keyboardType", "decimal-pad"));
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(decimalPadTypeFlags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ inline void fromRawValue(const RawValue &value, KeyboardType &result) {
result = KeyboardType::NumberPad;
return;
}
if (string == "url") {
result = KeyboardType::URL;
return;
}
if (string == "decimal-pad") {
result = KeyboardType::DecimalPad;
return;
Expand All @@ -177,10 +181,6 @@ inline void fromRawValue(const RawValue &value, KeyboardType &result) {
result = KeyboardType::NumbersAndPunctuation;
return;
}
if (string == "url") {
result = KeyboardType::URL;
return;
}
if (string == "name-phone-pad") {
result = KeyboardType::NamePhonePad;
return;
Expand Down

0 comments on commit 1465c8f

Please sign in to comment.