feat(ios): textfield option to disable iOS autofill strong password handling (#8348)

* feat(ios): textfield option to disable autofill strong password handling

* chore: api change report
This commit is contained in:
Nathan Walker
2020-03-23 03:16:40 -07:00
committed by GitHub
parent 8ab0e72bc9
commit 42fc4acea3
4 changed files with 80 additions and 64 deletions

View File

@ -8,6 +8,8 @@ export class TextFieldBase extends EditableTextBase implements TextFieldDefiniti
public static returnPressEvent = "returnPress";
public secure: boolean;
public closeOnReturn: boolean;
// iOS only (to avoid 12+ suggested strong password handling)
public secureWithoutAutofill: boolean;
}
TextFieldBase.prototype.recycleNativeView = "auto";

View File

@ -32,4 +32,9 @@ export class TextField extends EditableTextBase {
* Gets or sets if a text field should dismiss on return.
*/
closeOnReturn: boolean;
/**
* iOS only (to avoid 12+ auto suggested strong password handling)
*/
secureWithoutAutofill: boolean;
}

View File

@ -78,6 +78,14 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
const owner = this._owner.get();
if (owner) {
if (owner.secureWithoutAutofill && !textField.secureTextEntry) {
/**
* Helps avoid iOS 12+ autofill strong password suggestion prompt
* Discussed in several circles but for example:
* https://github.com/expo/expo/issues/2571#issuecomment-473347380
*/
textField.secureTextEntry = true;
}
const delta = replacementString.length - range.length;
if (delta > 0) {
if (textField.text.length + delta > owner.maxLength) {