Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ type IOSProps = $ReadOnly<{|
|}>;

type AndroidProps = $ReadOnly<{|
autoCompleteType?: ?(
| 'cc-csc'
| 'cc-exp'
| 'cc-exp-month'
| 'cc-exp-year'
| 'cc-number'
| 'email'
| 'name'
| 'password'
| 'postal-code'
| 'street-address'
| 'tel'
| 'username'
| 'off'
hramos marked this conversation as resolved.
Show resolved Hide resolved
),
returnKeyLabel?: ?string,
numberOfLines?: ?number,
disableFullscreenUI?: ?boolean,
Expand Down Expand Up @@ -350,6 +365,45 @@ const TextInput = createReactClass({
'words',
'characters',
]),
/**
* Determines which content to suggest on auto complete, e.g.`username`.
* To disable auto complete, use `off`.
*
* *Android Only*
*
* The following values work on Android only:
*
* - `username`
* - `password`
* - `email`
* - `name`
* - `tel`
* - `street-address`
* - `postal-code`
* - `cc-number`
* - `cc-csc`
* - `cc-exp`
* - `cc-exp-month`
* - `cc-exp-year`
* - `off`
*
* @platform android
*/
autoCompleteType: PropTypes.oneOf([
'cc-csc',
'cc-exp',
'cc-exp-month',
'cc-exp-year',
cassiozen marked this conversation as resolved.
Show resolved Hide resolved
cassiozen marked this conversation as resolved.
Show resolved Hide resolved
'cc-number',
'email',
'name',
'password',
'postal-code',
'street-address',
'tel',
'username',
'off',
]),
/**
* If `false`, disables auto-correct. The default value is `true`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,41 @@ public void setMaxLength(ReactEditText view, @Nullable Integer maxLength) {
view.setFilters(newFilters);
}

@ReactProp(name = "autoComplete")
public void setTextContentType(ReactEditText view, @Nullable String autocomplete) {
if (autocomplete == null) {
view.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
} else if ("username".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_USERNAME);
} else if ("password".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_PASSWORD);
} else if ("email".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_EMAIL_ADDRESS);
} else if ("name".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_NAME);
} else if ("tel".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_PHONE);
} else if ("street-address".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_POSTAL_ADDRESS);
} else if ("postal-code".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_POSTAL_CODE);
} else if ("cc-number".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_CREDIT_CARD_NUMBER);
} else if ("cc-csc".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE);
} else if ("cc-exp".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE);
} else if ("cc-exp-month".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH);
} else if ("cc-exp-year".equals(autocomplete)) {
view.setAutofillHints(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR);
} else if ("off".equals(autocomplete)) {
view.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
} else {
throw new JSApplicationIllegalArgumentException("Invalid autocomplete option: " + autocomplete);
}
}

@ReactProp(name = "autoCorrect")
public void setAutoCorrect(ReactEditText view, @Nullable Boolean autoCorrect) {
// clear auto correct flags, set SUGGESTIONS or NO_SUGGESTIONS depending on value
Expand Down