mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-15 17:53:31 +01:00
Shrinks AppCardCollectionViewCell height if there are no screenshots
This commit is contained in:
@@ -27,9 +27,24 @@ class AppCardCollectionViewCell: UICollectionViewCell
|
|||||||
private var screenshots: [AppScreenshot] = [] {
|
private var screenshots: [AppScreenshot] = [] {
|
||||||
didSet {
|
didSet {
|
||||||
self.dataSource.items = self.screenshots
|
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)
|
override init(frame: CGRect)
|
||||||
{
|
{
|
||||||
self.bannerView = AppBannerView(frame: .zero)
|
self.bannerView = AppBannerView(frame: .zero)
|
||||||
@@ -48,6 +63,12 @@ class AppCardCollectionViewCell: UICollectionViewCell
|
|||||||
self.stackView.alignment = .fill
|
self.stackView.alignment = .fill
|
||||||
self.stackView.distribution = .equalSpacing
|
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)
|
super.init(frame: frame)
|
||||||
|
|
||||||
self.contentView.clipsToBounds = true
|
self.contentView.clipsToBounds = true
|
||||||
@@ -70,20 +91,13 @@ class AppCardCollectionViewCell: UICollectionViewCell
|
|||||||
|
|
||||||
self.screenshotsCollectionView.register(AppScreenshotCollectionViewCell.self, forCellWithReuseIdentifier: RSTCellContentGenericCellIdentifier)
|
self.screenshotsCollectionView.register(AppScreenshotCollectionViewCell.self, forCellWithReuseIdentifier: RSTCellContentGenericCellIdentifier)
|
||||||
|
|
||||||
let inset = 14.0 //TODO: Assign from bannerView's layoutMargins
|
|
||||||
self.stackView.isLayoutMarginsRelativeArrangement = true
|
self.stackView.isLayoutMarginsRelativeArrangement = true
|
||||||
self.stackView.layoutMargins.bottom = inset
|
self.stackView.layoutMargins.bottom = inset
|
||||||
|
|
||||||
self.contentView.preservesSuperviewLayoutMargins = true
|
self.contentView.preservesSuperviewLayoutMargins = true
|
||||||
self.screenshotsCollectionView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: 0, leading: inset, bottom: 0, trailing: inset)
|
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([
|
NSLayoutConstraint.activate([
|
||||||
aspectRatioConstraint,
|
|
||||||
self.bannerView.heightAnchor.constraint(equalToConstant: 88)
|
self.bannerView.heightAnchor.constraint(equalToConstant: 88)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user