-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android + Crossplatform][TextInput] Add autoComplete prop #21575
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code analysis results:
eslint
found some issues.eslint
found some issues.
+1 |
@cassiozen Thanks for the PR! We already have https://facebook.github.io/react-native/docs/textinput#textcontenttype for iOS, I think we could reuse this prop and make it cross platform. We probably just have to specify which values are platform specific. |
Hi @janicduplessis - thanks for the feedback. I considered reusing Even on iOS, only On Android, the AutoFill means just safe autocompletion, it doesn't affect the system in any other way. |
Another argument in favor of a cross-platform solution: iOS is introducing password recipes (and Android might do something similar in the future) - we could embrace all those solutions with a single, unified API. |
Hopefully this gets merged soon. I need it to fix a whole host of bugs involving the autofill manager:
|
Hi there, I'm the technical lead of the Android Autofill Framework. See my replies below..
When we designed the Autofill Framework, we consider using Android's InputType to convey the semantic of the field type, but we decide to add a new property ( 1.The
I think an "autocomplete" property would be cross-platform as well, as this is a W3C standard. In fact, for Android apps using -- Felipe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick change requested on the java side but everything else looks good. Thanks for the feature!
ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Will give @cassiozen a chance to address feedback before importing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the changes! @cassiozen @hramos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Cassio Zen merged commit f151456 into |
Summary: TL;DR: Setting `autoComplete` will allow the system to suggest autofill options for the `<TextInput>` component. Android Oreo introduced the AutoFill Framework, for secure communication between an app and autofill services (e.g. Password managers). When using `<TextInput>` on Android Oreo+, the system already tries to autofill (based on heuristics), but there is no way to set configuring options or disable. The quick solution would be to just add the same Android attributes (`autofillHints` & `importantForAutofill`) in React Native TextInput, but that doesn't bond well with the cross-platform nature of the library. Introduces an `autoComplete` prop based on HTML's `autocomplete` attribute, mapping to Android `autofillHints` & `importantForAutofill` and serving as a proper placeholder for autofill/autocomplete in other platforms: Also gives you the ability to disable autofill by setting autocomplete="off". Pull Request resolved: #21575 Differential Revision: D14102949 Pulled By: hramos fbshipit-source-id: 7601aeaca0332a1f3ce8da8020dba037b700853a
We noticed some crashes on pre-26 devices. We're rolling out a fix to prevent |
Going to revert manually in 0.60-stable now. EDIT: Had some issues doing |
Fix is in d4aa1e7. Cross-posted to react-native-community/releases#99. |
Motivation
TL;DR: Setting
autoComplete
will allow the system to suggest autofill options for the<TextInput>
component.Android Oreo introduced the AutoFill Framework, for secure communication between an app and autofill services (e.g. Password managers). When using
<TextInput>
on Android Oreo+, the system already tries to autofill (based on heuristics), but there is no way to set configuring options or disable.The quick solution would be to just add the same Android attributes (
autofillHints
&importantForAutofill
) in React Native TextInput, but that doesn't bond well with the cross-platform nature of the library.This PR
Introduces an
autoComplete
prop based on HTML'sautocomplete
attribute, mapping to AndroidautofillHints
&importantForAutofill
and serving as a proper placeholder for autofill/autocomplete in other platforms:Also gives you the ability to disable autofill by setting autocomplete="off".
Test Plan
Adding autoComplete equal to username, password or any other available options should give you an autofill-bar bellow the TextInput which will let you fill in values from an AutoFill Service.
(The image show an example using Google's sample AutoFill Service
Setting the appropriate autoComplete will fill in the correct value in the TextInput.
Usage:
To disable:
References
Feature Request on React Native's Canny: https://react-native.canny.io/feature-requests/p/autocomplete-prop-for-textinput
Android AutoFill Framework documentation: https://developer.android.com/guide/topics/text/autofill
HTML autocomplete attribute spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls%3A-the-autocomplete-attribute
Related PR:
Docs PR: facebook/react-native-website#606
Release Notes:
Help reviewers and the release process by writing your own release notes. See below for an example.
[ANDROID] [FEATURE] [AutoComplete] - Allow control over autofill suggestions for the
<TextInput>
component.