Disable pruning offscreen rows in new timelines

I don't think this is actually necessary, the system should kill us
often enough that the amount of items in the data source doesn't become
unmanageable.

Making modifications to the data source in viewDidDisappear was causing
the collection view's contentOffset to change to be scrolled to top
(roughly) when the view became visible again.

Disabling it also fixes several issues caused by updating the data
source even when there were no changes.

Closes #193
Closes #192
Closes #187
Closes #186
This commit is contained in:
Shadowfacts 2022-10-28 18:56:18 -04:00
parent 2801f65e67
commit 868df25417
1 changed files with 23 additions and 22 deletions

View File

@ -160,7 +160,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
override func viewDidDisappear(_ animated: Bool) { override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated) super.viewDidDisappear(animated)
pruneOffscreenRows() // pruneOffscreenRows()
} }
private func removeTimelineDescriptionCell() { private func removeTimelineDescriptionCell() {
@ -170,27 +170,28 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
isShowingTimelineDescription = false isShowingTimelineDescription = false
} }
private func pruneOffscreenRows() { // private func pruneOffscreenRows() {
guard let lastVisibleIndexPath = collectionView.indexPathsForVisibleItems.last else { // guard let lastVisibleIndexPath = collectionView.indexPathsForVisibleItems.last else {
return // return
} // }
var snapshot = dataSource.snapshot() // var snapshot = dataSource.snapshot()
guard snapshot.indexOfSection(.statuses) != nil else { // guard snapshot.indexOfSection(.statuses) != nil else {
return // return
} // }
let items = snapshot.itemIdentifiers(inSection: .statuses) // let items = snapshot.itemIdentifiers(inSection: .statuses)
let pageSize = 20 // let pageSize = 20
let numberOfPagesToPrune = (items.count - lastVisibleIndexPath.row - 1) / pageSize // let numberOfPagesToPrune = (items.count - lastVisibleIndexPath.row - 1) / pageSize
if numberOfPagesToPrune > 0 { // if numberOfPagesToPrune > 0 {
let itemsToRemove = Array(items.suffix(numberOfPagesToPrune * pageSize)) // let itemsToRemove = Array(items.suffix(numberOfPagesToPrune * pageSize))
snapshot.deleteItems(itemsToRemove) // snapshot.deleteItems(itemsToRemove)
} //
dataSource.apply(snapshot, animatingDifferences: false) // dataSource.apply(snapshot, animatingDifferences: false)
//
if case .status(id: let id, state: _) = snapshot.itemIdentifiers(inSection: .statuses).last { // if case .status(id: let id, state: _) = snapshot.itemIdentifiers(inSection: .statuses).last {
older = .before(id: id, count: nil) // older = .before(id: id, count: nil)
} // }
} // }
// }
@objc func refresh() { @objc func refresh() {
Task { Task {