Skip to content

Commit 0a17a4f

Browse files
Michael Yoon (LAX)facebook-github-bot
Michael Yoon (LAX)
authored andcommitted
fix android TextInput transitions
Summary: On Android, when changing the props on TextInput component, there are cases where behavior is incorrect. ex: there were two other PR requests to fix the following issues: 1) TextInput doesnt respect the autoCapitalize prop when keyboardType is set to "default" 2) Password visibility is broken But those PRs ended up breaking a transition from phone-pad to default Root cause - The issue is that the bits that Android defines to store the InputType flags are reused. - For example, the previous issue: TYPE_TEXT_FLAG_CAP_WORDS and TYPE_NUMBER_FLAG_DECIMAL are both using 0x00002000 bit. So when switching input types from phone-pad to default (text), it is not known if this bit should be cleared. It could have been set for capitalize or for indicating the num pad should be generic. the solution is to always unset the TYPE_CLASS flags before setting the keyboardType so the user has the correct keyboard. Changelog: [Fixed] TextInput transition from phone-pad to default Reviewed By: JoshuaGross Differential Revision: D20263334 fbshipit-source-id: 0b283fbd6314bf10b90f760917447d2439aaa147
1 parent f1a9ca0 commit 0a17a4f

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
9797
INPUT_TYPE_KEYBOARD_DECIMAL_PAD | InputType.TYPE_NUMBER_FLAG_SIGNED;
9898
private static final int PASSWORD_VISIBILITY_FLAG =
9999
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD & ~InputType.TYPE_TEXT_VARIATION_PASSWORD;
100-
private static final int KEYBOARD_TYPE_FLAGS =
101-
INPUT_TYPE_KEYBOARD_NUMBERED
102-
| InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
103-
| InputType.TYPE_CLASS_TEXT
104-
| InputType.TYPE_CLASS_PHONE
105-
| PASSWORD_VISIBILITY_FLAG;
106100
private static final int AUTOCAPITALIZE_FLAGS =
107101
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
108102
| InputType.TYPE_TEXT_FLAG_CAP_WORDS
@@ -731,7 +725,6 @@ public void setAutoCapitalize(ReactEditText view, Dynamic autoCapitalize) {
731725
@ReactProp(name = "keyboardType")
732726
public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
733727
int flagsToSet = InputType.TYPE_CLASS_TEXT;
734-
boolean unsettingFlagsBreaksAutocomplete = false;
735728
if (KEYBOARD_TYPE_NUMERIC.equalsIgnoreCase(keyboardType)) {
736729
flagsToSet = INPUT_TYPE_KEYBOARD_NUMBERED;
737730
} else if (KEYBOARD_TYPE_NUMBER_PAD.equalsIgnoreCase(keyboardType)) {
@@ -746,15 +739,9 @@ public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) {
746739
// This will supercede secureTextEntry={false}. If it doesn't, due to the way
747740
// the flags work out, the underlying field will end up a URI-type field.
748741
flagsToSet = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
749-
} else if ((view.getStagedInputType() & AUTOCAPITALIZE_FLAGS) != 0) {
750-
// This prevents KEYBOARD_TYPE_FLAGS from being unset when the keyboardType is
751-
// default, null, or unsupported, and autocapitalize is on.
752-
// Unsetting these flags breaks the autoCapitalize functionality.
753-
unsettingFlagsBreaksAutocomplete = true;
754742
}
755743

756-
updateStagedInputTypeFlag(
757-
view, (unsettingFlagsBreaksAutocomplete ? 0 : KEYBOARD_TYPE_FLAGS), flagsToSet);
744+
updateStagedInputTypeFlag(view, InputType.TYPE_MASK_CLASS, flagsToSet);
758745
checkPasswordType(view);
759746
}
760747

0 commit comments

Comments
 (0)