From ff66af6719999e7857fd3b01e9994fa0c42c7b1f Mon Sep 17 00:00:00 2001 From: Ilias Pavlidakis Date: Tue, 14 Nov 2023 18:45:54 +0200 Subject: [PATCH] Fix issue where text view is not scrollable when pasting a long text (#2890) --- .../CommonViews/InputTextView/InputTextView.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/StreamChatUI/CommonViews/InputTextView/InputTextView.swift b/Sources/StreamChatUI/CommonViews/InputTextView/InputTextView.swift index 2f0fef7e20e..9a5a39552fb 100644 --- a/Sources/StreamChatUI/CommonViews/InputTextView/InputTextView.swift +++ b/Sources/StreamChatUI/CommonViews/InputTextView/InputTextView.swift @@ -172,7 +172,17 @@ open class InputTextView: UITextView, AppearanceProvider { @objc open func handleTextChange() { placeholderLabel.isHidden = !text.isEmpty - setNeedsDisplay() + setNeedsLayout() + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in + // This is due to bug in UITextView where the scroll sometimes disables + // when a very long text is pasted in it. + // Doing this ensures that it doesn't happen + // Reference: https://stackoverflow.com/a/62386088/5493299 + + self?.isScrollEnabled = false + self?.layoutIfNeeded() + self?.isScrollEnabled = true + } } @objc func textDidEndEditing(notification: Notification) {