Fix back pagination (#432)

* Use pagination and start items for view state.

isBackPaginating and canBackPaginate are updated each time the timeline is rebuilt

* Update some timeline snapshots

The top section has gone, which has altered the layout slightly.
This commit is contained in:
Doug
2023-01-11 09:11:36 +00:00
committed by GitHub
parent 3d1266ca25
commit 08b333839a
24 changed files with 54 additions and 72 deletions
@@ -49,6 +49,7 @@ struct RoomScreenViewState: BindableState {
var roomTitle = ""
var roomAvatar: UIImage?
var items: [RoomTimelineViewProvider] = []
var canBackPaginate = true
var isBackPaginating = false
var showLoading = false
var bindings: RoomScreenViewStateBindings
@@ -61,10 +61,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
self.state.items[viewIndex] = timelineViewFactory.buildTimelineViewFor(timelineItem: timelineItem)
case .startedBackPaginating:
self.state.isBackPaginating = true
case .finishedBackPaginating:
self.state.isBackPaginating = false
case .canBackPaginate(let canBackPaginate):
if self.state.canBackPaginate != canBackPaginate {
self.state.canBackPaginate = canBackPaginate
}
case .isBackPaginating(let isBackPaginating):
if self.state.isBackPaginating != isBackPaginating {
self.state.isBackPaginating = isBackPaginating
}
}
}
.store(in: &cancellables)
@@ -61,6 +61,9 @@ class TimelineTableViewController: UIViewController {
}
}
/// Whether or not the timeline has more messages to back paginate.
var canBackPaginate = true
/// Whether or not the timeline is waiting for more messages to be added to the top.
var isBackPaginating = false {
didSet {
@@ -334,7 +337,8 @@ class TimelineTableViewController: UIViewController {
///
/// Prefer not to call this directly, instead using ``paginateBackwardsPublisher`` to throttle requests.
private func paginateBackwardsIfNeeded() {
guard !isBackPaginating,
guard canBackPaginate,
!isBackPaginating,
!hasPendingUpdates,
tableView.contentOffset.y < tableView.visibleSize.height * 2.0
else { return }
@@ -59,6 +59,9 @@ struct TimelineView: UIViewControllerRepresentable {
if tableViewController.timelineItems != context.viewState.items {
tableViewController.timelineItems = context.viewState.items
}
if tableViewController.canBackPaginate != context.viewState.canBackPaginate {
tableViewController.canBackPaginate = context.viewState.canBackPaginate
}
if tableViewController.isBackPaginating != context.viewState.isBackPaginating {
tableViewController.isBackPaginating = context.viewState.isBackPaginating
}