From 1a767ff9103ae5b7fae2e3a5e78969b41819b786 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 13 Nov 2022 14:29:56 -0500 Subject: [PATCH] Fix crash when opening My Profile on iPad --- .../Profile/ProfileStatusesViewController.swift | 16 ++++++++-------- .../Screens/Profile/ProfileViewController.swift | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index 92e744801a..995a499140 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -106,13 +106,6 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie } } .store(in: &cancellables) - - var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections([.header, .pinned, .statuses]) - snapshot.appendItems([.header(accountID)], toSection: .header) - dataSource.apply(snapshot, animatingDifferences: false) - - state = .setupInitialSnapshot } private func createDataSource() -> UICollectionViewDiffableDataSource { @@ -181,11 +174,18 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie private func load() async { guard isViewLoaded, let accountID, - state == .setupInitialSnapshot, + state == .unloaded, mastodonController.persistentContainer.account(for: accountID) != nil else { return } + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([.header, .pinned, .statuses]) + snapshot.appendItems([.header(accountID)], toSection: .header) + await apply(snapshot, animatingDifferences: false) + + state = .setupInitialSnapshot + await controller.loadInitial() await tryLoadPinned() diff --git a/Tusker/Screens/Profile/ProfileViewController.swift b/Tusker/Screens/Profile/ProfileViewController.swift index 2fdc686543..014d35f7a3 100644 --- a/Tusker/Screens/Profile/ProfileViewController.swift +++ b/Tusker/Screens/Profile/ProfileViewController.swift @@ -152,6 +152,7 @@ class ProfileViewController: UIViewController { assert(!animated) // if old doesn't exist, we're selecting the initial view controller, so moving the header around isn't necessary new.initialHeaderMode = .createView + new.view.translatesAutoresizingMaskIntoConstraints = false embedChild(new) self.currentIndex = index state = .idle @@ -221,6 +222,7 @@ class ProfileViewController: UIViewController { new.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: additionalHeightNeededToMatchContentOffset, right: 0) } + new.view.translatesAutoresizingMaskIntoConstraints = false embedChild(new) new.view.transform = CGAffineTransform(translationX: direction * view.bounds.width, y: yTranslationToMatchOldContentOffset) @@ -256,6 +258,7 @@ class ProfileViewController: UIViewController { animator.startAnimation() } else { old.removeViewAndController() + new.view.translatesAutoresizingMaskIntoConstraints = false embedChild(new) completion?(true) }