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,
|
alignment: .leading,
|
||||||
spacing: 16
|
spacing: 16
|
||||||
) {
|
) {
|
||||||
TextField("Username", text: $username) { isBeginEditing in
|
TextField(
|
||||||
|
"login.text_field.username.placeholder",
|
||||||
|
text: $username
|
||||||
|
) { isBeginEditing in
|
||||||
guard isBeginEditing, errorMessage != nil else { return }
|
guard isBeginEditing, errorMessage != nil else { return }
|
||||||
|
|
||||||
errorMessage = nil
|
errorMessage = nil
|
||||||
}
|
}
|
||||||
.textContentType(.username)
|
.textContentType(.username)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
.autocapitalization(.none)
|
.autocapitalization(.none)
|
||||||
.disableAutocorrection(true)
|
.disableAutocorrection(true)
|
||||||
.keyboardType(.default)
|
.keyboardType(.default)
|
||||||
.focused($focusedField, equals: .username)
|
.focused($focusedField, equals: .username)
|
||||||
.onSubmit {
|
.onSubmit {
|
||||||
onUsernameReturnPressed()
|
onUsernameReturnPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
SecureField("Password", text: $password)
|
SecureField(
|
||||||
.textContentType(.password)
|
"login.text_field.password.placeholder",
|
||||||
.lineLimit(1)
|
text: $password
|
||||||
.autocapitalization(.none)
|
)
|
||||||
.disableAutocorrection(true)
|
.textContentType(.password)
|
||||||
.keyboardType(.default)
|
.lineLimit(1)
|
||||||
.focused($focusedField, equals: .password)
|
.autocapitalization(.none)
|
||||||
.onSubmit {
|
.disableAutocorrection(true)
|
||||||
onPasswordReturnPressed()
|
.keyboardType(.default)
|
||||||
}
|
.focused($focusedField, equals: .password)
|
||||||
|
.onSubmit {
|
||||||
|
onPasswordReturnPressed()
|
||||||
|
}
|
||||||
|
|
||||||
if let errorMessage {
|
if let errorMessage {
|
||||||
Divider()
|
Divider()
|
||||||
@ -81,16 +87,14 @@ struct LoginForm: View {
|
|||||||
|
|
||||||
private extension LoginForm {
|
private extension LoginForm {
|
||||||
func setClearButtonIfNeeded() {
|
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() {
|
func onUsernameReturnPressed() {
|
||||||
guard !username.isEmpty else {
|
guard !username.isEmpty else { return }
|
||||||
focusedField = .username
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if password.isEmpty {
|
if password.isEmpty {
|
||||||
focusedField = .password
|
focusedField = .password
|
||||||
@ -100,10 +104,7 @@ private extension LoginForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func onPasswordReturnPressed() {
|
func onPasswordReturnPressed() {
|
||||||
guard !password.isEmpty else {
|
guard !password.isEmpty else { return }
|
||||||
focusedField = .password
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if username.isEmpty {
|
if username.isEmpty {
|
||||||
focusedField = .username
|
focusedField = .username
|
||||||
|
Loading…
x
Reference in New Issue
Block a user