forked from shadowfacts/Tusker
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:
parent
2801f65e67
commit
868df25417
|
@ -160,7 +160,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
|||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
|
||||
pruneOffscreenRows()
|
||||
// pruneOffscreenRows()
|
||||
}
|
||||
|
||||
private func removeTimelineDescriptionCell() {
|
||||
|
@ -170,27 +170,28 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
|||
isShowingTimelineDescription = false
|
||||
}
|
||||
|
||||
private func pruneOffscreenRows() {
|
||||
guard let lastVisibleIndexPath = collectionView.indexPathsForVisibleItems.last else {
|
||||
return
|
||||
}
|
||||
var snapshot = dataSource.snapshot()
|
||||
guard snapshot.indexOfSection(.statuses) != nil else {
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
// private func pruneOffscreenRows() {
|
||||
// guard let lastVisibleIndexPath = collectionView.indexPathsForVisibleItems.last else {
|
||||
// return
|
||||
// }
|
||||
// var snapshot = dataSource.snapshot()
|
||||
// guard snapshot.indexOfSection(.statuses) != nil else {
|
||||
// return
|
||||
// }
|
||||
// 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 {
|
||||
|
|
Loading…
Reference in New Issue