From 6e60e0ded5d9f1ffe48a3dd0201f41371ddff5ff Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Mon, 12 Dec 2022 07:40:11 -0500 Subject: [PATCH] Wrap becomeFirstResponder in async dispatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes issues when we’re updating the responder chain every time SwiftUI refreshes the view, which can have unpredictable side effects. --- iOS/PostEditor/MultilineTextView.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iOS/PostEditor/MultilineTextView.swift b/iOS/PostEditor/MultilineTextView.swift index b3afd97..1c0aaee 100644 --- a/iOS/PostEditor/MultilineTextView.swift +++ b/iOS/PostEditor/MultilineTextView.swift @@ -41,8 +41,10 @@ private struct UITextViewWrapper: UIViewRepresentable { uiView.text = self.text } - if uiView.window != nil, isEditing { - uiView.becomeFirstResponder() + if uiView.window != nil && isEditing { + DispatchQueue.main.async { + uiView.becomeFirstResponder() + } } UITextViewWrapper.recalculateHeight(view: uiView, result: $calculatedHeight)