Why use many DispatchQueue.main.async when few do trick?

This commit is contained in:
Shadowfacts 2020-09-25 11:31:53 -04:00
parent 733d50b642
commit cf63384dce
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 6 additions and 8 deletions

View File

@ -149,20 +149,18 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
context.coordinator.didChange = textDidChange
context.coordinator.uiState = uiState
if becomeFirstResponder {
DispatchQueue.main.async {
// wait until the next runloop iteration so that SwiftUI view updates have finished and
// the text view knows its new content size
DispatchQueue.main.async {
self.textDidChange(uiView)
if becomeFirstResponder {
// calling becomeFirstResponder during the SwiftUI update causes a crash on iOS 13
uiView.becomeFirstResponder()
// can't update @State vars during the SwiftUI update
becomeFirstResponder = false
}
}
// wait until the next runloop iteration so that SwiftUI view updates have finished and
// the text view knows its new content size
DispatchQueue.main.async {
self.textDidChange(uiView)
}
}
func makeCoordinator() -> Coordinator {