Skip to content

Commit e41e146

Browse files
JoshuaGrossalloy
authored andcommittedMar 7, 2020
Fix toggling between hidden and visible password
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: #27523 Changelog: [Internal] Reviewed By: mdvacca, rodrigos-facebook Differential Revision: D19527245 fbshipit-source-id: a5ab343c8a0c6a608171dbfa5afc7536ff241826
1 parent ba3815f commit e41e146

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
9696
| InputType.TYPE_CLASS_TEXT
9797
| InputType.TYPE_CLASS_PHONE
9898
| PASSWORD_VISIBILITY_FLAG;
99+
private static final int AUTOCAPITALIZE_FLAGS =
100+
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
101+
| InputType.TYPE_TEXT_FLAG_CAP_WORDS
102+
| InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
99103

100104
private static final String KEYBOARD_TYPE_EMAIL_ADDRESS = "email-address";
101105
private static final String KEYBOARD_TYPE_NUMERIC = "numeric";
@@ -706,17 +710,13 @@ public void setAutoCapitalize(ReactEditText view, Dynamic autoCapitalize) {
706710
}
707711
}
708712

709-
updateStagedInputTypeFlag(
710-
view,
711-
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
712-
| InputType.TYPE_TEXT_FLAG_CAP_WORDS
713-
| InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS,
714-
autoCapitalizeValue);
713+
updateStagedInputTypeFlag(view, AUTOCAPITALIZE_FLAGS, autoCapitalizeValue);
715714
}
716715

717716
@ReactProp(name = "keyboardType")
718717
public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
719718
int flagsToSet = InputType.TYPE_CLASS_TEXT;
719+
boolean unsettingFlagsBreaksAutocomplete = false;
720720
if (KEYBOARD_TYPE_NUMERIC.equalsIgnoreCase(keyboardType)) {
721721
flagsToSet = INPUT_TYPE_KEYBOARD_NUMBERED;
722722
} else if (KEYBOARD_TYPE_NUMBER_PAD.equalsIgnoreCase(keyboardType)) {
@@ -731,12 +731,15 @@ public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
731731
// This will supercede secureTextEntry={false}. If it doesn't, due to the way
732732
// the flags work out, the underlying field will end up a URI-type field.
733733
flagsToSet = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
734-
} else {
735-
// This prevents KEYBOARD_TYPE_FLAGS from being set when the keyboardType is
736-
// default, unsupported or null. Setting of this flag breaks the autoCapitalize functionality.
737-
return;
734+
} else if ((view.getStagedInputType() & AUTOCAPITALIZE_FLAGS) != 0) {
735+
// This prevents KEYBOARD_TYPE_FLAGS from being unset when the keyboardType is
736+
// default, null, or unsupported, and autocapitalize is on.
737+
// Unsetting these flags breaks the autoCapitalize functionality.
738+
unsettingFlagsBreaksAutocomplete = true;
738739
}
739-
updateStagedInputTypeFlag(view, KEYBOARD_TYPE_FLAGS, flagsToSet);
740+
741+
updateStagedInputTypeFlag(
742+
view, (unsettingFlagsBreaksAutocomplete ? 0 : KEYBOARD_TYPE_FLAGS), flagsToSet);
740743
checkPasswordType(view);
741744
}
742745

0 commit comments

Comments
 (0)
Please sign in to comment.