From 99b3532e6421fb987623d8dee6bcda53950d24db Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 22 Jan 2023 17:17:59 -0500 Subject: [PATCH] Add description to trending link cards, fix not responding to dynamic type --- .../TrendingLinkCardCollectionViewCell.swift | 6 +- .../TrendingLinkCardCollectionViewCell.xib | 109 +++++++++++------- .../Screens/Search/SearchViewController.swift | 4 +- 3 files changed, 74 insertions(+), 45 deletions(-) diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift index 08a562eb..c3cc2291 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift @@ -17,6 +17,7 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { @IBOutlet weak var thumbnailView: UIImageView! @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var descriptionLabel: UILabel! @IBOutlet weak var providerLabel: UILabel! @IBOutlet weak var activityLabel: UILabel! @IBOutlet weak var historyView: TrendHistoryView! @@ -37,7 +38,6 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { super.layoutSubviews() contentView.layer.cornerRadius = 0.05 * bounds.width - thumbnailView.layer.cornerRadius = 0.05 * bounds.width } func updateUI(card: Card) { @@ -53,6 +53,10 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { let provider = card.providerName!.trimmingCharacters(in: .whitespacesAndNewlines) providerLabel.text = provider + let description = card.description.trimmingCharacters(in: .whitespacesAndNewlines) + descriptionLabel.text = description + descriptionLabel.isHidden = description.isEmpty + let sorted = card.history!.sorted(by: { $0.day < $1.day }) let lastTwo = sorted[(sorted.count - 2)...] let accounts = lastTwo.map(\.accounts).reduce(0, +) diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib index 6ce990d8..8549f22b 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib @@ -1,9 +1,9 @@ - + - + @@ -12,10 +12,10 @@ - + - + @@ -24,59 +24,86 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - + diff --git a/Tusker/Screens/Search/SearchViewController.swift b/Tusker/Screens/Search/SearchViewController.swift index 1ce86125..42b51fc3 100644 --- a/Tusker/Screens/Search/SearchViewController.swift +++ b/Tusker/Screens/Search/SearchViewController.swift @@ -49,10 +49,8 @@ class SearchViewController: UIViewController, CollectionViewController { return .list(using: listConfig, layoutEnvironment: environment) case .trendingLinks: - let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)) + let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(280)) let item = NSCollectionLayoutItem(layoutSize: itemSize) - // todo: i really wish i could just say the height is automatic and let autolayout figure out what it needs to be - // using .estimated(whatever) constrains the height to exactly whatever let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(250), heightDimension: .estimated(280)) let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) group.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: .fixed(8), top: nil, trailing: .fixed(8), bottom: nil)