From 811aac35d7c35770bb911dd1890216650217ad2e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 29 Nov 2022 10:29:40 -0500 Subject: [PATCH] Fix timeline statuses not getting deselected when entering split nav Closes #275 --- Tusker.xcodeproj/project.pbxproj | 4 ++++ .../Screens/Timeline/TimelineViewController.swift | 2 +- .../Utilities/CollectionViewController.swift | 13 +++++++++++++ .../Utilities/SplitNavigationController.swift | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 Tusker/Screens/Utilities/CollectionViewController.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index dd59bd7f..d6e1a296 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -49,6 +49,7 @@ D61F758D2933C69C00C0B37F /* StatusUpdatedNotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61F758B2933C69C00C0B37F /* StatusUpdatedNotificationTableViewCell.swift */; }; D61F758E2933C69C00C0B37F /* StatusUpdatedNotificationTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D61F758C2933C69C00C0B37F /* StatusUpdatedNotificationTableViewCell.xib */; }; D61F759029353B4300C0B37F /* FileManager+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61F758F29353B4300C0B37F /* FileManager+Size.swift */; }; + D61F759229365C6C00C0B37F /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61F759129365C6C00C0B37F /* CollectionViewController.swift */; }; D620483423D3801D008A63EF /* LinkTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D620483323D3801D008A63EF /* LinkTextView.swift */; }; D620483623D38075008A63EF /* ContentTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D620483523D38075008A63EF /* ContentTextView.swift */; }; D620483823D38190008A63EF /* StatusContentTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D620483723D38190008A63EF /* StatusContentTextView.swift */; }; @@ -414,6 +415,7 @@ D61F758B2933C69C00C0B37F /* StatusUpdatedNotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusUpdatedNotificationTableViewCell.swift; sourceTree = ""; }; D61F758C2933C69C00C0B37F /* StatusUpdatedNotificationTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusUpdatedNotificationTableViewCell.xib; sourceTree = ""; }; D61F758F29353B4300C0B37F /* FileManager+Size.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Size.swift"; sourceTree = ""; }; + D61F759129365C6C00C0B37F /* CollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = ""; }; D620483323D3801D008A63EF /* LinkTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkTextView.swift; sourceTree = ""; }; D620483523D38075008A63EF /* ContentTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentTextView.swift; sourceTree = ""; }; D620483723D38190008A63EF /* StatusContentTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusContentTextView.swift; sourceTree = ""; }; @@ -1357,6 +1359,7 @@ D6DFC69D242C490400ACC392 /* TrackpadScrollGestureRecognizer.swift */, D6B8DB332182A59300424AF7 /* UIAlertController+Visibility.swift */, D6C693FD2162FEEA007D6A6D /* UIViewController+Children.swift */, + D61F759129365C6C00C0B37F /* CollectionViewController.swift */, ); path = Utilities; sourceTree = ""; @@ -1800,6 +1803,7 @@ D6412B0324AFF6A600F5412E /* TabBarScrollableViewController.swift in Sources */, D6093FB725BE0CF3004811E6 /* TrendHistoryView.swift in Sources */, D6EBF01723C55E0D00AE061B /* UISceneSession+MastodonController.swift in Sources */, + D61F759229365C6C00C0B37F /* CollectionViewController.swift in Sources */, 04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */, D68E525D24A3E8F00054355A /* SearchViewController.swift in Sources */, D6AEBB412321642700E5038B /* SendMesasgeActivity.swift in Sources */, diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 58dea58f..28037cb0 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -10,7 +10,7 @@ import UIKit import Pachyderm import Combine -class TimelineViewController: UIViewController, TimelineLikeCollectionViewController, RefreshableViewController { +class TimelineViewController: UIViewController, TimelineLikeCollectionViewController, CollectionViewController, RefreshableViewController { let timeline: Timeline weak var mastodonController: MastodonController! diff --git a/Tusker/Screens/Utilities/CollectionViewController.swift b/Tusker/Screens/Utilities/CollectionViewController.swift new file mode 100644 index 00000000..b1a084c2 --- /dev/null +++ b/Tusker/Screens/Utilities/CollectionViewController.swift @@ -0,0 +1,13 @@ +// +// CollectionViewController.swift +// Tusker +// +// Created by Shadowfacts on 11/29/22. +// Copyright © 2022 Shadowfacts. All rights reserved. +// + +import UIKit + +protocol CollectionViewController: UIViewController { + var collectionView: UICollectionView! { get } +} diff --git a/Tusker/Screens/Utilities/SplitNavigationController.swift b/Tusker/Screens/Utilities/SplitNavigationController.swift index adaa2e99..78dc083f 100644 --- a/Tusker/Screens/Utilities/SplitNavigationController.swift +++ b/Tusker/Screens/Utilities/SplitNavigationController.swift @@ -56,7 +56,7 @@ class SplitNavigationController: UIViewController { let selectedIndexPath = tableVC.tableView.indexPathForSelectedRow { tableVC.tableView.deselectRow(at: selectedIndexPath, animated: true) } else if let sender = sender as? UIViewController, - let collectionView = sender.view as? UICollectionView { + let collectionView = (sender as? CollectionViewController)?.collectionView ?? sender.view as? UICollectionView { // the collection view's animation speed is weirdly fast, so we do it slower UIView.animate(withDuration: 0.5, delay: 0) { collectionView.indexPathsForSelectedItems?.forEach { collectionView.deselectItem(at: $0, animated: false) }