Fix timeline state restoration not returning to correct scroll position in certain circumstances
All of the work done by the restoreInitial callback needs to be async, so that when the TimelineLikeController signals that the loading indicator should be removed, the collection view is in the right place. Closes #439
This commit is contained in:
parent
e09935125f
commit
eb61043867
|
@ -420,7 +420,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
let hasStatusesToRestore = await loadStatusesToRestore(position: position)
|
let hasStatusesToRestore = await loadStatusesToRestore(position: position)
|
||||||
if hasStatusesToRestore {
|
if hasStatusesToRestore {
|
||||||
applyItemsToRestore(position: position)
|
await applyItemsToRestore(position: position)
|
||||||
loaded = true
|
loaded = true
|
||||||
}
|
}
|
||||||
case .mastodon:
|
case .mastodon:
|
||||||
|
@ -443,7 +443,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
position.centerStatusID = centerStatusID
|
position.centerStatusID = centerStatusID
|
||||||
let hasStatusesToRestore = await loadStatusesToRestore(position: position)
|
let hasStatusesToRestore = await loadStatusesToRestore(position: position)
|
||||||
if hasStatusesToRestore {
|
if hasStatusesToRestore {
|
||||||
applyItemsToRestore(position: position)
|
await applyItemsToRestore(position: position)
|
||||||
}
|
}
|
||||||
mastodonController.persistentContainer.viewContext.delete(position)
|
mastodonController.persistentContainer.viewContext.delete(position)
|
||||||
}
|
}
|
||||||
|
@ -532,7 +532,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func applyItemsToRestore(position: TimelinePosition) {
|
private func applyItemsToRestore(position: TimelinePosition) async {
|
||||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||||
snapshot.appendSections([.statuses])
|
snapshot.appendSections([.statuses])
|
||||||
let statusIDs = position.statusIDs
|
let statusIDs = position.statusIDs
|
||||||
|
@ -545,14 +545,13 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
"statusIDs": position.statusIDs
|
"statusIDs": position.statusIDs
|
||||||
]
|
]
|
||||||
SentrySDK.addBreadcrumb(crumb)
|
SentrySDK.addBreadcrumb(crumb)
|
||||||
dataSource.apply(snapshot, animatingDifferences: false) {
|
await apply(snapshot, animatingDifferences: false)
|
||||||
if let centerStatusID,
|
if let centerStatusID,
|
||||||
let index = statusIDs.firstIndex(of: centerStatusID) {
|
let index = statusIDs.firstIndex(of: centerStatusID) {
|
||||||
self.scrollToItem(item: items[index])
|
self.scrollToItem(item: items[index])
|
||||||
stateRestorationLogger.info("TimelineViewController: restored statuses with center ID \(centerStatusID)")
|
stateRestorationLogger.info("TimelineViewController: restored statuses with center ID \(centerStatusID)")
|
||||||
} else {
|
} else {
|
||||||
stateRestorationLogger.fault("TimelineViewController: restored statuses, but couldn't find center ID")
|
stateRestorationLogger.fault("TimelineViewController: restored statuses, but couldn't find center ID")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue