Fix crash when refreshing profile before it has loaded

This commit is contained in:
Shadowfacts 2022-10-31 14:27:37 -04:00
parent 95f9fad673
commit a18dfc38af
1 changed files with 9 additions and 3 deletions

View File

@ -100,7 +100,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
}
case .loading:
break
case .loaded, .addedHeader:
case .loaded, .setupInitialSnapshot:
var snapshot = dataSource.snapshot()
snapshot.reconfigureItems([.header(id)])
dataSource.apply(snapshot, animatingDifferences: true)
@ -183,7 +183,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
snapshot.appendItems([.header(accountID)], toSection: .header)
await apply(snapshot, animatingDifferences: false)
state = .addedHeader
state = .setupInitialSnapshot
await controller.loadInitial()
await tryLoadPinned()
@ -225,6 +225,12 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
}
@objc func refresh() {
guard case .loaded = state else {
#if !targetEnvironment(macCatalyst)
collectionView.refreshControl?.endRefreshing()
#endif
return
}
Task {
// TODO: coalesce these data source updates
// TODO: refresh profile
@ -242,7 +248,7 @@ extension ProfileStatusesViewController {
enum State {
case unloaded
case loading
case addedHeader
case setupInitialSnapshot
case loaded
}
}