diff --git a/View Controllers/StatusListViewController.swift b/View Controllers/StatusListViewController.swift index 0f2328a..10e2215 100644 --- a/View Controllers/StatusListViewController.swift +++ b/View Controllers/StatusListViewController.swift @@ -70,10 +70,12 @@ 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) - self.tableView.contentOffset.y -= offsetFromNavigationBar + + if let offsetFromNavigationBar = offsetFromNavigationBar { + self.tableView.contentOffset.y -= offsetFromNavigationBar + } } } } diff --git a/ViewModels/Sources/ViewModels/StatusListViewModel.swift b/ViewModels/Sources/ViewModels/StatusListViewModel.swift index 88e2d6d..bcb845c 100644 --- a/ViewModels/Sources/ViewModels/StatusListViewModel.swift +++ b/ViewModels/Sources/ViewModels/StatusListViewModel.swift @@ -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 } }