Fixed the error cleanup when any of the text field is focused in the LoginForm component.

This commit is contained in:
Javier Cicchelli 2022-12-11 22:13:56 +01:00
parent 07defd0045
commit a2f7a7f0f7
2 changed files with 12 additions and 5 deletions

View File

@ -38,11 +38,7 @@ struct LoginForm: View {
comment: "The placeholder for the username text field."
),
text: $username
) { isBeginEditing in
guard isBeginEditing, errorMessage != nil else { return }
errorMessage = nil
}
)
.textContentType(.username)
.lineLimit(1)
.autocapitalization(.none)
@ -96,6 +92,9 @@ struct LoginForm: View {
.onAppear {
setClearButtonIfNeeded()
}
.onChange(of: focusedField) { _ in
onTextFieldFocused()
}
}
}
@ -109,6 +108,13 @@ private extension LoginForm {
textFieldAppearance.clearButtonMode = .whileEditing
}
func onTextFieldFocused() {
guard errorMessage != nil else { return }
password = ""
errorMessage = nil
}
func onUsernameReturnPressed() {
guard !username.isEmpty else { return }

View File

@ -97,6 +97,7 @@ fileprivate extension LoginView {
} icon: {
if isAuthenticating {
ProgressView()
.controlSize(.regular)
} else {
EmptyView()
}