Note: This bug has been fixed in Xcode 13.0 beta 3
I am experiencing very odd behavior when trying to use multiple SecureFields when following a TextField in a view. Attempting to enter text in one of the SecureFields stops at one character with the field turning yellow and displaying "Strong Password", as well as duplicating in the second SecureField. This is occurring on iOS 14.2 in Xcode 12.2 on the Xcode preview and in the simulator.
Here is a minimal example that demonstrates the issue:
struct SecureFieldTestView: View {
@State var displayName: String = ""
@State var password = ""
@State var passwordVerifiation = ""
var body: some View {
VStack {
TextField("Display name", text: $displayName)
SecureField("Password", text: $password)
SecureField("Verify Password", text: $passwordVerifiation)
}
.padding()
}
}
struct SecureFieldTestView_Previews: PreviewProvider {
static var previews: some View {
SecureFieldTestView()
}
}
The console shows the following errors when running into the simulator:
[AutoFill] Cannot show Automatic Strong Passwords for app bundleID: <REDACTED BY ME> due to error: iCloud Keychain is disabled
[Assert] View <(null):0x0> does not conform to UITextInput protocol
I have tried to wrap the SecureFields into their own VStack{} and wrapping them all into a Form{}, but the issue remains.
Is there something obvious that I am missing or is this a bug in the SDK?
The . padding() style will add padding around the TextField component. By default padding is set to all for sides of the component.
A secure text field is suitable for use as a password-entry object or for any item in which the text value must be kept secret. NSSecureTextField uses NSSecureTextFieldCell to implement its user interface.
I would report a bug to Apple regarding this issue...
However, for the moment here is a workaround to fix this and still use the SecureField without the yellow bar on top..
SecureField("First", text: $password)
.textContentType(.newPassword)
Just add textContentType for newPassword and that bar won't appear.
On further investigation, there is another issue that was occurring; the software keyboard would not appear until after some delay. Entering text in the SecureFields before the software keyboard appeared consistantly produced the issue. Waiting for the software keyboard to appear resolves the odd behavior.
Strangely, the delay in the keyboard appearance seems to occur when the device/simulator is not logged into iCloud; the keyboard appearance delay and SecureField issue does not occur when the device is logged in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With