From 804a5d0fda8120c3641945630a6d57c3493a92d9 Mon Sep 17 00:00:00 2001 From: shannon Date: Wed, 18 Dec 2024 10:52:39 -0500 Subject: [PATCH] Control the height of the compose window a little better. Avoids the known hang, which was caused by getting stuck in a loop setting the frame back and forth over and over. Looked like it was adding and then removing (and then adding, etc) the height of a single line of text. Possible the username was shifting back and forth between truncating and wrapping, but have not confirmed that. Fixes #705 IOS client consistently hangs when writing new post at ~= 150 chars --- .../ComposeContentViewModel+DataSource.swift | 9 ++++++--- .../TableViewCell/ComposeContentTableViewCell.swift | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift index 7806a1c010..6e839d227e 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift @@ -52,9 +52,12 @@ extension ComposeContentViewModel { guard let self = self else { return } guard self.composeContentTableViewCellIsInTableView(tableView) else { return } UIView.performWithoutAnimation { - tableView.beginUpdates() - self.composeContentTableViewCell.frame.size.height = height - tableView.endUpdates() + if height != self.composeContentTableViewCell.contentHeight { + tableView.beginUpdates() + self.composeContentTableViewCell.contentHeight = height + self.composeContentTableViewCell.invalidateIntrinsicContentSize() + tableView.endUpdates() + } } } .store(in: &disposeBag) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/TableViewCell/ComposeContentTableViewCell.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/TableViewCell/ComposeContentTableViewCell.swift index c81da3be34..5a70439260 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/TableViewCell/ComposeContentTableViewCell.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/TableViewCell/ComposeContentTableViewCell.swift @@ -9,6 +9,13 @@ import UIKit import UIHostingConfigurationBackport final class ComposeContentTableViewCell: UITableViewCell { + + var contentHeight: CGFloat? + + override var intrinsicContentSize: CGSize { + let superContentSize = super.intrinsicContentSize + return CGSize(width: superContentSize.width, height: contentHeight ?? superContentSize.height) + } override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier)