Fixed that focusTextField may gets called during view update resulting in 'undefined behavior'

This commit is contained in:
dankito 2020-09-07 15:01:13 +02:00
parent 0baa74484b
commit 3d11614921
1 changed files with 7 additions and 5 deletions

View File

@ -91,6 +91,7 @@ struct UIKitTextField: UIViewRepresentable {
uiView.text = text uiView.text = text
if focusTextField { if focusTextField {
DispatchQueue.main.async { // in very few cases focusTextField gets called during view update resulting in 'undefined behavior' -> async() fixes this
uiView.focus() uiView.focus()
DispatchQueue.main.async { DispatchQueue.main.async {
@ -98,6 +99,7 @@ struct UIKitTextField: UIViewRepresentable {
} }
} }
} }
}
private func addDoneButtonToKeyboard(_ textField: UITextField, _ coordinator: Coordinator) { private func addDoneButtonToKeyboard(_ textField: UITextField, _ coordinator: Coordinator) {
coordinator.textField = textField coordinator.textField = textField