0

I am using a combination of TextField and SecureField on my Login screen of the app, user can click the eye button to show and hide text using this code:

ZStack(alignment: .trailing){
            if isSecured{
                SecureField(placeholder, text: $text)
                    .padding(.trailing, 35)
            }else{
                TextField(placeholder, text: $text)
                    .padding(.trailing, 35)
            }
            
            Button {
                isSecured = !isSecured
            } label: {
                Image(systemName: isSecured ? "eye.slash" : "eye")
            }

        }
        .background(
            Color.gray
                .frame(height: 0.5)
                .padding(.top, 40)
        )

So, when the user clicks the eye button to show the password and then again clicks the eye button after it to hide the password leads SecureField to auto-clear password on entering text, is there any way that password doesn't auto-clear? thanks

Umair Khan
  • 993
  • 8
  • 14
  • Probably you need to use only `TextField` and just hide text using two storages... anyway even if there would no be auto-clear issue you loose focus/caret removing/inserting entire input control. – Asperi Jan 07 '22 at 08:07
  • Yeah i think i need to change it like this, because nobody answered yet – Umair Khan Jan 07 '22 at 11:33

0 Answers0