Skip to content

Commit

Permalink
Fix toggling between hidden and visible password
Browse files Browse the repository at this point in the history
Summary:
A previous PR broke toggling between visible and non-visible password (basically once a password field was made visible, future updates to the keyboardType were effectively ignored, so the password would always be visible).

Original PR: facebook#27523

Changelog: [Internal]

Reviewed By: mdvacca, rodrigos-facebook

Differential Revision: D19527245

fbshipit-source-id: a5ab343c8a0c6a608171dbfa5afc7536ff241826
  • Loading branch information
JoshuaGross authored and osdnk committed Mar 9, 2020
1 parent 2b0017b commit 4972ed8
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
| InputType.TYPE_CLASS_TEXT
| InputType.TYPE_CLASS_PHONE
| PASSWORD_VISIBILITY_FLAG;
private static final int AUTOCAPITALIZE_FLAGS =
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
| InputType.TYPE_TEXT_FLAG_CAP_WORDS
| InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;

private static final String KEYBOARD_TYPE_EMAIL_ADDRESS = "email-address";
private static final String KEYBOARD_TYPE_NUMERIC = "numeric";
Expand Down Expand Up @@ -708,17 +712,13 @@ public void setAutoCapitalize(ReactEditText view, Dynamic autoCapitalize) {
}
}

updateStagedInputTypeFlag(
view,
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
| InputType.TYPE_TEXT_FLAG_CAP_WORDS
| InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS,
autoCapitalizeValue);
updateStagedInputTypeFlag(view, AUTOCAPITALIZE_FLAGS, autoCapitalizeValue);
}

@ReactProp(name = "keyboardType")
public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
int flagsToSet = InputType.TYPE_CLASS_TEXT;
boolean unsettingFlagsBreaksAutocomplete = false;
if (KEYBOARD_TYPE_NUMERIC.equalsIgnoreCase(keyboardType)) {
flagsToSet = INPUT_TYPE_KEYBOARD_NUMBERED;
} else if (KEYBOARD_TYPE_NUMBER_PAD.equalsIgnoreCase(keyboardType)) {
Expand All @@ -733,12 +733,15 @@ 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 {
// This prevents KEYBOARD_TYPE_FLAGS from being set when the keyboardType is
// default, unsupported or null. Setting of this flag breaks the autoCapitalize functionality.
return;
} else if ((view.getStagedInputType() & AUTOCAPITALIZE_FLAGS) != 0) {
// This prevents KEYBOARD_TYPE_FLAGS from being unset when the keyboardType is
// default, null, or unsupported, and autocapitalize is on.
// Unsetting these flags breaks the autoCapitalize functionality.
unsettingFlagsBreaksAutocomplete = true;
}
updateStagedInputTypeFlag(view, KEYBOARD_TYPE_FLAGS, flagsToSet);

updateStagedInputTypeFlag(
view, (unsettingFlagsBreaksAutocomplete ? 0 : KEYBOARD_TYPE_FLAGS), flagsToSet);
checkPasswordType(view);
}

Expand Down

0 comments on commit 4972ed8

Please sign in to comment.