30
30
import android .widget .EditText ;
31
31
import android .widget .TextView ;
32
32
import androidx .annotation .Nullable ;
33
+ import androidx .autofill .HintConstants ;
33
34
import androidx .core .content .ContextCompat ;
34
35
import com .facebook .common .logging .FLog ;
35
36
import com .facebook .infer .annotation .Assertions ;
72
73
import com .facebook .react .views .text .TextTransform ;
73
74
import com .facebook .yoga .YogaConstants ;
74
75
import java .lang .reflect .Field ;
76
+ import java .util .HashMap ;
75
77
import java .util .LinkedList ;
76
78
import java .util .Map ;
77
79
@@ -84,6 +86,51 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
84
86
private static final int [] SPACING_TYPES = {
85
87
Spacing .ALL , Spacing .LEFT , Spacing .RIGHT , Spacing .TOP , Spacing .BOTTOM ,
86
88
};
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
+ };
87
134
88
135
private static final int FOCUS_TEXT_INPUT = 1 ;
89
136
private static final int BLUR_TEXT_INPUT = 2 ;
@@ -659,32 +706,10 @@ public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {
659
706
public void setTextContentType (ReactEditText view , @ Nullable String autoCompleteType ) {
660
707
if (autoCompleteType == null ) {
661
708
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 );
686
709
} else if ("off" .equals (autoCompleteType )) {
687
710
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 ));
688
713
} else {
689
714
throw new JSApplicationIllegalArgumentException (
690
715
"Invalid autoCompleteType: " + autoCompleteType );
0 commit comments