-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(ios): secureWithoutAutofill on TextField #11129
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate { | |
| public static ObjCProtocols = [UITextFieldDelegate]; | ||
|
|
||
| private _owner: WeakRef<TextField>; | ||
| private firstEdit: boolean; | ||
|
|
||
| public static initWithOwner(owner: WeakRef<TextField>): UITextFieldDelegateImpl { | ||
| const delegate = <UITextFieldDelegateImpl>UITextFieldDelegateImpl.new(); | ||
|
|
@@ -125,6 +124,7 @@ export class TextField extends TextFieldBase { | |
| super.initNativeView(); | ||
| this._delegate = UITextFieldDelegateImpl.initWithOwner(new WeakRef(this)); | ||
| this.nativeViewProtected.delegate = this._delegate; | ||
| this._applySecureWithoutAutofillTraits(this.nativeViewProtected); | ||
| } | ||
|
|
||
| disposeNativeView() { | ||
|
|
@@ -140,6 +140,7 @@ export class TextField extends TextFieldBase { | |
|
|
||
| public textFieldShouldBeginEditing(textField: UITextField): boolean { | ||
| this._firstEdit = true; | ||
| this._applySecureWithoutAutofillTraits(textField); | ||
|
|
||
| return this.editable; | ||
| } | ||
|
|
@@ -174,14 +175,7 @@ export class TextField extends TextFieldBase { | |
| } | ||
|
|
||
| public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean { | ||
| if (this.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; | ||
| } | ||
| this._applySecureWithoutAutofillTraits(textField); | ||
| const delta = replacementString.length - range.length; | ||
| if (delta > 0) { | ||
| if (textField.text.length + delta > this.maxLength) { | ||
|
|
@@ -243,6 +237,44 @@ export class TextField extends TextFieldBase { | |
| } | ||
| [secureProperty.setNative](value: boolean) { | ||
| this.nativeTextViewProtected.secureTextEntry = value; | ||
| this._applySecureWithoutAutofillTraits(this.nativeTextViewProtected); | ||
| } | ||
|
|
||
| private _applySecureWithoutAutofillTraits(textField: UITextField): void { | ||
| if (!textField || !this.secureWithoutAutofill) { | ||
| return; | ||
| } | ||
|
|
||
| const nativeField = textField as any; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is cast to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some properties are sdk level scoped so we can probably rather use SDK_VERSION scope on some. |
||
|
|
||
| textField.secureTextEntry = true; | ||
|
|
||
| if (nativeField.textContentType !== undefined) { | ||
| nativeField.textContentType = typeof UITextContentTypeOneTimeCode !== 'undefined' ? UITextContentTypeOneTimeCode : ''; | ||
| } | ||
|
|
||
| if (nativeField.autocorrectionType !== undefined) { | ||
| nativeField.autocorrectionType = UITextAutocorrectionType.No; | ||
| } | ||
| if (nativeField.spellCheckingType !== undefined) { | ||
| nativeField.spellCheckingType = UITextSpellCheckingType.No; | ||
| } | ||
| if (nativeField.smartDashesType !== undefined) { | ||
| nativeField.smartDashesType = UITextSmartDashesType.No; | ||
| } | ||
| if (nativeField.smartQuotesType !== undefined) { | ||
| nativeField.smartQuotesType = UITextSmartQuotesType.No; | ||
| } | ||
| if (nativeField.smartInsertDeleteType !== undefined) { | ||
| nativeField.smartInsertDeleteType = UITextSmartInsertDeleteType.No; | ||
| } | ||
| if (nativeField.passwordRules !== undefined) { | ||
| nativeField.passwordRules = null; | ||
| } | ||
|
|
||
| if (nativeField.reloadInputViews) { | ||
| nativeField.reloadInputViews(); | ||
| } | ||
| } | ||
|
|
||
| [colorProperty.getDefault](): { textColor: UIColor; tintColor: UIColor } { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Maybe we need an extra flag to determine if the native props have already been updated and reduce
_applySecureWithoutAutofillTraitscalls since there are cases likereloadInputViews()that might be called multiple times while typing.For instance, the old fix made sure to check whether
secureTextEntrywas already enabled or not before proceeding.