From ac598aff2b388d4fac9f42a2e2cef73542d2531d Mon Sep 17 00:00:00 2001 From: Radek Czemerys Date: Mon, 23 Mar 2026 14:49:30 -0700 Subject: [PATCH] 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` image Reviewed By: cortinico, javache Differential Revision: D96952637 Pulled By: NickGerleman fbshipit-source-id: e01c99bfa4411219a73fb586b873b1f86ea28122 --- .../AndroidTextInputNativeComponent.js | 24 +++++++++++ .../Components/TextInput/TextInput.d.ts | 24 +++++++++++ .../Components/TextInput/TextInput.flow.js | 24 +++++++++++ .../views/textinput/ReactTextInputManager.kt | 13 ++++++ .../textinput/ReactTextInputPropertyTest.kt | 33 +++++++++++++++ packages/react-native/ReactNativeApi.d.ts | 18 ++++++-- .../react-native/gradle/libs.versions.toml | 2 +- .../TextInput/TextInputExample.android.js | 42 +++++++++++++++++++ 8 files changed, 176 insertions(+), 4 deletions(-) diff --git a/packages/react-native/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js b/packages/react-native/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js index ee9d9f7fbfd..c8df67cb48f 100644 --- a/packages/react-native/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +++ b/packages/react-native/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js @@ -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', diff --git a/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts b/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts index 25c814232a7..97535f6cf82 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts +++ b/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts @@ -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' diff --git a/packages/react-native/Libraries/Components/TextInput/TextInput.flow.js b/packages/react-native/Libraries/Components/TextInput/TextInput.flow.js index 50a794ebe3c..85e6c69b645 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInput.flow.js +++ b/packages/react-native/Libraries/Components/TextInput/TextInput.flow.js @@ -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' diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.kt index 9ce62f72093..9e40dbe5e69 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.kt @@ -1056,6 +1056,7 @@ public open class ReactTextInputManager public constructor() : private val REACT_PROPS_AUTOFILL_HINTS_MAP: Map = 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, ) diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt index 844e237e69c..e1fe5c6b27c 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/ReactTextInputPropertyTest.kt @@ -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) diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index 073c1eefdbf..a2bbb68bb33 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -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 diff --git a/packages/react-native/gradle/libs.versions.toml b/packages/react-native/gradle/libs.versions.toml index 2f9c4666495..c04bdb8a79a 100644 --- a/packages/react-native/gradle/libs.versions.toml +++ b/packages/react-native/gradle/libs.versions.toml @@ -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" diff --git a/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js b/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js index eda21cd69be..3ab12ec76bc 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js @@ -375,7 +375,49 @@ const examples: Array = [ autoComplete="one-time-code" placeholder="one-time-code" /> + + + + + + + + + + + + ); },