Fix timeline momentum scrolling stopping due to adding footer section

This commit is contained in:
Shadowfacts 2021-06-26 15:53:58 -04:00
parent 5f9fe505d5
commit dc1ea1bed9
2 changed files with 6 additions and 6 deletions

View File

@ -107,8 +107,8 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
var snapshot = Snapshot()
snapshot.appendSections([.statuses])
snapshot.appendItems(statuses.map { .status(id: $0.id, state: .unknown) })
snapshot.appendSections([.statuses, .footer])
snapshot.appendItems(statuses.map { .status(id: $0.id, state: .unknown) }, toSection: .statuses)
completion(.success(snapshot))
}
}
@ -122,13 +122,12 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
}
guard !Preferences.shared.disableInfiniteScrolling || didConfirmLoadMore else {
guard !currentSnapshot.sectionIdentifiers.contains(.footer) || !currentSnapshot.itemIdentifiers(inSection: .footer).contains(.confirmLoadMore) else {
guard !currentSnapshot.itemIdentifiers(inSection: .footer).contains(.confirmLoadMore) else {
// todo: need something more accurate than "success"/"failure"
completion(.success(currentSnapshot))
return
}
var snapshot = currentSnapshot
snapshot.appendSections([.footer])
snapshot.appendItems([.confirmLoadMore], toSection: .footer)
self.dataSource.apply(snapshot)
completion(.success(snapshot))
@ -148,7 +147,7 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
var snapshot = currentSnapshot
snapshot.appendItems(statuses.map { .status(id: $0.id, state: .unknown) }, toSection: .statuses)
snapshot.deleteSections([.footer])
snapshot.deleteItems([.confirmLoadMore])
completion(.success(snapshot))
}
}

View File

@ -156,7 +156,8 @@ class DiffableTimelineLikeTableViewController<Section: Hashable & CaseIterable,
// this assumes that indexPathsForVisibleRows is always in order
lastLastVisibleRow = tableView.indexPathsForVisibleRows?.last
if indexPath.section == tableView.numberOfSections - 1,
let orderedContentSections = dataSource.snapshot().sectionIdentifiers.filter { timelineContentSections().contains($0) }
if indexPath.section == orderedContentSections.count - 1,
indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
loadOlder()