Implemented that login name text field gets focused when a bank has been selected

This commit is contained in:
dankito 2020-10-05 03:08:23 +02:00
parent c2a9f9f44a
commit f6f28890a7
2 changed files with 15 additions and 13 deletions

View File

@ -18,14 +18,7 @@ struct LabelledUIKitTextField: View {
var focusOnStart = false var focusOnStart = false
var focusNextTextFieldOnReturnKeyPress = false var focusNextTextFieldOnReturnKeyPress = false
@State var focusTextField: Bool = false var focusTextField: Binding<Bool> = .constant(false)
private var focusTextFieldBinding: Binding<Bool> {
Binding<Bool>(
get: { self.focusTextField },
set: { self.focusTextField = $0 }
)
}
var isFocusedChanged: ((Bool) -> Void)? = nil var isFocusedChanged: ((Bool) -> Void)? = nil
@ -45,7 +38,7 @@ struct LabelledUIKitTextField: View {
Text(label) Text(label)
.onTapGesture { .onTapGesture {
DispatchQueue.main.async { DispatchQueue.main.async {
self.focusTextField = true self.focusTextField.wrappedValue = true
} }
} }
@ -67,7 +60,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: focusTextFieldBinding, 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)
@ -85,7 +78,7 @@ struct LabelledUIKitTextField: View {
) )
.onTapGesture { .onTapGesture {
DispatchQueue.main.async { DispatchQueue.main.async {
self.focusTextField = true self.focusTextField.wrappedValue = true
} }
} }
} }

View File

@ -9,6 +9,8 @@ struct AddAccountDialog: View {
@State private var userName = "" @State private var userName = ""
@State private var password = "" @State private var password = ""
@State private var focusLoginNameTextField: Bool = false
@State private var isTryingToAddAccount = false @State private var isTryingToAddAccount = false
@ -38,8 +40,8 @@ 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", LabelledUIKitTextField(label: "Online banking login name", text: $userName, placeholder: "Enter Online banking login name", autocapitalizationType: .none,
autocapitalizationType: .none, focusNextTextFieldOnReturnKeyPress: true, actionOnReturnKeyPress: handleReturnKeyPress) focusNextTextFieldOnReturnKeyPress: true, focusTextField: $focusLoginNameTextField, actionOnReturnKeyPress: handleReturnKeyPress)
LabelledUIKitTextField(label: "Online banking login password", text: $password, placeholder: "Enter Online banking login password", LabelledUIKitTextField(label: "Online banking login password", text: $password, placeholder: "Enter Online banking login password",
autocapitalizationType: .none, isPasswordField: true, actionOnReturnKeyPress: handleReturnKeyPress) autocapitalizationType: .none, isPasswordField: true, actionOnReturnKeyPress: handleReturnKeyPress)
@ -58,6 +60,13 @@ struct AddAccountDialog: View {
} }
} }
.onAppear {
if bank != nil {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // wait till animation for hiding SelectBankDialog is fully done
self.focusLoginNameTextField = true
}
}
}
.alert(message: $errorMessage) .alert(message: $errorMessage)
.fixKeyboardCoversLowerPart() .fixKeyboardCoversLowerPart()
.showNavigationBarTitle("Add account") .showNavigationBarTitle("Add account")