diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/UIKitExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/UIKitExtensions.swift new file mode 100644 index 00000000..cedbd2b5 --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/ui/UIKitExtensions.swift @@ -0,0 +1,14 @@ +import SwiftUI + + +extension UIResponder { + + @discardableResult func focus() -> Bool { + return becomeFirstResponder() + } + + @discardableResult func clearFocus() -> Bool { + return resignFirstResponder() + } + +} diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/UIKitTextField.swift b/ui/BankingiOSApp/BankingiOSApp/ui/UIKitTextField.swift index 43ccc9c5..891fb48b 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/UIKitTextField.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/UIKitTextField.swift @@ -51,7 +51,7 @@ struct UIKitTextField: UIViewRepresentable { textField.tag = Self.NextTagId if focusOnStart { - textField.becomeFirstResponder() + textField.focus() } return textField @@ -110,11 +110,11 @@ struct UIKitTextField: UIViewRepresentable { let nextView = textField.superview?.superview?.superview?.viewWithTag(nextViewTag) ?? textField.superview?.superview?.superview?.superview?.superview?.viewWithTag(nextViewTag) // for text fields in Lists (tables) - didHandleReturnKey = nextView?.becomeFirstResponder() ?? false + didHandleReturnKey = nextView?.focus() ?? false } if didHandleReturnKey == false { - textField.resignFirstResponder() // default behaviour + textField.clearFocus() // default behaviour } return didHandleReturnKey diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/UIKitSearchBar.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/UIKitSearchBar.swift index a5d32222..cc4e9b46 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/UIKitSearchBar.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/UIKitSearchBar.swift @@ -36,7 +36,7 @@ struct UIKitSearchBar : UIViewRepresentable { searchBar.searchTextField.delegate = context.coordinator if focusOnStart { - searchBar.becomeFirstResponder() + searchBar.focus() } return searchBar