From 613b7feee8423113713a6b1a94fd46a285f4a420 Mon Sep 17 00:00:00 2001 From: shannon Date: Fri, 13 Dec 2024 13:33:07 -0500 Subject: [PATCH] Avoid warning about accessing visibleCells during tableview updates --- .../ComposeContentViewModel+DataSource.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift index f3ebd7785..7806a1c01 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift @@ -28,6 +28,17 @@ extension ComposeContentViewModel { case replyTo case status } + + private func composeContentTableViewCellIsInTableView(_ tableView: UIView) -> Bool { + var superview = composeContentTableViewCell.superview + while superview != nil { + if superview == tableView { + return true + } + superview = superview?.superview + } + return false + } private func setupTableViewCell(tableView: UITableView) { composeContentTableViewCell.contentConfiguration = UIHostingConfigurationBackport { @@ -39,7 +50,7 @@ extension ComposeContentViewModel { .removeDuplicates() .sink { [weak self] height in guard let self = self else { return } - guard !tableView.visibleCells.isEmpty else { return } + guard self.composeContentTableViewCellIsInTableView(tableView) else { return } UIView.performWithoutAnimation { tableView.beginUpdates() self.composeContentTableViewCell.frame.size.height = height