Fix account header jumping

This commit is contained in:
Justin Mazzocchi 2021-02-05 20:23:05 -08:00
parent d99e8dd9cc
commit 86cdb4676a
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -321,7 +321,9 @@ private extension TableViewController {
} }
.store(in: &cancellables) .store(in: &cancellables)
viewModel.updates.sink { [weak self] in self?.update($0) }.store(in: &cancellables) viewModel.updates.receive(on: DispatchQueue.main)
.sink { [weak self] in self?.update($0) }
.store(in: &cancellables)
viewModel.events.receive(on: DispatchQueue.main) viewModel.events.receive(on: DispatchQueue.main)
.sink { [weak self] in self?.handle(event: $0) } .sink { [weak self] in self?.handle(event: $0) }
@ -370,15 +372,23 @@ private extension TableViewController {
func update(_ update: CollectionUpdate) { func update(_ update: CollectionUpdate) {
let positionMaintenanceOffset: CGFloat let positionMaintenanceOffset: CGFloat
let preUpdateContentOffsetY = tableView.contentOffset.y
var setPreviousOffset = false
if let itemId = update.maintainScrollPositionItemId, if let itemId = update.maintainScrollPositionItemId,
let indexPath = dataSource.indexPath(itemId: itemId) { let indexPath = dataSource.indexPath(itemId: itemId) {
positionMaintenanceOffset = tableView.rectForRow(at: indexPath).origin.y positionMaintenanceOffset = tableView.rectForRow(at: indexPath).origin.y
- tableView.safeAreaInsets.top - tableView.contentOffset.y - tableView.safeAreaInsets.top - preUpdateContentOffsetY
} else { } else {
positionMaintenanceOffset = 0 positionMaintenanceOffset = 0
} }
if let headerView = tableView.tableHeaderView,
let headerViewWindowFrame = view.window?.convert(headerView.frame, from: headerView),
headerViewWindowFrame.maxY > 0 {
setPreviousOffset = true
}
self.dataSource.apply(update.sections.snapshot(), animatingDifferences: false) { [weak self] in self.dataSource.apply(update.sections.snapshot(), animatingDifferences: false) { [weak self] in
guard let self = self else { return } guard let self = self else { return }
@ -395,6 +405,8 @@ private extension TableViewController {
self.tableView.scrollToRow(at: indexPath, at: .top, animated: false) self.tableView.scrollToRow(at: indexPath, at: .top, animated: false)
self.tableView.contentOffset.y -= positionMaintenanceOffset self.tableView.contentOffset.y -= positionMaintenanceOffset
} else if setPreviousOffset {
self.tableView.contentOffset.y = preUpdateContentOffsetY
} }
} }
} }