Fix scroll position maintenance
This commit is contained in:
parent
6307381375
commit
a47667c15b
|
@ -70,13 +70,15 @@ class StatusListViewController: UITableViewController {
|
|||
self.dataSource.apply($0.snapshot(), animatingDifferences: false) {
|
||||
if
|
||||
let id = self.viewModel.maintainScrollPositionOfStatusID,
|
||||
let indexPath = self.dataSource.indexPath(for: id),
|
||||
let offsetFromNavigationBar = offsetFromNavigationBar {
|
||||
let indexPath = self.dataSource.indexPath(for: id) {
|
||||
self.tableView.scrollToRow(at: indexPath, at: .top, animated: false)
|
||||
|
||||
if let offsetFromNavigationBar = offsetFromNavigationBar {
|
||||
self.tableView.contentOffset.y -= offsetFromNavigationBar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.$loading
|
||||
|
|
|
@ -92,8 +92,10 @@ private extension StatusListViewModel {
|
|||
func determineIfScrollPositionShouldBeMaintained(newStatusSections: [[Status]]) {
|
||||
maintainScrollPositionOfStatusID = nil // clear old value
|
||||
|
||||
let flatStatusIDs = statusIDs.reduce([], +)
|
||||
|
||||
// Maintain scroll position of parent after initial load of context
|
||||
if let contextParentID = contextParentID, statusIDs.reduce([], +) == [contextParentID] {
|
||||
if let contextParentID = contextParentID, flatStatusIDs == [contextParentID] || flatStatusIDs == [] {
|
||||
maintainScrollPositionOfStatusID = contextParentID
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue