Fix notifications scrolling to top when refreshing
This commit is contained in:
parent
7449688bfe
commit
eac5a4c9a6
|
@ -355,8 +355,24 @@ extension NotificationsCollectionViewController {
|
|||
}
|
||||
|
||||
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
|
||||
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] {
|
||||
|
|
|
@ -153,6 +153,7 @@ extension TimelineLikeCollectionViewController {
|
|||
}
|
||||
await apply(snapshot, animatingDifferences: false)
|
||||
|
||||
// todo: this won't work for cmd+r when not at top
|
||||
if let first,
|
||||
let indexPath = dataSource.indexPath(for: first) {
|
||||
// TODO: i can't tell if this actually works or not
|
||||
|
|
Loading…
Reference in New Issue