mirror of
https://github.com/metabolist/metatext.git
synced 2025-01-09 21:45:24 +00:00
Improve position maintenance
This commit is contained in:
parent
d42642c079
commit
a672e97441
1 changed files with 10 additions and 14 deletions
|
@ -275,21 +275,20 @@ private extension TableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(_ update: CollectionUpdate) {
|
func update(_ update: CollectionUpdate) {
|
||||||
var offsetFromNavigationBar: CGFloat?
|
let positionMaintenanceOffset: CGFloat
|
||||||
|
|
||||||
if
|
if let itemId = update.maintainScrollPositionItemId,
|
||||||
let itemId = update.maintainScrollPositionItemId,
|
let indexPath = dataSource.indexPath(itemId: itemId) {
|
||||||
let indexPath = dataSource.indexPath(itemId: itemId),
|
positionMaintenanceOffset = tableView.rectForRow(at: indexPath).origin.y
|
||||||
let navigationBar = navigationController?.navigationBar {
|
- tableView.safeAreaInsets.top - tableView.contentOffset.y
|
||||||
let navigationBarMaxY = tableView.convert(navigationBar.bounds, from: navigationBar).maxY
|
} else {
|
||||||
offsetFromNavigationBar = tableView.rectForRow(at: indexPath).origin.y - navigationBarMaxY
|
positionMaintenanceOffset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
self.dataSource.apply(update.items.snapshot(), animatingDifferences: false) { [weak self] in
|
self.dataSource.apply(update.items.snapshot(), animatingDifferences: false) { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
||||||
if
|
if let itemId = update.maintainScrollPositionItemId,
|
||||||
let itemId = update.maintainScrollPositionItemId,
|
|
||||||
let indexPath = self.dataSource.indexPath(itemId: itemId) {
|
let indexPath = self.dataSource.indexPath(itemId: itemId) {
|
||||||
if update.shouldAdjustContentInset {
|
if update.shouldAdjustContentInset {
|
||||||
self.tableView.contentInset.bottom = max(
|
self.tableView.contentInset.bottom = max(
|
||||||
|
@ -299,10 +298,7 @@ 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
|
||||||
if let offsetFromNavigationBar = offsetFromNavigationBar {
|
|
||||||
self.tableView.contentOffset.y -= offsetFromNavigationBar
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue