@@ -13,7 +13,6 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
1313 public static ObjCProtocols = [ UITextFieldDelegate ] ;
1414
1515 private _owner : WeakRef < TextField > ;
16- private firstEdit : boolean ;
1716
1817 public static initWithOwner ( owner : WeakRef < TextField > ) : UITextFieldDelegateImpl {
1918 const delegate = < UITextFieldDelegateImpl > UITextFieldDelegateImpl . new ( ) ;
@@ -125,6 +124,7 @@ export class TextField extends TextFieldBase {
125124 super . initNativeView ( ) ;
126125 this . _delegate = UITextFieldDelegateImpl . initWithOwner ( new WeakRef ( this ) ) ;
127126 this . nativeViewProtected . delegate = this . _delegate ;
127+ this . _applySecureWithoutAutofillTraits ( this . nativeViewProtected ) ;
128128 }
129129
130130 disposeNativeView ( ) {
@@ -140,6 +140,7 @@ export class TextField extends TextFieldBase {
140140
141141 public textFieldShouldBeginEditing ( textField : UITextField ) : boolean {
142142 this . _firstEdit = true ;
143+ this . _applySecureWithoutAutofillTraits ( textField ) ;
143144
144145 return this . editable ;
145146 }
@@ -174,14 +175,7 @@ export class TextField extends TextFieldBase {
174175 }
175176
176177 public textFieldShouldChangeCharactersInRangeReplacementString ( textField : UITextField , range : NSRange , replacementString : string ) : boolean {
177- if ( this . secureWithoutAutofill && ! textField . secureTextEntry ) {
178- /**
179- * Helps avoid iOS 12+ autofill strong password suggestion prompt
180- * Discussed in several circles but for example:
181- * https://github.com/expo/expo/issues/2571#issuecomment-473347380
182- */
183- textField . secureTextEntry = true ;
184- }
178+ this . _applySecureWithoutAutofillTraits ( textField ) ;
185179 const delta = replacementString . length - range . length ;
186180 if ( delta > 0 ) {
187181 if ( textField . text . length + delta > this . maxLength ) {
@@ -243,6 +237,44 @@ export class TextField extends TextFieldBase {
243237 }
244238 [ secureProperty . setNative ] ( value : boolean ) {
245239 this . nativeTextViewProtected . secureTextEntry = value ;
240+ this . _applySecureWithoutAutofillTraits ( this . nativeTextViewProtected ) ;
241+ }
242+
243+ private _applySecureWithoutAutofillTraits ( textField : UITextField ) : void {
244+ if ( ! textField || ! this . secureWithoutAutofill ) {
245+ return ;
246+ }
247+
248+ const nativeField = textField as any ;
249+
250+ textField . secureTextEntry = true ;
251+
252+ if ( nativeField . textContentType !== undefined ) {
253+ nativeField . textContentType = typeof UITextContentTypeOneTimeCode !== 'undefined' ? UITextContentTypeOneTimeCode : '' ;
254+ }
255+
256+ if ( nativeField . autocorrectionType !== undefined ) {
257+ nativeField . autocorrectionType = UITextAutocorrectionType . No ;
258+ }
259+ if ( nativeField . spellCheckingType !== undefined ) {
260+ nativeField . spellCheckingType = UITextSpellCheckingType . No ;
261+ }
262+ if ( nativeField . smartDashesType !== undefined ) {
263+ nativeField . smartDashesType = UITextSmartDashesType . No ;
264+ }
265+ if ( nativeField . smartQuotesType !== undefined ) {
266+ nativeField . smartQuotesType = UITextSmartQuotesType . No ;
267+ }
268+ if ( nativeField . smartInsertDeleteType !== undefined ) {
269+ nativeField . smartInsertDeleteType = UITextSmartInsertDeleteType . No ;
270+ }
271+ if ( nativeField . passwordRules !== undefined ) {
272+ nativeField . passwordRules = null ;
273+ }
274+
275+ if ( nativeField . reloadInputViews ) {
276+ nativeField . reloadInputViews ( ) ;
277+ }
246278 }
247279
248280 [ colorProperty . getDefault ] ( ) : { textColor : UIColor ; tintColor : UIColor } {
0 commit comments