Don't query visible cells on scroll

This commit is contained in:
Justin Mazzocchi 2021-01-19 13:09:12 -08:00
parent 5c179457e5
commit 33494b9f76
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -17,6 +17,7 @@ class TableViewController: UITableViewController {
private let loadingTableFooterView = LoadingTableFooterView() private let loadingTableFooterView = LoadingTableFooterView()
private let webfingerIndicatorView = WebfingerIndicatorView() private let webfingerIndicatorView = WebfingerIndicatorView()
@Published private var loading = false @Published private var loading = false
private var visibleLoadMoreViews = Set<LoadMoreView>()
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
private var cellHeightCaches = [CGFloat: [CollectionItem: CGFloat]]() private var cellHeightCaches = [CGFloat: [CollectionItem: CGFloat]]()
private var shouldKeepPlayingVideoAfterDismissal = false private var shouldKeepPlayingVideoAfterDismissal = false
@ -105,6 +106,18 @@ class TableViewController: UITableViewController {
: viewModel.nextPageMaxId { : viewModel.nextPageMaxId {
viewModel.request(maxId: maxId, minId: nil) viewModel.request(maxId: maxId, minId: nil)
} }
if let loadMoreView = cell.contentView as? LoadMoreView {
visibleLoadMoreViews.insert(loadMoreView)
}
}
override func tableView(_ tableView: UITableView,
didEndDisplaying cell: UITableViewCell,
forRowAt indexPath: IndexPath) {
if let loadMoreView = cell.contentView as? LoadMoreView {
visibleLoadMoreViews.remove(loadMoreView)
}
} }
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
@ -220,10 +233,6 @@ private extension TableViewController {
static let bottomInset: CGFloat = .newStatusButtonDimension + .defaultSpacing * 4 static let bottomInset: CGFloat = .newStatusButtonDimension + .defaultSpacing * 4
static let loadingFooterDebounceInterval: TimeInterval = 0.5 static let loadingFooterDebounceInterval: TimeInterval = 0.5
var visibleLoadMoreViews: [LoadMoreView] {
tableView.visibleCells.compactMap { $0.contentView as? LoadMoreView }
}
func setupViewModelBindings() { func setupViewModelBindings() {
viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables) viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables)