forked from shadowfacts/Tusker
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,7 +545,7 @@ 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])
|
||||||
|
@ -554,7 +554,6 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
stateRestorationLogger.fault("TimelineViewController: restored statuses, but couldn't find center ID")
|
stateRestorationLogger.fault("TimelineViewController: restored statuses, but couldn't find center ID")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func restoreStatusesFromMarkerPosition() async -> Bool {
|
private func restoreStatusesFromMarkerPosition() async -> Bool {
|
||||||
|
|
Loading…
Reference in New Issue