Extracted UIKitExtensions

This commit is contained in:
dankito 2020-08-03 20:41:26 +02:00
parent 38da439888
commit 98428959bb
3 changed files with 18 additions and 4 deletions

View File

@ -0,0 +1,14 @@
import SwiftUI
extension UIResponder {
@discardableResult func focus() -> Bool {
return becomeFirstResponder()
}
@discardableResult func clearFocus() -> Bool {
return resignFirstResponder()
}
}

View File

@ -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

View File

@ -36,7 +36,7 @@ struct UIKitSearchBar : UIViewRepresentable {
searchBar.searchTextField.delegate = context.coordinator
if focusOnStart {
searchBar.becomeFirstResponder()
searchBar.focus()
}
return searchBar