mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Don't query visible cells on scroll
This commit is contained in:
parent
5c179457e5
commit
33494b9f76
1 changed files with 13 additions and 4 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue