From f6f28890a7df44d5d2bade8dddb6a789257acfc6 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 5 Oct 2020 03:08:23 +0200 Subject: [PATCH] Implemented that login name text field gets focused when a bank has been selected --- .../ui/UIKit/LabelledUIKitTextField.swift | 15 ++++----------- .../ui/dialogs/AddAccountDialog.swift | 13 +++++++++++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/UIKit/LabelledUIKitTextField.swift b/ui/BankingiOSApp/BankingiOSApp/ui/UIKit/LabelledUIKitTextField.swift index 4a8da40c..9253f9cf 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/UIKit/LabelledUIKitTextField.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/UIKit/LabelledUIKitTextField.swift @@ -18,14 +18,7 @@ struct LabelledUIKitTextField: View { var focusOnStart = false var focusNextTextFieldOnReturnKeyPress = false - @State var focusTextField: Bool = false - - private var focusTextFieldBinding: Binding { - Binding( - get: { self.focusTextField }, - set: { self.focusTextField = $0 } - ) - } + var focusTextField: Binding = .constant(false) var isFocusedChanged: ((Bool) -> Void)? = nil @@ -45,7 +38,7 @@ struct LabelledUIKitTextField: View { Text(label) .onTapGesture { DispatchQueue.main.async { - self.focusTextField = true + self.focusTextField.wrappedValue = true } } @@ -67,7 +60,7 @@ struct LabelledUIKitTextField: View { UIKitTextField(placeholder, text: $text, keyboardType: keyboardType, autocapitalizationType: autocapitalizationType, addDoneButton: addDoneButton, isPasswordField: isPasswordField, - focusOnStart: focusOnStart, focusNextTextFieldOnReturnKeyPress: focusNextTextFieldOnReturnKeyPress, focusTextField: focusTextFieldBinding, + focusOnStart: focusOnStart, focusNextTextFieldOnReturnKeyPress: focusNextTextFieldOnReturnKeyPress, focusTextField: focusTextField, isFocusedChanged: isFocusedChanged, textAlignment: .right, isUserInputEnabled: isUserInputEnabled, actionOnReturnKeyPress: actionOnReturnKeyPress, textChanged: textChanged) @@ -85,7 +78,7 @@ struct LabelledUIKitTextField: View { ) .onTapGesture { DispatchQueue.main.async { - self.focusTextField = true + self.focusTextField.wrappedValue = true } } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift index c9140cb1..fd3e61a6 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift @@ -9,6 +9,8 @@ struct AddAccountDialog: View { @State private var userName = "" @State private var password = "" + + @State private var focusLoginNameTextField: Bool = false @State private var isTryingToAddAccount = false @@ -38,8 +40,8 @@ struct AddAccountDialog: View { } Section(header: Text("Online banking login data")) { - LabelledUIKitTextField(label: "Online banking login name", text: $userName, placeholder: "Enter Online banking login name", - autocapitalizationType: .none, focusNextTextFieldOnReturnKeyPress: true, actionOnReturnKeyPress: handleReturnKeyPress) + LabelledUIKitTextField(label: "Online banking login name", text: $userName, placeholder: "Enter Online banking login name", autocapitalizationType: .none, + focusNextTextFieldOnReturnKeyPress: true, focusTextField: $focusLoginNameTextField, actionOnReturnKeyPress: handleReturnKeyPress) LabelledUIKitTextField(label: "Online banking login password", text: $password, placeholder: "Enter Online banking login password", 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) .fixKeyboardCoversLowerPart() .showNavigationBarTitle("Add account")