Fix scroll position maintenance

This commit is contained in:
Justin Mazzocchi 2020-09-02 00:39:42 -07:00
parent 6307381375
commit a47667c15b
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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
}
}