From ff4e20950dba686ae54f3f2d510a2ca9673c737a Mon Sep 17 00:00:00 2001 From: CMK Date: Fri, 2 Jul 2021 14:07:24 +0800 Subject: [PATCH] fix: disable cell frame cache for notification list due to data source not stable --- .../NotificationViewController.swift | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/Mastodon/Scene/Notification/NotificationViewController.swift b/Mastodon/Scene/Notification/NotificationViewController.swift index 8ac57a9f1..200ea2f20 100644 --- a/Mastodon/Scene/Notification/NotificationViewController.swift +++ b/Mastodon/Scene/Notification/NotificationViewController.swift @@ -192,33 +192,34 @@ extension NotificationViewController { extension NotificationViewController: StatusTableViewControllerAspect { } // MARK: - TableViewCellHeightCacheableContainer -extension NotificationViewController: TableViewCellHeightCacheableContainer { - var cellFrameCache: NSCache { - viewModel.cellFrameCache - } - - func cacheTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { - guard let diffableDataSource = viewModel.diffableDataSource else { return } - guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return } - let key = item.hashValue - let frame = cell.frame - viewModel.cellFrameCache.setObject(NSValue(cgRect: frame), forKey: NSNumber(value: key)) - } +//extension NotificationViewController: TableViewCellHeightCacheableContainer { +// var cellFrameCache: NSCache { +// viewModel.cellFrameCache +// } +// +// func cacheTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { +// guard let diffableDataSource = viewModel.diffableDataSource else { return } +// guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return } +// let key = item.hashValue +// let frame = cell.frame +// viewModel.cellFrameCache.setObject(NSValue(cgRect: frame), forKey: NSNumber(value: key)) +// } +// +// func handleTableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { +// guard let diffableDataSource = viewModel.diffableDataSource else { return UITableView.automaticDimension } +// guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return UITableView.automaticDimension } +// guard let frame = viewModel.cellFrameCache.object(forKey: NSNumber(value: item.hashValue))?.cgRectValue else { +// if case .bottomLoader = item { +// return TimelineLoaderTableViewCell.cellHeight +// } else { +// return UITableView.automaticDimension +// } +// } +// +// return ceil(frame.height) +// } +//} - func handleTableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { - guard let diffableDataSource = viewModel.diffableDataSource else { return UITableView.automaticDimension } - guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return UITableView.automaticDimension } - guard let frame = viewModel.cellFrameCache.object(forKey: NSNumber(value: item.hashValue))?.cgRectValue else { - if case .bottomLoader = item { - return TimelineLoaderTableViewCell.cellHeight - } else { - return UITableView.automaticDimension - } - } - - return ceil(frame.height) - } -} // MARK: - UITableViewDelegate extension NotificationViewController: UITableViewDelegate {