From 868df254177371ee059fa43b0844514081fbaf86 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 28 Oct 2022 18:56:18 -0400 Subject: [PATCH] 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 --- .../Timeline/TimelineViewController.swift | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index b40c2076..1b343078 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -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 {