Fixed that tap on label didn't lead to a change in focusTextField's value

This commit is contained in:
dankito 2020-11-05 00:51:58 +01:00
parent 079979aca4
commit c037308751
2 changed files with 6 additions and 8 deletions

View File

@ -17,8 +17,8 @@ struct LabelledUIKitTextField: View {
var focusOnStart = false var focusOnStart = false
var focusNextTextFieldOnReturnKeyPress = false var focusNextTextFieldOnReturnKeyPress = false
var focusTextField: Binding<Bool> = .constant(false) @State var focusTextField: Bool = false
var isFocusedChanged: ((Bool) -> Void)? = nil var isFocusedChanged: ((Bool) -> Void)? = nil
@ -37,9 +37,7 @@ struct LabelledUIKitTextField: View {
HStack(alignment: .center) { HStack(alignment: .center) {
Text(label) Text(label)
.onTapGesture { .onTapGesture {
DispatchQueue.main.async { self.focusTextField = true
self.focusTextField.wrappedValue = true
}
} }
Spacer() Spacer()
@ -60,7 +58,7 @@ struct LabelledUIKitTextField: View {
UIKitTextField(placeholder, text: $text, UIKitTextField(placeholder, text: $text,
keyboardType: keyboardType, autocapitalizationType: autocapitalizationType, addDoneButton: addDoneButton, keyboardType: keyboardType, autocapitalizationType: autocapitalizationType, addDoneButton: addDoneButton,
isPasswordField: isPasswordField, isPasswordField: isPasswordField,
focusOnStart: focusOnStart, focusNextTextFieldOnReturnKeyPress: focusNextTextFieldOnReturnKeyPress, focusTextField: focusTextField, focusOnStart: focusOnStart, focusNextTextFieldOnReturnKeyPress: focusNextTextFieldOnReturnKeyPress, focusTextField: $focusTextField,
isFocusedChanged: isFocusedChanged, textAlignment: .right, isUserInputEnabled: isUserInputEnabled, isFocusedChanged: isFocusedChanged, textAlignment: .right, isUserInputEnabled: isUserInputEnabled,
actionOnReturnKeyPress: actionOnReturnKeyPress, textChanged: textChanged) actionOnReturnKeyPress: actionOnReturnKeyPress, textChanged: textChanged)
@ -78,7 +76,7 @@ struct LabelledUIKitTextField: View {
) )
.onTapGesture { .onTapGesture {
DispatchQueue.main.async { DispatchQueue.main.async {
self.focusTextField.wrappedValue = true self.focusTextField = true
} }
} }
} }

View File

@ -44,7 +44,7 @@ struct AddAccountDialog: View {
Section(header: Text("Online banking login data")) { Section(header: Text("Online banking login data")) {
LabelledUIKitTextField(label: "Online banking login name", text: $userName, placeholder: "Enter Online banking login name", autocapitalizationType: .none, LabelledUIKitTextField(label: "Online banking login name", text: $userName, placeholder: "Enter Online banking login name", autocapitalizationType: .none,
focusNextTextFieldOnReturnKeyPress: true, focusTextField: $focusLoginNameTextField, actionOnReturnKeyPress: handleReturnKeyPress) focusNextTextFieldOnReturnKeyPress: true, focusTextField: focusLoginNameTextField, actionOnReturnKeyPress: handleReturnKeyPress)
BankCredentialsPasswordView($password, $savePassword, handleReturnKeyPress) BankCredentialsPasswordView($password, $savePassword, handleReturnKeyPress)
} }