Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unset phone and visible-password keyboardType flags on Android #17249

Conversation

BrandonWilliamsCS
Copy link
Contributor

Motivation

Attempted fix for issue #17248

Test Plan

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

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.

Related PRs

(none)

Release Notes

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 17, 2017
@pull-bot
Copy link

pull-bot commented Dec 17, 2017

@facebook-github-bot label Android

Generated by 🚫 dangerJS

@@ -527,6 +527,13 @@ public void setAutoCapitalize(ReactEditText view, int autoCapitalize) {

@ReactProp(name = "keyboardType")
public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
int passwordVisibilityFlag = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this flag is only the visibility bit if I understand correctly? It won't unset the fact that it is a password or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. We wouldn't want to set/unset general password status in keyboardType, only in secureTextEntry.

int keyboardTypeFlags = INPUT_TYPE_KEYBOARD_NUMBERED |
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS |
InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_PHONE |
passwordVisibilityFlag;
int flagsToSet = InputType.TYPE_CLASS_TEXT;
if (KEYBOARD_TYPE_NUMERIC.equalsIgnoreCase(keyboardType)) {
flagsToSet = INPUT_TYPE_KEYBOARD_NUMBERED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit later in this code we set the TYPE_TEXT_VARIATION_VISIBLE_PASSWORD flag, should we just set passwordVisibilityFlag instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. I think it comes down to how the field should behave when keyboardType="visible-password" but secureTextEntry="false". Due to the way Android handles the flags, if we set the flag I called passwordVisibilityFlag without setting the InputType.TYPE_TEXT_VARIATION_PASSWORD flag, it will actually treat it like InputType.TYPE_TEXT_VARIATION_URI.

So three options I see:

  1. Somehow forbid keyboardType="visible-password" with secureTextEntry="false"
  2. Let keyboardType="visible-password" override the secureTextEntry prop (equivalent to the current PR code)
  3. Allow the consumer to set the props inconsistently (probably with a warning) and risk an unexpected InputType.TYPE_TEXT_VARIATION_URI

I should probably leave that decision up to the core maintainers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, let's keep the current behavior (current PR code).

int passwordVisibilityFlag = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &
~InputType.TYPE_TEXT_VARIATION_PASSWORD;

int keyboardTypeFlags = INPUT_TYPE_KEYBOARD_NUMBERED |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this and passwordVisibilityFlag to private static final members in the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, commit incoming.

@janicduplessis
Copy link
Contributor

Thanks for figuring this out, this flag code is pretty hard to understand -_-

@BrandonWilliamsCS
Copy link
Contributor Author

Glad I could help!
I moved the flag values to private static finals and added a comment noting the quirk, so that future contributions can have a little more context into the mess that is coordinating InputType flags between declarative and imperative contexts. Let me know if there's more I can do here.

@BrandonWilliamsCS
Copy link
Contributor Author

Pinging @janicduplessis just to make sure my update didn't get lost in the shuffle of the holidays.

@janicduplessis
Copy link
Contributor

Thanks @BrandonWilliamsCS, will merge after holidays!

@BrandonWilliamsCS
Copy link
Contributor Author

@janicduplessis I don't mean to be a pest, but is this still slated for merge?

@janicduplessis
Copy link
Contributor

Thanks for reminding me, yes!

@facebook-github-bot shipit

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jan 12, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janicduplessis is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@colinux
Copy link

colinux commented Apr 13, 2021

This PR seems to not have been merged.

I'm facing the same issue on RN 64, which should have been fixed by this PR, and I don't see this code in master. Or did I miss something ?

@hikaaam
Copy link

hikaaam commented Dec 8, 2022

this issue still happen react-native v.0.63, keyboardType visible-password make my password visible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants