Skip to content

Commit

Permalink
Do not use autofill methods on Android APIs older than Oreo (26)
Browse files Browse the repository at this point in the history
Summary:
Autofill Hints were added in [Android API 26](https://developer.android.com/reference/android/view/View.html#setAutofillHints(java.lang.String...)). Without this runtime check, pre-26 devices will crash.

[Android][Fixed] - Fixes crash on pre-26 Android devices when setting text content type

Reviewed By: lunaleaps

Differential Revision: D14479468

fbshipit-source-id: 238c1efd6aea682a93ecb45e1123aaed6bdcd9e3
  • Loading branch information
hramos authored and grabbou committed Mar 22, 2019
1 parent 3f1d2b0 commit 7263a77
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
private static final int FOCUS_TEXT_INPUT = 1;
private static final int BLUR_TEXT_INPUT = 2;

private static final int INPUT_TYPE_KEYBOARD_NUMBER_PAD = InputType.TYPE_CLASS_NUMBER;
private static final int INPUT_TYPE_KEYBOARD_NUMBER_PAD = InputType.TYPE_CLASS_NUMBER;
private static final int INPUT_TYPE_KEYBOARD_DECIMAL_PAD = INPUT_TYPE_KEYBOARD_NUMBER_PAD |
InputType.TYPE_NUMBER_FLAG_DECIMAL;
private static final int INPUT_TYPE_KEYBOARD_NUMBERED = INPUT_TYPE_KEYBOARD_DECIMAL_PAD |
Expand Down Expand Up @@ -559,6 +559,11 @@ public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {

@ReactProp(name = "autoComplete")
public void setTextContentType(ReactEditText view, @Nullable String autocomplete) {
// Autofill hints were added in Android API 26.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

if (autocomplete == null) {
view.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
} else if ("username".equals(autocomplete)) {
Expand Down

0 comments on commit 7263a77

Please sign in to comment.