mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-29 11:31:02 +00:00
Remove prefetching
This commit is contained in:
parent
ca49611df5
commit
73fc2cd599
1 changed files with 8 additions and 21 deletions
|
@ -42,7 +42,6 @@ class TableViewController: UITableViewController {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
tableView.dataSource = dataSource
|
tableView.dataSource = dataSource
|
||||||
tableView.prefetchDataSource = self
|
|
||||||
tableView.cellLayoutMarginsFollowReadableWidth = true
|
tableView.cellLayoutMarginsFollowReadableWidth = true
|
||||||
tableView.tableFooterView = UIView()
|
tableView.tableFooterView = UIView()
|
||||||
tableView.contentInset.bottom = Self.bottomInset
|
tableView.contentInset.bottom = Self.bottomInset
|
||||||
|
@ -98,7 +97,14 @@ class TableViewController: UITableViewController {
|
||||||
heightCache[item] = cell.frame.height
|
heightCache[item] = cell.frame.height
|
||||||
cellHeightCaches[tableView.frame.width] = heightCache
|
cellHeightCaches[tableView.frame.width] = heightCache
|
||||||
|
|
||||||
paginateIfLastIndexPathPresent(indexPaths: [indexPath])
|
if !loading,
|
||||||
|
indexPath.section == dataSource.numberOfSections(in: tableView) - 1,
|
||||||
|
indexPath.row == dataSource.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1,
|
||||||
|
let maxId = viewModel.preferLastPresentIdOverNextPageMaxId
|
||||||
|
? dataSource.itemIdentifier(for: indexPath)?.itemId
|
||||||
|
: viewModel.nextPageMaxId {
|
||||||
|
viewModel.request(maxId: maxId, minId: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||||
|
@ -124,12 +130,6 @@ class TableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TableViewController: UITableViewDataSourcePrefetching {
|
|
||||||
func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
|
|
||||||
paginateIfLastIndexPathPresent(indexPaths: indexPaths)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension TableViewController {
|
extension TableViewController {
|
||||||
func report(reportViewModel: ReportViewModel) {
|
func report(reportViewModel: ReportViewModel) {
|
||||||
let reportViewController = ReportViewController(viewModel: reportViewModel)
|
let reportViewController = ReportViewController(viewModel: reportViewModel)
|
||||||
|
@ -451,18 +451,5 @@ private extension TableViewController {
|
||||||
|
|
||||||
present(activityViewController, animated: true, completion: nil)
|
present(activityViewController, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func paginateIfLastIndexPathPresent(indexPaths: [IndexPath]) {
|
|
||||||
guard !loading,
|
|
||||||
let indexPath = indexPaths.last,
|
|
||||||
indexPath.section == dataSource.numberOfSections(in: tableView) - 1,
|
|
||||||
indexPath.row == dataSource.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1,
|
|
||||||
let maxId = viewModel.preferLastPresentIdOverNextPageMaxId
|
|
||||||
? dataSource.itemIdentifier(for: indexPath)?.itemId
|
|
||||||
: viewModel.nextPageMaxId
|
|
||||||
else { return }
|
|
||||||
|
|
||||||
viewModel.request(maxId: maxId, minId: nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// swiftlint:enable file_length
|
// swiftlint:enable file_length
|
||||||
|
|
Loading…
Reference in a new issue