Skip to content

Commit

Permalink
Fix secure text entry setting
Browse files Browse the repository at this point in the history
Summary:
We have password components which allow visibility to be toggled by
setting both the keyboardType and secureTextEntry props. The order in
which those updates are executed is determined by iterating a NativeMap
of props, and the iteration order of a NativeMap is implementation
dependent.

With libc++ as our STL, we observe that setSecureTextEntry is called
before setKeyboardType. This results in the following sequence of input
type flag settings when toggling the component to visible and then back
to hidden:

* The field starts out with TYPE_TEXT_VARIATION_PASSWORD (0x80).
* When we toggle to visible, setSecureTextEntry is called with password
  being false, which clears TYPE_TEXT_VARIATION_PASSWORD.
  setKeyboardType is then called with the visible-password keyboard
  type, which sets TYPE_TEXT_VARIATION_VISIBLE_PASSWORD (0x90).
* When we toggle back to hidden, setSecureTextEntry is called with
  password being true, which sets TYPE_TEXT_VARIATION_PASSWORD but
  doesn't clear TYPE_TEXT_VARIATION_VISIBLE_PASSWORD. setKeyboardType is
  then called with the default keyboard type and additionally sets
  TYPE_CLASS_TEXT, but TYPE_TEXT_VARIATION_VISIBLE_PASSWORD remains and
  the password field remains visible.

The fix is to clear TYPE_TEXT_VARIATION_VISIBLE_PASSWORD when
setSecureTextEntry is called with password being true, to ensure the
password gets hidden.

Changelog:
[Android][Fixed] - Fix secure text entry setting to always hide text

Reviewed By: shergin

Differential Revision: D23399174

fbshipit-source-id: a81deec702e768672e2103b76ab50ec728dac229
  • Loading branch information
smeenai authored and facebook-github-bot committed Aug 28, 2020
1 parent 7d44959 commit f193723
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public void setSecureTextEntry(ReactEditText view, boolean password) {
updateStagedInputTypeFlag(
view,
password
? 0
? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
: InputType.TYPE_NUMBER_VARIATION_PASSWORD | InputType.TYPE_TEXT_VARIATION_PASSWORD,
password ? InputType.TYPE_TEXT_VARIATION_PASSWORD : 0);
checkPasswordType(view);
Expand Down

0 comments on commit f193723

Please sign in to comment.