From e85d194e5fd23c53276ba9834057e91b76a14984 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 16 Jan 2023 17:47:56 -0500 Subject: [PATCH] Make table and collection view focusable --- .../xcshareddata/xcschemes/Tusker.xcscheme | 4 ++++ .../Account List/AccountListViewController.swift | 1 + .../Asset Picker/AssetCollectionViewController.swift | 1 + .../AssetCollectionsListViewController.swift | 2 ++ .../Bookmarks/BookmarksTableViewController.swift | 3 ++- .../Conversation/ConversationTableViewController.swift | 4 ++-- .../Explore/AddSavedHashtagViewController.swift | 1 + Tusker/Screens/Explore/ExploreViewController.swift | 1 + .../Explore/ProfileDirectoryViewController.swift | 1 + .../Explore/TrendingHashtagsViewController.swift | 1 + .../Screens/Explore/TrendingLinksViewController.swift | 1 + .../Explore/TrendingStatusesViewController.swift | 1 + .../Screens/Lists/EditListAccountsViewController.swift | 1 + .../NotificationsTableViewController.swift | 2 ++ .../Profile/ProfileStatusesViewController.swift | 10 ++++++++++ .../Screens/Search/SearchResultsViewController.swift | 2 ++ Tusker/Screens/Search/SearchViewController.swift | 1 + .../StatusActionAccountListViewController.swift | 1 + Tusker/Screens/Timeline/TimelineViewController.swift | 1 + 19 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Tusker.xcodeproj/xcshareddata/xcschemes/Tusker.xcscheme b/Tusker.xcodeproj/xcshareddata/xcschemes/Tusker.xcscheme index 50066d9e..1c2b456f 100644 --- a/Tusker.xcodeproj/xcshareddata/xcschemes/Tusker.xcscheme +++ b/Tusker.xcodeproj/xcshareddata/xcschemes/Tusker.xcscheme @@ -88,6 +88,10 @@ argument = "-com.apple.CoreData.ConcurrencyDebug 1" isEnabled = "YES"> + + diff --git a/Tusker/Screens/Account List/AccountListViewController.swift b/Tusker/Screens/Account List/AccountListViewController.swift index 5e3747a3..b05d1546 100644 --- a/Tusker/Screens/Account List/AccountListViewController.swift +++ b/Tusker/Screens/Account List/AccountListViewController.swift @@ -36,6 +36,7 @@ class AccountListViewController: UIViewController, CollectionViewController { view = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true dataSource = createDataSource() } diff --git a/Tusker/Screens/Asset Picker/AssetCollectionViewController.swift b/Tusker/Screens/Asset Picker/AssetCollectionViewController.swift index e11b86b0..72f5d27b 100644 --- a/Tusker/Screens/Asset Picker/AssetCollectionViewController.swift +++ b/Tusker/Screens/Asset Picker/AssetCollectionViewController.swift @@ -79,6 +79,7 @@ class AssetCollectionViewController: UIViewController, UICollectionViewDelegate collectionView.alwaysBounceVertical = true collectionView.allowsMultipleSelection = true collectionView.allowsSelection = true + collectionView.allowsFocus = true collectionView.register(UINib(nibName: "AssetCollectionViewCell", bundle: .main), forCellWithReuseIdentifier: reuseIdentifier) diff --git a/Tusker/Screens/Asset Picker/AssetCollectionsListViewController.swift b/Tusker/Screens/Asset Picker/AssetCollectionsListViewController.swift index 84239699..d3c008b2 100644 --- a/Tusker/Screens/Asset Picker/AssetCollectionsListViewController.swift +++ b/Tusker/Screens/Asset Picker/AssetCollectionsListViewController.swift @@ -33,6 +33,8 @@ class AssetCollectionsListViewController: UITableViewController { tableView.register(UINib(nibName: "AllPhotosTableViewCell", bundle: .main), forCellReuseIdentifier: "allPhotosCell") tableView.register(UINib(nibName: "AlbumTableViewCell", bundle: .main), forCellReuseIdentifier: "albumCell") + tableView.allowsFocus = true + dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in switch item { case .cameraRoll: diff --git a/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift b/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift index b4e48521..80865605 100644 --- a/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift +++ b/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift @@ -41,7 +41,8 @@ class BookmarksTableViewController: EnhancedTableViewController { tableView.rowHeight = UITableView.automaticDimension tableView.estimatedRowHeight = 140 - + tableView.allowsFocus = true + tableView.register(UINib(nibName: "TimelineStatusTableViewCell", bundle: .main), forCellReuseIdentifier: statusCell) tableView.prefetchDataSource = self diff --git a/Tusker/Screens/Conversation/ConversationTableViewController.swift b/Tusker/Screens/Conversation/ConversationTableViewController.swift index 81149d21..bf4c8f9c 100644 --- a/Tusker/Screens/Conversation/ConversationTableViewController.swift +++ b/Tusker/Screens/Conversation/ConversationTableViewController.swift @@ -61,13 +61,13 @@ class ConversationTableViewController: EnhancedTableViewController { tableView.delegate = self tableView.dataSource = self + tableView.prefetchDataSource = self tableView.register(UINib(nibName: "TimelineStatusTableViewCell", bundle: nil), forCellReuseIdentifier: "statusCell") tableView.register(UINib(nibName: "ConversationMainStatusTableViewCell", bundle: nil), forCellReuseIdentifier: "mainStatusCell") tableView.register(UINib(nibName: "ExpandThreadTableViewCell", bundle: .main), forCellReuseIdentifier: "expandThreadCell") - tableView.prefetchDataSource = self - + tableView.allowsFocus = true tableView.backgroundColor = .secondarySystemBackground // separators are disabled on the table view so we can re-add them ourselves // so they're not inserted in between statuses in the ame sub-thread diff --git a/Tusker/Screens/Explore/AddSavedHashtagViewController.swift b/Tusker/Screens/Explore/AddSavedHashtagViewController.swift index 2892fb91..f02332f4 100644 --- a/Tusker/Screens/Explore/AddSavedHashtagViewController.swift +++ b/Tusker/Screens/Explore/AddSavedHashtagViewController.swift @@ -42,6 +42,7 @@ class AddSavedHashtagViewController: UIViewController { collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout) collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] collectionView.delegate = self + collectionView.allowsFocus = true view.addSubview(collectionView) let sectionHeaderCell = UICollectionView.SupplementaryRegistration(elementKind: UICollectionView.elementKindSectionHeader) { (headerView, collectionView, indexPath) in diff --git a/Tusker/Screens/Explore/ExploreViewController.swift b/Tusker/Screens/Explore/ExploreViewController.swift index a8e5a88c..5e634b61 100644 --- a/Tusker/Screens/Explore/ExploreViewController.swift +++ b/Tusker/Screens/Explore/ExploreViewController.swift @@ -50,6 +50,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate, Collect collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true view.addSubview(collectionView) dataSource = createDataSource() diff --git a/Tusker/Screens/Explore/ProfileDirectoryViewController.swift b/Tusker/Screens/Explore/ProfileDirectoryViewController.swift index 2bb792f5..88b7d4c0 100644 --- a/Tusker/Screens/Explore/ProfileDirectoryViewController.swift +++ b/Tusker/Screens/Explore/ProfileDirectoryViewController.swift @@ -68,6 +68,7 @@ class ProfileDirectoryViewController: UIViewController { collectionView.register(UINib(nibName: "FeaturedProfileCollectionViewCell", bundle: .main), forCellWithReuseIdentifier: "featuredProfileCell") collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true view.addSubview(collectionView) dataSource = createDataSource() diff --git a/Tusker/Screens/Explore/TrendingHashtagsViewController.swift b/Tusker/Screens/Explore/TrendingHashtagsViewController.swift index b0afbb30..e503e9d5 100644 --- a/Tusker/Screens/Explore/TrendingHashtagsViewController.swift +++ b/Tusker/Screens/Explore/TrendingHashtagsViewController.swift @@ -40,6 +40,7 @@ class TrendingHashtagsViewController: UIViewController { collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true view.addSubview(collectionView) let registration = UICollectionView.CellRegistration { cell, indexPath, hashtag in diff --git a/Tusker/Screens/Explore/TrendingLinksViewController.swift b/Tusker/Screens/Explore/TrendingLinksViewController.swift index 4f71bf67..106fb249 100644 --- a/Tusker/Screens/Explore/TrendingLinksViewController.swift +++ b/Tusker/Screens/Explore/TrendingLinksViewController.swift @@ -36,6 +36,7 @@ class TrendingLinksViewController: EnhancedTableViewController { tableView.register(TrendingLinkTableViewCell.self, forCellReuseIdentifier: "trendingLinkCell") tableView.estimatedRowHeight = 100 + tableView.allowsFocus = true dataSource = UITableViewDiffableDataSource(tableView: tableView, cellProvider: { tableView, indexPath, item in let cell = tableView.dequeueReusableCell(withIdentifier: "trendingLinkCell", for: indexPath) as! TrendingLinkTableViewCell diff --git a/Tusker/Screens/Explore/TrendingStatusesViewController.swift b/Tusker/Screens/Explore/TrendingStatusesViewController.swift index 3abb1ef9..40c83fd0 100644 --- a/Tusker/Screens/Explore/TrendingStatusesViewController.swift +++ b/Tusker/Screens/Explore/TrendingStatusesViewController.swift @@ -70,6 +70,7 @@ class TrendingStatusesViewController: UIViewController { view = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true dataSource = createDataSource() } diff --git a/Tusker/Screens/Lists/EditListAccountsViewController.swift b/Tusker/Screens/Lists/EditListAccountsViewController.swift index 11660b99..f0eb2e16 100644 --- a/Tusker/Screens/Lists/EditListAccountsViewController.swift +++ b/Tusker/Screens/Lists/EditListAccountsViewController.swift @@ -53,6 +53,7 @@ class EditListAccountsViewController: EnhancedTableViewController { tableView.rowHeight = UITableView.automaticDimension tableView.estimatedRowHeight = 66 + tableView.allowsSelection = false dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in guard case let .account(id) = item else { fatalError() } diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index 58ef34a0..b9f70a46 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -55,7 +55,9 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< tableView.register(UINib(nibName: "PollFinishedTableViewCell", bundle: .main), forCellReuseIdentifier: pollCell) tableView.register(UINib(nibName: "StatusUpdatedNotificationTableViewCell", bundle: .main), forCellReuseIdentifier: updatedCell) tableView.register(UINib(nibName: "BasicTableViewCell", bundle: .main), forCellReuseIdentifier: unknownCell) + tableView.cellLayoutMarginsFollowReadableWidth = true + tableView.allowsFocus = true } private func request(range: RequestRange) -> Request<[Pachyderm.Notification]> { diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index dfec9b66..d17c0e5e 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -94,6 +94,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie view = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true registerTimelineLikeCells() dataSource = createDataSource() @@ -555,6 +556,15 @@ extension ProfileStatusesViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { MenuPreviewHelper.willPerformPreviewAction(animator: animator, presenter: self) } + + func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool { + switch dataSource.itemIdentifier(for: indexPath) { + case .header(_), .loadingIndicator: + return false + default: + return true + } + } } extension ProfileStatusesViewController: UICollectionViewDragDelegate { diff --git a/Tusker/Screens/Search/SearchResultsViewController.swift b/Tusker/Screens/Search/SearchResultsViewController.swift index e261b681..bc723d13 100644 --- a/Tusker/Screens/Search/SearchResultsViewController.swift +++ b/Tusker/Screens/Search/SearchResultsViewController.swift @@ -83,6 +83,8 @@ class SearchResultsViewController: EnhancedTableViewController { tableView.register(UINib(nibName: "TimelineStatusTableViewCell", bundle: .main), forCellReuseIdentifier: statusCell) tableView.register(UINib(nibName: "HashtagTableViewCell", bundle: .main), forCellReuseIdentifier: hashtagCell) + tableView.allowsFocus = true + dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in switch item { case let .account(id): diff --git a/Tusker/Screens/Search/SearchViewController.swift b/Tusker/Screens/Search/SearchViewController.swift index cc755f93..5a02feb3 100644 --- a/Tusker/Screens/Search/SearchViewController.swift +++ b/Tusker/Screens/Search/SearchViewController.swift @@ -70,6 +70,7 @@ class SearchViewController: UIViewController { collectionView.delegate = self collectionView.dragDelegate = self collectionView.backgroundColor = .secondarySystemBackground + collectionView.allowsFocus = true view.addSubview(collectionView) dataSource = createDataSource() diff --git a/Tusker/Screens/Status Action Account List/StatusActionAccountListViewController.swift b/Tusker/Screens/Status Action Account List/StatusActionAccountListViewController.swift index e2aee53d..2d092e95 100644 --- a/Tusker/Screens/Status Action Account List/StatusActionAccountListViewController.swift +++ b/Tusker/Screens/Status Action Account List/StatusActionAccountListViewController.swift @@ -74,6 +74,7 @@ class StatusActionAccountListViewController: UIViewController, CollectionViewCon view = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true dataSource = createDataSource() } diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 953e25f2..bf6b03ed 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -98,6 +98,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.delegate = self collectionView.dragDelegate = self + collectionView.allowsFocus = true collectionView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(collectionView) NSLayoutConstraint.activate([