Fix notifications scrolling to top when refreshing

This commit is contained in:
Shadowfacts 2023-05-07 19:46:15 -04:00
parent 7449688bfe
commit eac5a4c9a6
2 changed files with 17 additions and 0 deletions

View File

@ -355,8 +355,24 @@ extension NotificationsCollectionViewController {
} }
func handlePrependItems(_ timelineItems: [NotificationGroup]) async { func handlePrependItems(_ timelineItems: [NotificationGroup]) async {
let topItem = dataSource.snapshot().itemIdentifiers(inSection: .notifications).first
// we always replace all, because new items are merged with existing ones // we always replace all, because new items are merged with existing ones
await handleReplaceAllItems(timelineItems) await handleReplaceAllItems(timelineItems)
// preserve the scroll position
// todo: this won't work for cmd+r when not at top
if let topID = topItem?.group?.notifications.first?.id {
// the exact item may have changed, due to merging
let newTopGroup = timelineItems.first {
$0.notifications.contains {
$0.id == topID
}
}!
if let newTopIndexPath = dataSource.indexPath(for: .group(newTopGroup)) {
collectionView.scrollToItem(at: newTopIndexPath, at: .top, animated: false)
}
}
} }
func loadOlder() async throws -> [NotificationGroup] { func loadOlder() async throws -> [NotificationGroup] {

View File

@ -153,6 +153,7 @@ extension TimelineLikeCollectionViewController {
} }
await apply(snapshot, animatingDifferences: false) await apply(snapshot, animatingDifferences: false)
// todo: this won't work for cmd+r when not at top
if let first, if let first,
let indexPath = dataSource.indexPath(for: first) { let indexPath = dataSource.indexPath(for: first) {
// TODO: i can't tell if this actually works or not // TODO: i can't tell if this actually works or not