Improved the helper functions in the LoginForm view component.
This commit is contained in:
parent
ad409f938c
commit
4eb373b6ef
@ -31,33 +31,39 @@ struct LoginForm: View {
|
||||
alignment: .leading,
|
||||
spacing: 16
|
||||
) {
|
||||
TextField("Username", text: $username) { isBeginEditing in
|
||||
TextField(
|
||||
"login.text_field.username.placeholder",
|
||||
text: $username
|
||||
) { isBeginEditing in
|
||||
guard isBeginEditing, errorMessage != nil else { return }
|
||||
|
||||
errorMessage = nil
|
||||
}
|
||||
.textContentType(.username)
|
||||
.lineLimit(1)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.keyboardType(.default)
|
||||
.focused($focusedField, equals: .username)
|
||||
.onSubmit {
|
||||
onUsernameReturnPressed()
|
||||
}
|
||||
.textContentType(.username)
|
||||
.lineLimit(1)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.keyboardType(.default)
|
||||
.focused($focusedField, equals: .username)
|
||||
.onSubmit {
|
||||
onUsernameReturnPressed()
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
SecureField("Password", text: $password)
|
||||
.textContentType(.password)
|
||||
.lineLimit(1)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.keyboardType(.default)
|
||||
.focused($focusedField, equals: .password)
|
||||
.onSubmit {
|
||||
onPasswordReturnPressed()
|
||||
}
|
||||
SecureField(
|
||||
"login.text_field.password.placeholder",
|
||||
text: $password
|
||||
)
|
||||
.textContentType(.password)
|
||||
.lineLimit(1)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.keyboardType(.default)
|
||||
.focused($focusedField, equals: .password)
|
||||
.onSubmit {
|
||||
onPasswordReturnPressed()
|
||||
}
|
||||
|
||||
if let errorMessage {
|
||||
Divider()
|
||||
@ -81,16 +87,14 @@ struct LoginForm: View {
|
||||
|
||||
private extension LoginForm {
|
||||
func setClearButtonIfNeeded() {
|
||||
guard UITextField.appearance().clearButtonMode != .whileEditing else { return }
|
||||
let textFieldAppearance = UITextField.appearance()
|
||||
guard textFieldAppearance.clearButtonMode != .whileEditing else { return }
|
||||
|
||||
UITextField.appearance().clearButtonMode = .whileEditing
|
||||
textFieldAppearance.clearButtonMode = .whileEditing
|
||||
}
|
||||
|
||||
func onUsernameReturnPressed() {
|
||||
guard !username.isEmpty else {
|
||||
focusedField = .username
|
||||
return
|
||||
}
|
||||
guard !username.isEmpty else { return }
|
||||
|
||||
if password.isEmpty {
|
||||
focusedField = .password
|
||||
@ -100,10 +104,7 @@ private extension LoginForm {
|
||||
}
|
||||
|
||||
func onPasswordReturnPressed() {
|
||||
guard !password.isEmpty else {
|
||||
focusedField = .password
|
||||
return
|
||||
}
|
||||
guard !password.isEmpty else { return }
|
||||
|
||||
if username.isEmpty {
|
||||
focusedField = .username
|
||||
|
Loading…
x
Reference in New Issue
Block a user