Skip to content

Commit

Permalink
Unset phone and visible-password keyboardType flags on Android
Browse files Browse the repository at this point in the history
Summary:
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

Attempted fix for issue #17248

Added unit tests that cover the affected function and manually repeated the reproduction steps found in the issue.

Note: I had to apply the attached patch file to actually *run* the tests because they were not enabled. I didn't include this in the PR because it seemed like a secondary problem with possible ramifications (see comment near patched line) beyond this issue. For example, other, unrelated tests break when that line is uncommented.
[textInputTestEnable.patch.txt](https://github.com/facebook/react-native/files/1565807/textInputTestEnable.patch.txt)

If I should apply the patch to this PR or re-enable the tests in some other fashion, please let me know and I can do so.

(none)

<!--
Help reviewers and the release process by writing your own release notes

**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

  CATEGORY
[----------]        TYPE
[ CLI      ]   [-------------]      LOCATION
[ DOCS     ]   [ BREAKING    ]   [-------------]
[ GENERAL  ]   [ BUGFIX      ]   [-{Component}-]
[ INTERNAL ]   [ ENHANCEMENT ]   [ {File}      ]
[ IOS      ]   [ FEATURE     ]   [ {Directory} ]   |-----------|
[ ANDROID  ]   [ MINOR       ]   [ {Framework} ] - | {Message} |
[----------]   [-------------]   [-------------]   |-----------|

[CATEGORY] [TYPE] [LOCATION] - MESSAGE

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->

[ANDROID] [BUGFIX] [TextInput] - Fix an issue when swapping to and from the `'visible-password'` or `'phone-pad'` keyboard types.
Closes #17249

Differential Revision: D6713008

Pulled By: hramos

fbshipit-source-id: 85eeb5398748d48e59d33eb86d851fd02d587a31
  • Loading branch information
BrandonWilliamsCS authored and facebook-github-bot committed Jan 12, 2018
1 parent 9024f56 commit 164f6b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
private static final int INPUT_TYPE_KEYBOARD_NUMBERED =
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL |
InputType.TYPE_NUMBER_FLAG_SIGNED;
private static final int PASSWORD_VISIBILITY_FLAG = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &
~InputType.TYPE_TEXT_VARIATION_PASSWORD;
private static final int KEYBOARD_TYPE_FLAGS = INPUT_TYPE_KEYBOARD_NUMBERED |
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS |
InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_PHONE |
PASSWORD_VISIBILITY_FLAG;

private static final String KEYBOARD_TYPE_EMAIL_ADDRESS = "email-address";
private static final String KEYBOARD_TYPE_NUMERIC = "numeric";
Expand Down Expand Up @@ -540,12 +546,13 @@ public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
} else if (KEYBOARD_TYPE_PHONE_PAD.equalsIgnoreCase(keyboardType)) {
flagsToSet = InputType.TYPE_CLASS_PHONE;
} else if (KEYBOARD_TYPE_VISIBLE_PASSWORD.equalsIgnoreCase(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;
}
updateStagedInputTypeFlag(
view,
INPUT_TYPE_KEYBOARD_NUMBERED | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS |
InputType.TYPE_CLASS_TEXT,
KEYBOARD_TYPE_FLAGS,
flagsToSet);
checkPasswordType(view);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,38 @@ public void testNumLines() {
@Test
public void testKeyboardType() {
ReactEditText view = mManager.createViewInstance(mThemedContext);
int numericTypeFlags =
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL |
InputType.TYPE_NUMBER_FLAG_SIGNED;
int emailTypeFlags = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_CLASS_TEXT;
int passwordVisibilityFlag = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &
~InputType.TYPE_TEXT_VARIATION_PASSWORD;

int generalKeyboardTypeFlags = numericTypeFlags |
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS |
InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_PHONE |
passwordVisibilityFlag;

mManager.updateProperties(view, buildStyles());
assertThat(view.getInputType() & InputType.TYPE_CLASS_NUMBER).isZero();
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);

mManager.updateProperties(view, buildStyles("keyboardType", "text"));
assertThat(view.getInputType() & InputType.TYPE_CLASS_NUMBER).isZero();
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);

mManager.updateProperties(view, buildStyles("keyboardType", "numeric"));
assertThat(view.getInputType() & InputType.TYPE_CLASS_NUMBER).isNotZero();
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(numericTypeFlags);

mManager.updateProperties(view, buildStyles("keyboardType", "email-address"));
assertThat(view.getInputType() & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS).isNotZero();
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(emailTypeFlags);

mManager.updateProperties(view, buildStyles("keyboardType", "phone-pad"));
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_PHONE);

mManager.updateProperties(view, buildStyles("keyboardType", "visible-password"));
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(passwordVisibilityFlag);

mManager.updateProperties(view, buildStyles("keyboardType", null));
assertThat(view.getInputType() & InputType.TYPE_CLASS_NUMBER).isZero();
assertThat(view.getInputType() & generalKeyboardTypeFlags).isEqualTo(InputType.TYPE_CLASS_TEXT);
}

@Test
Expand Down

0 comments on commit 164f6b6

Please sign in to comment.