Extracted UIKitExtensions
This commit is contained in:
parent
38da439888
commit
98428959bb
|
@ -0,0 +1,14 @@
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
|
||||||
|
extension UIResponder {
|
||||||
|
|
||||||
|
@discardableResult func focus() -> Bool {
|
||||||
|
return becomeFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult func clearFocus() -> Bool {
|
||||||
|
return resignFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -51,7 +51,7 @@ struct UIKitTextField: UIViewRepresentable {
|
||||||
textField.tag = Self.NextTagId
|
textField.tag = Self.NextTagId
|
||||||
|
|
||||||
if focusOnStart {
|
if focusOnStart {
|
||||||
textField.becomeFirstResponder()
|
textField.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
return textField
|
return textField
|
||||||
|
@ -110,11 +110,11 @@ struct UIKitTextField: UIViewRepresentable {
|
||||||
let nextView = textField.superview?.superview?.superview?.viewWithTag(nextViewTag)
|
let nextView = textField.superview?.superview?.superview?.viewWithTag(nextViewTag)
|
||||||
?? textField.superview?.superview?.superview?.superview?.superview?.viewWithTag(nextViewTag) // for text fields in Lists (tables)
|
?? 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 {
|
if didHandleReturnKey == false {
|
||||||
textField.resignFirstResponder() // default behaviour
|
textField.clearFocus() // default behaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
return didHandleReturnKey
|
return didHandleReturnKey
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct UIKitSearchBar : UIViewRepresentable {
|
||||||
searchBar.searchTextField.delegate = context.coordinator
|
searchBar.searchTextField.delegate = context.coordinator
|
||||||
|
|
||||||
if focusOnStart {
|
if focusOnStart {
|
||||||
searchBar.becomeFirstResponder()
|
searchBar.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
return searchBar
|
return searchBar
|
||||||
|
|
Loading…
Reference in New Issue