From b515664db335dd0d932301cf438c98a6ffe4e977 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 30 Nov 2022 16:33:28 -0500 Subject: [PATCH] Fix creating list on iPad overwriting previous item navigation stack --- .../Main/MainSidebarViewController.swift | 34 ++----------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 2878050a..c336387d 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -213,23 +213,7 @@ class MainSidebarViewController: UIViewController { exploreSnapshot.expand([.listsHeader]) exploreSnapshot.append(lists.map { .list($0) }, to: .listsHeader) exploreSnapshot.append([.addList], to: .listsHeader) - var selectedItem: Item? - if let selectedIndexPath = collectionView.indexPathsForSelectedItems?.first, - let item = dataSource.itemIdentifier(for: selectedIndexPath) { - if case .list(let list) = item, - let newList = lists.first(where: { $0.id == list.id }) { - selectedItem = .list(newList) - } else { - selectedItem = item - } - } - - self.dataSource.apply(exploreSnapshot, to: .lists) { - if let selectedItem, - let indexPath = self.dataSource.indexPath(for: selectedItem) { - self.collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically) - } - } + self.dataSource.apply(exploreSnapshot, to: .lists) } @MainActor @@ -255,8 +239,6 @@ class MainSidebarViewController: UIViewController { } @objc private func reloadSavedHashtags() { - let selected = collectionView.indexPathsForSelectedItems?.first - var hashtagsSnapshot = NSDiffableDataSourceSectionSnapshot() hashtagsSnapshot.append([.savedHashtagsHeader]) hashtagsSnapshot.expand([.savedHashtagsHeader]) @@ -265,16 +247,10 @@ class MainSidebarViewController: UIViewController { } hashtagsSnapshot.append(hashtags, to: .savedHashtagsHeader) hashtagsSnapshot.append([.addSavedHashtag], to: .savedHashtagsHeader) - self.dataSource.apply(hashtagsSnapshot, to: .savedHashtags, animatingDifferences: false) { - if let selected = selected { - self.collectionView.selectItem(at: selected, animated: false, scrollPosition: .centeredVertically) - } - } + self.dataSource.apply(hashtagsSnapshot, to: .savedHashtags) } @objc private func reloadSavedInstances() { - let selected = collectionView.indexPathsForSelectedItems?.first - var instancesSnapshot = NSDiffableDataSourceSectionSnapshot() instancesSnapshot.append([.savedInstancesHeader]) instancesSnapshot.expand([.savedInstancesHeader]) @@ -283,11 +259,7 @@ class MainSidebarViewController: UIViewController { } instancesSnapshot.append(instances, to: .savedInstancesHeader) instancesSnapshot.append([.addSavedInstance], to: .savedInstancesHeader) - self.dataSource.apply(instancesSnapshot, to: .savedInstances, animatingDifferences: false) { - if let selected = selected { - self.collectionView.selectItem(at: selected, animated: false, scrollPosition: .centeredVertically) - } - } + self.dataSource.apply(instancesSnapshot, to: .savedInstances) } @objc private func preferencesChanged() {