From edf3281eee41f6e6ebca3c6c3567b348d9e52956 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 19 Oct 2023 17:18:48 -0500 Subject: [PATCH] Shrinks AppCardCollectionViewCell height if there are no screenshots --- .../AppCardCollectionViewCell.swift | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/AltStore/Components/AppCardCollectionViewCell.swift b/AltStore/Components/AppCardCollectionViewCell.swift index 7177233f..ec00ca0b 100644 --- a/AltStore/Components/AppCardCollectionViewCell.swift +++ b/AltStore/Components/AppCardCollectionViewCell.swift @@ -27,9 +27,24 @@ class AppCardCollectionViewCell: UICollectionViewCell private var screenshots: [AppScreenshot] = [] { didSet { self.dataSource.items = self.screenshots + + if self.screenshots.isEmpty + { + // No screenshots, so hide collection view. + self.collectionViewAspectRatioConstraint.isActive = false + self.stackView.layoutMargins.bottom = 0 + } + else + { + // At least one screenshot, so show collection view. + self.collectionViewAspectRatioConstraint.isActive = true + self.stackView.layoutMargins.bottom = self.screenshotsCollectionView.directionalLayoutMargins.leading + } } } + private let collectionViewAspectRatioConstraint: NSLayoutConstraint + override init(frame: CGRect) { self.bannerView = AppBannerView(frame: .zero) @@ -48,6 +63,12 @@ class AppCardCollectionViewCell: UICollectionViewCell self.stackView.alignment = .fill self.stackView.distribution = .equalSpacing + // Aspect ratio constraint to fit exactly 3 modern portrait iPhone screenshots side-by-side (with spacing). + let inset = 14.0 //TODO: Assign from bannerView's layoutMargins + let multiplier = (AppScreenshot.defaultAspectRatio.width * 3) / AppScreenshot.defaultAspectRatio.height + let spacing = (inset * 2) + (minimumItemSpacing * 2) + self.collectionViewAspectRatioConstraint = self.screenshotsCollectionView.widthAnchor.constraint(equalTo: self.screenshotsCollectionView.heightAnchor, multiplier: multiplier, constant: spacing) + super.init(frame: frame) self.contentView.clipsToBounds = true @@ -70,20 +91,13 @@ class AppCardCollectionViewCell: UICollectionViewCell self.screenshotsCollectionView.register(AppScreenshotCollectionViewCell.self, forCellWithReuseIdentifier: RSTCellContentGenericCellIdentifier) - let inset = 14.0 //TODO: Assign from bannerView's layoutMargins self.stackView.isLayoutMarginsRelativeArrangement = true self.stackView.layoutMargins.bottom = inset self.contentView.preservesSuperviewLayoutMargins = true self.screenshotsCollectionView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: 0, leading: inset, bottom: 0, trailing: inset) - - // Aspect ratio constraint to fit exactly 3 modern portrait iPhone screenshots side-by-side (with spacing). - let multiplier = (AppScreenshot.defaultAspectRatio.width * 3) / AppScreenshot.defaultAspectRatio.height - let spacing = (inset * 2) + (minimumItemSpacing * 2) - let aspectRatioConstraint = self.screenshotsCollectionView.widthAnchor.constraint(equalTo: self.screenshotsCollectionView.heightAnchor, multiplier: multiplier, constant: spacing) - + NSLayoutConstraint.activate([ - aspectRatioConstraint, self.bannerView.heightAnchor.constraint(equalToConstant: 88) ]) }