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) {
|
override func viewDidDisappear(_ animated: Bool) {
|
||||||
super.viewDidDisappear(animated)
|
super.viewDidDisappear(animated)
|
||||||
|
|
||||||
// TODO: prune offscreen rows
|
pruneOffscreenRows()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func removeTimelineDescriptionCell() {
|
private func removeTimelineDescriptionCell() {
|
||||||
|
@ -170,6 +170,25 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
isShowingTimelineDescription = false
|
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() {
|
@objc func refresh() {
|
||||||
Task {
|
Task {
|
||||||
await controller.loadNewer()
|
await controller.loadNewer()
|
||||||
|
|
Loading…
Reference in New Issue