Fix offscreen row pruning removing all rows from profile statuses
This commit is contained in:
parent
6ba5f70615
commit
804fdb439d
|
@ -52,6 +52,8 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
|||
return NSLocalizedString("Refresh Statuses", comment: "refresh statuses command discoverability title")
|
||||
}
|
||||
|
||||
// MARK: - DiffableTimelineLikeTableViewController
|
||||
|
||||
override func cellProvider(_ tableView: UITableView, _ indexPath: IndexPath, _ item: Item) -> UITableViewCell? {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "statusCell", for: indexPath) as! TimelineStatusTableViewCell
|
||||
|
||||
|
|
|
@ -67,8 +67,7 @@ class DiffableTimelineLikeTableViewController<Section: Hashable & CaseIterable,
|
|||
}
|
||||
|
||||
private func pruneOffscreenRows() {
|
||||
guard let lastVisibleRow = lastLastVisibleRow,
|
||||
lastVisibleRow.section < tableView.numberOfSections else {
|
||||
guard let lastVisibleRow = tableView.indexPathsForVisibleRows?.last else {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -77,33 +76,24 @@ class DiffableTimelineLikeTableViewController<Section: Hashable & CaseIterable,
|
|||
let lastVisibleRowSection = snapshot.sectionIdentifiers[lastVisibleRow.section]
|
||||
|
||||
let contentSections = snapshot.sectionIdentifiers.filter { timelineContentSections().contains($0) }
|
||||
let contentSectionIndices = contentSections.compactMap(snapshot.indexOfSection(_:))
|
||||
let maxContentSectionIndex = contentSectionIndices.max()!
|
||||
|
||||
guard let lastVisibleContentSectionIndex = contentSections.lastIndex(of: lastVisibleRowSection) else {
|
||||
if lastVisibleRow.section < maxContentSectionIndex {
|
||||
return
|
||||
}
|
||||
|
||||
if lastVisibleContentSectionIndex < contentSections.count - 1 {
|
||||
// there are more content sections below the current last visible one
|
||||
|
||||
let sectionsToRemove = contentSections[lastVisibleContentSectionIndex...]
|
||||
snapshot.deleteSections(Array(sectionsToRemove))
|
||||
|
||||
let itemsToRemove = sectionsToRemove.filter {
|
||||
snapshot.indexOfSection($0) != nil
|
||||
}.flatMap(snapshot.itemIdentifiers(inSection:))
|
||||
willRemoveItems(itemsToRemove)
|
||||
} else if lastVisibleContentSectionIndex == contentSections.count - 1 {
|
||||
} else if lastVisibleRow.section == maxContentSectionIndex {
|
||||
let items = snapshot.itemIdentifiers(inSection: lastVisibleRowSection)
|
||||
|
||||
if lastVisibleRow.row < items.count - pageSize {
|
||||
let itemsToRemove = Array(items.suffix(pageSize))
|
||||
let numberOfPagesToPrune = (items.count - lastVisibleRow.row - 1) / pageSize
|
||||
if numberOfPagesToPrune > 0 {
|
||||
let itemsToRemove = Array(items.suffix(numberOfPagesToPrune * pageSize))
|
||||
snapshot.deleteItems(itemsToRemove)
|
||||
|
||||
willRemoveItems(itemsToRemove)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// unreachable
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue