From a18dfc38aff3f436f1135e64cd0d06312ccad9ae Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 31 Oct 2022 14:27:37 -0400 Subject: [PATCH] Fix crash when refreshing profile before it has loaded --- .../Profile/ProfileStatusesViewController.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index 99a38341..5eb3ad88 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -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 } }