Skip to content

Commit d9e0ea7

Browse files
safaiyehfacebook-github-bot
authored andcommitted
Migrate to androidx.autofill.HintConstants & Support all constant types (#28008)
Summary: Fix for #27952. Noticed more than just `AUTOFILL_HINT_NEW_PASSWORD` were missing, this PR will support every `AUTOFILL_HINT_*` type. ## Changelog [Android] [Added] - Added all autofill types to TextEdit Pull Request resolved: #28008 Reviewed By: sturmen Differential Revision: D29766235 Pulled By: mdvacca fbshipit-source-id: d5171aef8092d37716fddcb6f3443637a4af8481
1 parent 48ba8df commit d9e0ea7

File tree

6 files changed

+96
-24
lines changed

6 files changed

+96
-24
lines changed

Libraries/Components/TextInput/TextInput.js

+24
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,42 @@ type AndroidProps = $ReadOnly<{|
332332
* @platform android
333333
*/
334334
autoCompleteType?: ?(
335+
| 'birthdate-day'
336+
| 'birthdate-full'
337+
| 'birthdate-month'
338+
| 'birthdate-year'
335339
| 'cc-csc'
336340
| 'cc-exp'
341+
| 'cc-exp-day'
337342
| 'cc-exp-month'
338343
| 'cc-exp-year'
339344
| 'cc-number'
340345
| 'email'
346+
| 'gender'
341347
| 'name'
348+
| 'name-family'
349+
| 'name-given'
350+
| 'name-middle'
351+
| 'name-middle-initial'
352+
| 'name-prefix'
353+
| 'name-suffix'
342354
| 'password'
355+
| 'password-new'
356+
| 'postal-address'
357+
| 'postal-address-country'
358+
| 'postal-address-extended'
359+
| 'postal-address-extended-postal-code'
360+
| 'postal-address-locality'
361+
| 'postal-address-region'
343362
| 'postal-code'
344363
| 'street-address'
364+
| 'sms-otp'
345365
| 'tel'
366+
| 'tel-country-code'
367+
| 'tel-national'
368+
| 'tel-device'
346369
| 'username'
370+
| 'username-new'
347371
| 'off'
348372
),
349373

ReactAndroid/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ dependencies {
500500
api("com.facebook.yoga:proguard-annotations:1.19.0")
501501
api("javax.inject:javax.inject:1")
502502
api("androidx.appcompat:appcompat:1.0.2")
503+
api("androidx.autofill:autofill:1.1.0")
503504
api("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
504505
api("com.facebook.fresco:fresco:${FRESCO_VERSION}")
505506
api("com.facebook.fresco:imagepipeline-okhttp3:${FRESCO_VERSION}")

ReactAndroid/src/main/java/com/facebook/react/BUCK

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rn_android_library(
1313
react_native_dep("third-party/android/androidx:fragment"),
1414
react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
1515
react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
16+
react_native_dep("third-party/android/androidx:autofill"),
1617
],
1718
visibility = [
1819
"PUBLIC",

ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rn_android_library(
1515
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
1616
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
1717
react_native_dep("third-party/java/jsr-305:jsr-305"),
18+
react_native_dep("third-party/android/androidx:autofill"),
1819
react_native_target("java/com/facebook/react/bridge:bridge"),
1920
react_native_target("java/com/facebook/react/common:common"),
2021
react_native_target("java/com/facebook/react/module/annotations:annotations"),

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

+49-24
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.widget.EditText;
3131
import android.widget.TextView;
3232
import androidx.annotation.Nullable;
33+
import androidx.autofill.HintConstants;
3334
import androidx.core.content.ContextCompat;
3435
import com.facebook.common.logging.FLog;
3536
import com.facebook.infer.annotation.Assertions;
@@ -72,6 +73,7 @@
7273
import com.facebook.react.views.text.TextTransform;
7374
import com.facebook.yoga.YogaConstants;
7475
import java.lang.reflect.Field;
76+
import java.util.HashMap;
7577
import java.util.LinkedList;
7678
import java.util.Map;
7779

@@ -84,6 +86,51 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
8486
private static final int[] SPACING_TYPES = {
8587
Spacing.ALL, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, Spacing.BOTTOM,
8688
};
89+
private static final Map<String, String> REACT_PROPS_AUTOFILL_HINTS_MAP =
90+
new HashMap<String, String>() {
91+
{
92+
put("birthdate-day", HintConstants.AUTOFILL_HINT_BIRTH_DATE_DAY);
93+
put("birthdate-full", HintConstants.AUTOFILL_HINT_BIRTH_DATE_FULL);
94+
put("birthdate-month", HintConstants.AUTOFILL_HINT_BIRTH_DATE_MONTH);
95+
put("birthdate-year", HintConstants.AUTOFILL_HINT_BIRTH_DATE_YEAR);
96+
put("cc-csc", HintConstants.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE);
97+
put("cc-exp", HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE);
98+
put("cc-exp-day", HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY);
99+
put("cc-exp-month", HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH);
100+
put("cc-exp-year", HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR);
101+
put("cc-number", HintConstants.AUTOFILL_HINT_CREDIT_CARD_NUMBER);
102+
put("email", HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS);
103+
put("gender", HintConstants.AUTOFILL_HINT_GENDER);
104+
put("name", HintConstants.AUTOFILL_HINT_PERSON_NAME);
105+
put("name-family", HintConstants.AUTOFILL_HINT_PERSON_NAME_FAMILY);
106+
put("name-given", HintConstants.AUTOFILL_HINT_PERSON_NAME_GIVEN);
107+
put("name-middle", HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE);
108+
put("name-middle-initial", HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL);
109+
put("name-prefix", HintConstants.AUTOFILL_HINT_PERSON_NAME_PREFIX);
110+
put("name-suffix", HintConstants.AUTOFILL_HINT_PERSON_NAME_SUFFIX);
111+
put("password", HintConstants.AUTOFILL_HINT_PASSWORD);
112+
put("password-new", HintConstants.AUTOFILL_HINT_NEW_PASSWORD);
113+
put("postal-address", HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS);
114+
put("postal-address-country", HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY);
115+
put(
116+
"postal-address-extended",
117+
HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS);
118+
put(
119+
"postal-address-extended-postal-code",
120+
HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE);
121+
put("postal-address-locality", HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY);
122+
put("postal-address-region", HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_REGION);
123+
put("postal-code", HintConstants.AUTOFILL_HINT_POSTAL_CODE);
124+
put("street-address", HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS);
125+
put("sms-otp", HintConstants.AUTOFILL_HINT_SMS_OTP);
126+
put("tel", HintConstants.AUTOFILL_HINT_PHONE_NUMBER);
127+
put("tel-country-code", HintConstants.AUTOFILL_HINT_PHONE_COUNTRY_CODE);
128+
put("tel-national", HintConstants.AUTOFILL_HINT_PHONE_NATIONAL);
129+
put("tel-device", HintConstants.AUTOFILL_HINT_PHONE_NUMBER_DEVICE);
130+
put("username", HintConstants.AUTOFILL_HINT_USERNAME);
131+
put("username-new", HintConstants.AUTOFILL_HINT_NEW_USERNAME);
132+
}
133+
};
87134

88135
private static final int FOCUS_TEXT_INPUT = 1;
89136
private static final int BLUR_TEXT_INPUT = 2;
@@ -659,32 +706,10 @@ public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {
659706
public void setTextContentType(ReactEditText view, @Nullable String autoCompleteType) {
660707
if (autoCompleteType == null) {
661708
setImportantForAutofill(view, View.IMPORTANT_FOR_AUTOFILL_NO);
662-
} else if ("username".equals(autoCompleteType)) {
663-
setAutofillHints(view, View.AUTOFILL_HINT_USERNAME);
664-
} else if ("password".equals(autoCompleteType)) {
665-
setAutofillHints(view, View.AUTOFILL_HINT_PASSWORD);
666-
} else if ("email".equals(autoCompleteType)) {
667-
setAutofillHints(view, View.AUTOFILL_HINT_EMAIL_ADDRESS);
668-
} else if ("name".equals(autoCompleteType)) {
669-
setAutofillHints(view, View.AUTOFILL_HINT_NAME);
670-
} else if ("tel".equals(autoCompleteType)) {
671-
setAutofillHints(view, View.AUTOFILL_HINT_PHONE);
672-
} else if ("street-address".equals(autoCompleteType)) {
673-
setAutofillHints(view, View.AUTOFILL_HINT_POSTAL_ADDRESS);
674-
} else if ("postal-code".equals(autoCompleteType)) {
675-
setAutofillHints(view, View.AUTOFILL_HINT_POSTAL_CODE);
676-
} else if ("cc-number".equals(autoCompleteType)) {
677-
setAutofillHints(view, View.AUTOFILL_HINT_CREDIT_CARD_NUMBER);
678-
} else if ("cc-csc".equals(autoCompleteType)) {
679-
setAutofillHints(view, View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE);
680-
} else if ("cc-exp".equals(autoCompleteType)) {
681-
setAutofillHints(view, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE);
682-
} else if ("cc-exp-month".equals(autoCompleteType)) {
683-
setAutofillHints(view, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH);
684-
} else if ("cc-exp-year".equals(autoCompleteType)) {
685-
setAutofillHints(view, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR);
686709
} else if ("off".equals(autoCompleteType)) {
687710
setImportantForAutofill(view, View.IMPORTANT_FOR_AUTOFILL_NO);
711+
} else if (REACT_PROPS_AUTOFILL_HINTS_MAP.containsKey(autoCompleteType)) {
712+
setAutofillHints(view, REACT_PROPS_AUTOFILL_HINTS_MAP.get(autoCompleteType));
688713
} else {
689714
throw new JSApplicationIllegalArgumentException(
690715
"Invalid autoCompleteType: " + autoCompleteType);

ReactAndroid/src/main/third-party/android/androidx/BUCK

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ fb_native.android_library(
3232
],
3333
)
3434

35+
fb_native.android_library(
36+
name = "autofill",
37+
visibility = ["PUBLIC"],
38+
exported_deps = [
39+
":autofill-binary",
40+
":core",
41+
],
42+
)
43+
3544
fb_native.android_library(
3645
name = "collection",
3746
visibility = ["PUBLIC"],
@@ -342,6 +351,11 @@ fb_native.android_prebuilt_aar(
342351
aar = ":asynclayoutinflater-binary-aar",
343352
)
344353

354+
fb_native.android_prebuilt_aar(
355+
name = "autofill-binary",
356+
aar = ":autofill-binary-aar",
357+
)
358+
345359
fb_native.prebuilt_jar(
346360
name = "collection-binary",
347361
binary_jar = ":collection-binary.jar",
@@ -501,6 +515,12 @@ fb_native.remote_file(
501515
url = "mvn:androidx.asynclayoutinflater:asynclayoutinflater:aar:1.0.0",
502516
)
503517

518+
fb_native.remote_file(
519+
name = "autofill-binary-aar",
520+
sha1 = "d9cdaa22b9c373ba75a35dcc33ee8871543164e5",
521+
url = "mvn:androidx.autofill:autofill:aar:1.1.0",
522+
)
523+
504524
fb_native.remote_file(
505525
name = "collection-binary.jar",
506526
sha1 = "42858b26cafdaa69b6149f45dfc2894007bc2c7a",

0 commit comments

Comments
 (0)