From a2f7a7f0f717f3cfc728a230310b37412d01cb56 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 11 Dec 2022 22:13:56 +0100 Subject: [PATCH] Fixed the error cleanup when any of the text field is focused in the LoginForm component. --- .../Sources/Login/UI/Components/LoginForm.swift | 16 +++++++++++----- Modules/Sources/Login/UI/Views/LoginView.swift | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Modules/Sources/Login/UI/Components/LoginForm.swift b/Modules/Sources/Login/UI/Components/LoginForm.swift index 543dc27..5bb0711 100644 --- a/Modules/Sources/Login/UI/Components/LoginForm.swift +++ b/Modules/Sources/Login/UI/Components/LoginForm.swift @@ -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 } diff --git a/Modules/Sources/Login/UI/Views/LoginView.swift b/Modules/Sources/Login/UI/Views/LoginView.swift index 955a6f3..754fe4c 100644 --- a/Modules/Sources/Login/UI/Views/LoginView.swift +++ b/Modules/Sources/Login/UI/Views/LoginView.swift @@ -97,6 +97,7 @@ fileprivate extension LoginView { } icon: { if isAuthenticating { ProgressView() + .controlSize(.regular) } else { EmptyView() }