From 4500e9be27f58bb25acbeba46f6898235c1e993b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 3 Feb 2024 12:41:03 -0500 Subject: [PATCH] visionOS: Don't use certain nib-based cells --- .../Explore/SuggestedProfilesViewController.swift | 15 +++++++++++++++ .../Explore/TrendingLinksViewController.swift | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/Tusker/Screens/Explore/SuggestedProfilesViewController.swift b/Tusker/Screens/Explore/SuggestedProfilesViewController.swift index 7a08d984..8330d0cc 100644 --- a/Tusker/Screens/Explore/SuggestedProfilesViewController.swift +++ b/Tusker/Screens/Explore/SuggestedProfilesViewController.swift @@ -8,6 +8,9 @@ import UIKit import Pachyderm +#if os(visionOS) +import SwiftUI +#endif class SuggestedProfilesViewController: UIViewController, CollectionViewController { @@ -53,10 +56,22 @@ class SuggestedProfilesViewController: UIViewController, CollectionViewControlle } private func createDataSource() -> UICollectionViewDiffableDataSource { + #if os(visionOS) + let accountCell = UICollectionView.CellRegistration { [unowned self] cell, indexPath, item in + if let account = self.mastodonController.persistentContainer.account(for: item.0) { + cell.contentConfiguration = UIHostingConfiguration(content: { + SuggestedProfileCardView(account: account) + }) + } else { + cell.contentConfiguration = nil + } + } + #else let accountCell = UICollectionView.CellRegistration(cellNib: UINib(nibName: "SuggestedProfileCardCollectionViewCell", bundle: .main)) { cell, indexPath, item in cell.delegate = self cell.updateUI(accountID: item.0, source: item.1) } + #endif let dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in switch itemIdentifier { case .account(let id, let source): diff --git a/Tusker/Screens/Explore/TrendingLinksViewController.swift b/Tusker/Screens/Explore/TrendingLinksViewController.swift index 28fdf38a..3859fad2 100644 --- a/Tusker/Screens/Explore/TrendingLinksViewController.swift +++ b/Tusker/Screens/Explore/TrendingLinksViewController.swift @@ -11,6 +11,9 @@ import Pachyderm import WebURLFoundationExtras import SafariServices import Combine +#if os(visionOS) +import SwiftUI +#endif class TrendingLinksViewController: UIViewController, CollectionViewController { @@ -90,10 +93,18 @@ class TrendingLinksViewController: UIViewController, CollectionViewController { let loadingCell = UICollectionView.CellRegistration { cell, indexPath, itemIdentifier in cell.indicator.startAnimating() } + #if os(visionOS) + let linkCell = UICollectionView.CellRegistration { cell, indexPath, item in + cell.contentConfiguration = UIHostingConfiguration(content: { + TrendingLinkCardView(card: item) + }) + } + #else let linkCell = UICollectionView.CellRegistration(cellNib: UINib(nibName: "TrendingLinkCardCollectionViewCell", bundle: .main)) { cell, indexPath, item in cell.verticalSize = .compact cell.updateUI(card: item) } + #endif let confirmLoadMoreCell = UICollectionView.CellRegistration { cell, indexPath, isLoading in cell.confirmLoadMore = self.confirmLoadMore cell.isLoading = isLoading