Prune offscreen rows on new timeline
This commit is contained in:
parent
e78bec8409
commit
a703b7cc0a
|
@ -160,7 +160,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
|||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
|
||||
// TODO: prune offscreen rows
|
||||
pruneOffscreenRows()
|
||||
}
|
||||
|
||||
private func removeTimelineDescriptionCell() {
|
||||
|
@ -170,6 +170,25 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
|||
isShowingTimelineDescription = false
|
||||
}
|
||||
|
||||
private func pruneOffscreenRows() {
|
||||
guard let lastVisibleIndexPath = collectionView.indexPathsForVisibleItems.last else {
|
||||
return
|
||||
}
|
||||
var snapshot = dataSource.snapshot()
|
||||
let items = snapshot.itemIdentifiers(inSection: .statuses)
|
||||
let pageSize = 20
|
||||
let numberOfPagesToPrune = (items.count - lastVisibleIndexPath.row - 1) / pageSize
|
||||
if numberOfPagesToPrune > 0 {
|
||||
let itemsToRemove = Array(items.suffix(numberOfPagesToPrune * pageSize))
|
||||
snapshot.deleteItems(itemsToRemove)
|
||||
}
|
||||
dataSource.apply(snapshot, animatingDifferences: false)
|
||||
|
||||
if case .status(id: let id, state: _) = snapshot.itemIdentifiers(inSection: .statuses).last {
|
||||
older = .before(id: id, count: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func refresh() {
|
||||
Task {
|
||||
await controller.loadNewer()
|
||||
|
|
Loading…
Reference in New Issue