Android autofill: bump to 1.3.0 and add extended hints (#56105)

Summary:
This change expands Android `TextInput` autofill support by aligning React Native with newer AndroidX autofill APIs and exposing additional `autoComplete` values backed by official `androidx.autofill.HintConstants`.

What changed:
- Bumped AndroidX Autofill dependency from `1.1.0` to `1.3.0`.
- Added Android native mappings in `ReactTextInputManager` for:
  - `2fa-app-otp`
  - `email-otp`
  - `wifi-password`
  - `upi-vpa`
  - `postal-address-unit`
  - `postal-address-dependent-locality`
  - `promo-code`
  - `flight-number`
  - `flight-confirmation-code`
  - `gift-card-number`
  - `gift-card-pin`
  - `loyalty-account-number`

- Updated public `TextInput` type/docs surfaces (`Flow`, `TypeScript`, and Android native component props) to include the new Android values.
- Added Android unit test coverage for the extended hint mappings.
- Added RNTester Android examples for the new `autoComplete` values.

## Changelog:

[ANDROID] [ADDED] - Add extended Android `TextInput` `autoComplete` autofill hint support and bump `androidx.autofill` to `1.3.0`.

Pull Request resolved: https://github.com/facebook/react-native/pull/56105

Test Plan:
Ran Android unit tests locally:

```bash
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.views.textinput.ReactTextInputPropertyTest
```

Run `rn-tester`
<img width="473" height="864" alt="image" src="https://github.com/user-attachments/assets/21b779d9-b485-47e9-809b-d9917e12b472" />

Reviewed By: cortinico, javache

Differential Revision: D96952637

Pulled By: NickGerleman

fbshipit-source-id: e01c99bfa4411219a73fb586b873b1f86ea28122
This commit is contained in:
Radek Czemerys authored and meta-codesync[bot] committed 2026-03-23 14:49:30 -07:00
1 parent b1e2e5a68e
commit ac598aff2b
8 files changed
+176 -4

No files matched your search

@@ -90,8 +90,15 @@ export type AndroidTextInputNativeProps = Readonly<{
* - `cc-exp-month`
* - `cc-exp-year`
* - `cc-number`
* - `2fa-app-otp`
* - `email`
* - `email-otp`
* - `flight-confirmation-code`
* - `flight-number`
* - `gender`
* - `gift-card-number`
* - `gift-card-pin`
* - `loyalty-account-number`
* - `name`
* - `name-family`
* - `name-given`
@@ -103,17 +110,22 @@ export type AndroidTextInputNativeProps = Readonly<{
* - `password-new`
* - `postal-address`
* - `postal-address-country`
* - `postal-address-dependent-locality`
* - `postal-address-extended`
* - `postal-address-extended-postal-code`
* - `postal-address-locality`
* - `postal-address-region`
* - `postal-address-unit`
* - `postal-code`
* - `promo-code`
* - `street-address`
* - `sms-otp`
* - `tel`
* - `tel-country-code`
* - `tel-national`
* - `tel-device`
* - `upi-vpa`
* - `wifi-password`
* - `username`
* - `username-new`
* - `off`
@@ -121,6 +133,7 @@ export type AndroidTextInputNativeProps = Readonly<{
* @platform android
*/
autoComplete?: WithDefault<
| '2fa-app-otp'
| 'birthdate-day'
| 'birthdate-full'
| 'birthdate-month'
@@ -132,7 +145,13 @@ export type AndroidTextInputNativeProps = Readonly<{
| 'cc-exp-year'
| 'cc-number'
| 'email'
| 'email-otp'
| 'flight-confirmation-code'
| 'flight-number'
| 'gender'
| 'gift-card-number'
| 'gift-card-pin'
| 'loyalty-account-number'
| 'name'
| 'name-family'
| 'name-given'
@@ -144,17 +163,22 @@ export type AndroidTextInputNativeProps = Readonly<{
| 'password-new'
| 'postal-address'
| 'postal-address-country'
| 'postal-address-dependent-locality'
| 'postal-address-extended'
| 'postal-address-extended-postal-code'
| 'postal-address-locality'
| 'postal-address-region'
| 'postal-address-unit'
| 'postal-code'
| 'promo-code'
| 'street-address'
| 'sms-otp'
| 'tel'
| 'tel-country-code'
| 'tel-national'
| 'tel-device'
| 'upi-vpa'
| 'wifi-password'
| 'username'
| 'username-new'
| 'off',
@@ -632,7 +632,14 @@ export interface TextInputProps
* - `cc-exp-day`
* - `cc-exp-month`
* - `cc-exp-year`
* - `2fa-app-otp`
* - `email-otp`
* - `flight-confirmation-code`
* - `flight-number`
* - `gender`
* - `gift-card-number`
* - `gift-card-pin`
* - `loyalty-account-number`
* - `name-family`
* - `name-given`
* - `name-middle`
@@ -643,17 +650,23 @@ export interface TextInputProps
* - `password-new`
* - `postal-address`
* - `postal-address-country`
* - `postal-address-dependent-locality`
* - `postal-address-extended`
* - `postal-address-extended-postal-code`
* - `postal-address-locality`
* - `postal-address-region`
* - `postal-address-unit`
* - `promo-code`
* - `sms-otp`
* - `tel-country-code`
* - `tel-national`
* - `tel-device`
* - `upi-vpa`
* - `wifi-password`
* - `username-new`
*/
autoComplete?:
| '2fa-app-otp'
| 'additional-name'
| 'address-line1'
| 'address-line2'
@@ -675,11 +688,17 @@ export interface TextInputProps
| 'country'
| 'current-password'
| 'email'
| 'email-otp'
| 'flight-confirmation-code'
| 'flight-number'
| 'family-name'
| 'gender'
| 'gift-card-number'
| 'gift-card-pin'
| 'given-name'
| 'honorific-prefix'
| 'honorific-suffix'
| 'loyalty-account-number'
| 'name'
| 'name-family'
| 'name-given'
@@ -696,18 +715,23 @@ export interface TextInputProps
| 'password-new'
| 'postal-address'
| 'postal-address-country'
| 'postal-address-dependent-locality'
| 'postal-address-extended'
| 'postal-address-extended-postal-code'
| 'postal-address-locality'
| 'postal-address-region'
| 'postal-address-unit'
| 'postal-code'
| 'promo-code'
| 'street-address'
| 'sms-otp'
| 'tel'
| 'tel-country-code'
| 'tel-national'
| 'tel-device'
| 'upi-vpa'
| 'url'
| 'wifi-password'
| 'username'
| 'username-new'
| 'off'
@@ -594,7 +594,14 @@ type TextInputBaseProps = Readonly<{
*
* The following values work on Android only:
*
* - `2fa-app-otp`
* - `email-otp`
* - `flight-confirmation-code`
* - `flight-number`
* - `gender`
* - `gift-card-number`
* - `gift-card-pin`
* - `loyalty-account-number`
* - `name-family`
* - `name-given`
* - `name-middle`
@@ -605,17 +612,23 @@ type TextInputBaseProps = Readonly<{
* - `password-new`
* - `postal-address`
* - `postal-address-country`
* - `postal-address-dependent-locality`
* - `postal-address-extended`
* - `postal-address-extended-postal-code`
* - `postal-address-locality`
* - `postal-address-region`
* - `postal-address-unit`
* - `promo-code`
* - `sms-otp`
* - `tel-country-code`
* - `tel-national`
* - `tel-device`
* - `upi-vpa`
* - `wifi-password`
* - `username-new`
*/
autoComplete?: ?(
| '2fa-app-otp'
| 'additional-name'
| 'address-line1'
| 'address-line2'
@@ -637,11 +650,17 @@ type TextInputBaseProps = Readonly<{
| 'country'
| 'current-password'
| 'email'
| 'email-otp'
| 'flight-confirmation-code'
| 'flight-number'
| 'family-name'
| 'gender'
| 'gift-card-number'
| 'gift-card-pin'
| 'given-name'
| 'honorific-prefix'
| 'honorific-suffix'
| 'loyalty-account-number'
| 'name'
| 'name-family'
| 'name-given'
@@ -658,18 +677,23 @@ type TextInputBaseProps = Readonly<{
| 'password-new'
| 'postal-address'
| 'postal-address-country'
| 'postal-address-dependent-locality'
| 'postal-address-extended'
| 'postal-address-extended-postal-code'
| 'postal-address-locality'
| 'postal-address-region'
| 'postal-address-unit'
| 'postal-code'
| 'promo-code'
| 'street-address'
| 'sms-otp'
| 'tel'
| 'tel-country-code'
| 'tel-national'
| 'tel-device'
| 'upi-vpa'
| 'url'
| 'wifi-password'
| 'username'
| 'username-new'
| 'off'
@@ -1056,6 +1056,7 @@ public open class ReactTextInputManager public constructor() :
private val REACT_PROPS_AUTOFILL_HINTS_MAP: Map<String, String> =
mapOf(
"2fa-app-otp" to HintConstants.AUTOFILL_HINT_2FA_APP_OTP,
"birthdate-day" to HintConstants.AUTOFILL_HINT_BIRTH_DATE_DAY,
"birthdate-full" to HintConstants.AUTOFILL_HINT_BIRTH_DATE_FULL,
"birthdate-month" to HintConstants.AUTOFILL_HINT_BIRTH_DATE_MONTH,
@@ -1067,7 +1068,13 @@ public open class ReactTextInputManager public constructor() :
"cc-exp-year" to HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR,
"cc-number" to HintConstants.AUTOFILL_HINT_CREDIT_CARD_NUMBER,
"email" to HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS,
"email-otp" to HintConstants.AUTOFILL_HINT_EMAIL_OTP,
"flight-confirmation-code" to HintConstants.AUTOFILL_HINT_FLIGHT_CONFIRMATION_CODE,
"flight-number" to HintConstants.AUTOFILL_HINT_FLIGHT_NUMBER,
"gender" to HintConstants.AUTOFILL_HINT_GENDER,
"gift-card-number" to HintConstants.AUTOFILL_HINT_GIFT_CARD_NUMBER,
"gift-card-pin" to HintConstants.AUTOFILL_HINT_GIFT_CARD_PIN,
"loyalty-account-number" to HintConstants.AUTOFILL_HINT_LOYALTY_ACCOUNT_NUMBER,
"name" to HintConstants.AUTOFILL_HINT_PERSON_NAME,
"name-family" to HintConstants.AUTOFILL_HINT_PERSON_NAME_FAMILY,
"name-given" to HintConstants.AUTOFILL_HINT_PERSON_NAME_GIVEN,
@@ -1079,19 +1086,25 @@ public open class ReactTextInputManager public constructor() :
"password-new" to HintConstants.AUTOFILL_HINT_NEW_PASSWORD,
"postal-address" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS,
"postal-address-country" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY,
"postal-address-dependent-locality" to
HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_DEPENDENT_LOCALITY,
"postal-address-extended" to
HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS,
"postal-address-extended-postal-code" to
HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE,
"postal-address-locality" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY,
"postal-address-region" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_REGION,
"postal-address-unit" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_APT_NUMBER,
"postal-code" to HintConstants.AUTOFILL_HINT_POSTAL_CODE,
"promo-code" to HintConstants.AUTOFILL_HINT_PROMO_CODE,
"street-address" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS,
"sms-otp" to HintConstants.AUTOFILL_HINT_SMS_OTP,
"tel" to HintConstants.AUTOFILL_HINT_PHONE_NUMBER,
"tel-country-code" to HintConstants.AUTOFILL_HINT_PHONE_COUNTRY_CODE,
"tel-national" to HintConstants.AUTOFILL_HINT_PHONE_NATIONAL,
"tel-device" to HintConstants.AUTOFILL_HINT_PHONE_NUMBER_DEVICE,
"upi-vpa" to HintConstants.AUTOFILL_HINT_UPI_VPA,
"wifi-password" to HintConstants.AUTOFILL_HINT_WIFI_PASSWORD,
"username" to HintConstants.AUTOFILL_HINT_USERNAME,
"username-new" to HintConstants.AUTOFILL_HINT_NEW_USERNAME,
)
@@ -19,7 +19,9 @@ import android.text.InputType
import android.text.Layout
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.autofill.HintConstants
import androidx.core.content.res.ResourcesCompat.ID_NULL
import com.facebook.react.bridge.BridgeReactContext
import com.facebook.react.bridge.CatalystInstance
@@ -214,6 +216,37 @@ class ReactTextInputPropertyTest {
assertThat(view.isEnabled).isTrue
}
@Test
fun testAutoCompleteExtendedHints() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return
}
val expectedHints =
listOf(
"2fa-app-otp" to HintConstants.AUTOFILL_HINT_2FA_APP_OTP,
"email-otp" to HintConstants.AUTOFILL_HINT_EMAIL_OTP,
"flight-confirmation-code" to HintConstants.AUTOFILL_HINT_FLIGHT_CONFIRMATION_CODE,
"flight-number" to HintConstants.AUTOFILL_HINT_FLIGHT_NUMBER,
"gift-card-number" to HintConstants.AUTOFILL_HINT_GIFT_CARD_NUMBER,
"gift-card-pin" to HintConstants.AUTOFILL_HINT_GIFT_CARD_PIN,
"loyalty-account-number" to HintConstants.AUTOFILL_HINT_LOYALTY_ACCOUNT_NUMBER,
"postal-address-dependent-locality" to
HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_DEPENDENT_LOCALITY,
"postal-address-unit" to HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_APT_NUMBER,
"promo-code" to HintConstants.AUTOFILL_HINT_PROMO_CODE,
"upi-vpa" to HintConstants.AUTOFILL_HINT_UPI_VPA,
"wifi-password" to HintConstants.AUTOFILL_HINT_WIFI_PASSWORD,
)
expectedHints.forEach { (autoComplete, expectedHint) ->
manager.updateProperties(view, buildStyles("autoComplete", autoComplete))
assertThat(view.importantForAutofill).isEqualTo(View.IMPORTANT_FOR_AUTOFILL_YES)
assertThat(view.autofillHints?.toList()).containsExactly(expectedHint)
}
}
@Test
fun testPlaceholderTextColor() {
val defaultPlaceholderColorStateList = getDefaultTextColorHint(view.context)
+15 -3
View File
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4d9de6bc6082c3ea5b39b8a5b685ac68>>
* @generated SignedSource<<093ad6137fc6ea19fc24f5449a183065>>
*
* This file was generated by scripts/js-api/build-types/index.js.
*/
@@ -5185,6 +5185,7 @@ declare type TextInputBaseProps = {
readonly allowFontScaling?: boolean
readonly autoCapitalize?: AutoCapitalize
readonly autoComplete?:
| "2fa-app-otp"
| "additional-name"
| "address-line1"
| "address-line2"
@@ -5205,12 +5206,18 @@ declare type TextInputBaseProps = {
| "cc-type"
| "country"
| "current-password"
| "email-otp"
| "email"
| "family-name"
| "flight-confirmation-code"
| "flight-number"
| "gender"
| "gift-card-number"
| "gift-card-pin"
| "given-name"
| "honorific-prefix"
| "honorific-suffix"
| "loyalty-account-number"
| "name-family"
| "name-given"
| "name-middle-initial"
@@ -5227,21 +5234,26 @@ declare type TextInputBaseProps = {
| "password-new"
| "password"
| "postal-address-country"
| "postal-address-dependent-locality"
| "postal-address-extended-postal-code"
| "postal-address-extended"
| "postal-address-locality"
| "postal-address-region"
| "postal-address-unit"
| "postal-address"
| "postal-code"
| "promo-code"
| "sms-otp"
| "street-address"
| "tel-country-code"
| "tel-device"
| "tel-national"
| "tel"
| "upi-vpa"
| "url"
| "username-new"
| "username"
| "wifi-password"
readonly autoCorrect?: boolean
readonly autoFocus?: boolean
readonly blurOnSubmit?: boolean
@@ -6216,7 +6228,7 @@ export {
TaskProvider, // 266dedf2
Text, // 0620c789
TextContentType, // 239b3ecc
TextInput, // 2e89b91d
TextInput, // dbb9f0e2
TextInputAndroidProps, // 3f09ce49
TextInputChangeEvent, // 6821f629
TextInputContentSizeChangeEvent, // 5fba3f54
@@ -6224,7 +6236,7 @@ export {
TextInputFocusEvent, // c36e977c
TextInputIOSProps, // 0d05a855
TextInputKeyPressEvent, // 967178c2
TextInputProps, // c75f0362
TextInputProps, // 3c24b82d
TextInputSelectionChangeEvent, // a1a7622f
TextInputSubmitEditingEvent, // 48d903af
TextLayoutEvent, // 45b0a8d7
@@ -9,7 +9,7 @@ ndkVersion = "27.1.12297006"
agp = "8.12.0"
androidx-annotation = "1.6.0"
androidx-appcompat = "1.7.0"
androidx-autofill = "1.1.0"
androidx-autofill = "1.3.0"
androidx-benchmark-macro-junit4 = "1.3.3"
androidx-profileinstaller = "1.4.1"
androidx-swiperefreshlayout = "1.1.0"
@@ -375,7 +375,49 @@ const examples: Array<RNTesterModuleExample> = [
autoComplete="one-time-code"
placeholder="one-time-code"
/>
<ExampleTextInput
autoComplete="2fa-app-otp"
placeholder="2fa-app-otp"
/>
<ExampleTextInput autoComplete="email-otp" placeholder="email-otp" />
<ExampleTextInput
autoComplete="flight-number"
placeholder="flight-number"
/>
<ExampleTextInput
autoComplete="flight-confirmation-code"
placeholder="flight-confirmation-code"
/>
<ExampleTextInput
autoComplete="gift-card-number"
placeholder="gift-card-number"
/>
<ExampleTextInput
autoComplete="gift-card-pin"
placeholder="gift-card-pin"
/>
<ExampleTextInput
autoComplete="loyalty-account-number"
placeholder="loyalty-account-number"
/>
<ExampleTextInput
autoComplete="postal-address-unit"
placeholder="postal-address-unit"
/>
<ExampleTextInput
autoComplete="postal-address-dependent-locality"
placeholder="postal-address-dependent-locality"
/>
<ExampleTextInput
autoComplete="promo-code"
placeholder="promo-code"
/>
<ExampleTextInput autoComplete="sms-otp" placeholder="sms-otp" />
<ExampleTextInput autoComplete="upi-vpa" placeholder="upi-vpa" />
<ExampleTextInput
autoComplete="wifi-password"
placeholder="wifi-password"
/>
</View>
);
},