mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 16:53:29 +01:00
Limits paging app screenshots on FeaturedViewController to bottom of cell
Prioritizes paging featured apps over app screenshots.
This commit is contained in:
@@ -363,6 +363,7 @@ private extension FeaturedViewController
|
|||||||
dataSource.cellConfigurationHandler = { cell, storeApp, indexPath in
|
dataSource.cellConfigurationHandler = { cell, storeApp, indexPath in
|
||||||
let cell = cell as! AppCardCollectionViewCell
|
let cell = cell as! AppCardCollectionViewCell
|
||||||
cell.configure(for: storeApp)
|
cell.configure(for: storeApp)
|
||||||
|
cell.prefersPagingScreenshots = false
|
||||||
|
|
||||||
cell.bannerView.button.addTarget(self, action: #selector(FeaturedViewController.performAppAction), for: .primaryActionTriggered)
|
cell.bannerView.button.addTarget(self, action: #selector(FeaturedViewController.performAppAction), for: .primaryActionTriggered)
|
||||||
cell.bannerView.sourceIconImageView.isHidden = true
|
cell.bannerView.sourceIconImageView.isHidden = true
|
||||||
|
|||||||
@@ -20,9 +20,13 @@ class AppCardCollectionViewCell: UICollectionViewCell
|
|||||||
let bannerView: AppBannerView
|
let bannerView: AppBannerView
|
||||||
let captionLabel: UILabel
|
let captionLabel: UILabel
|
||||||
|
|
||||||
|
var prefersPagingScreenshots = true
|
||||||
|
|
||||||
private let screenshotsCollectionView: UICollectionView
|
private let screenshotsCollectionView: UICollectionView
|
||||||
private let stackView: UIStackView
|
private let stackView: UIStackView
|
||||||
|
|
||||||
|
private let topAreaPanGestureRecognizer: UIPanGestureRecognizer
|
||||||
|
|
||||||
private lazy var dataSource = self.makeDataSource()
|
private lazy var dataSource = self.makeDataSource()
|
||||||
|
|
||||||
private var screenshots: [AppScreenshot] = [] {
|
private var screenshots: [AppScreenshot] = [] {
|
||||||
@@ -81,6 +85,12 @@ class AppCardCollectionViewCell: UICollectionViewCell
|
|||||||
let spacing = (inset * 2) + (minimumItemSpacing * 2)
|
let spacing = (inset * 2) + (minimumItemSpacing * 2)
|
||||||
self.collectionViewAspectRatioConstraint = self.screenshotsCollectionView.widthAnchor.constraint(equalTo: self.screenshotsCollectionView.heightAnchor, multiplier: multiplier, constant: spacing)
|
self.collectionViewAspectRatioConstraint = self.screenshotsCollectionView.widthAnchor.constraint(equalTo: self.screenshotsCollectionView.heightAnchor, multiplier: multiplier, constant: spacing)
|
||||||
|
|
||||||
|
// Allows us to ignore swipes in top portion of screenshotsCollectionView.
|
||||||
|
self.topAreaPanGestureRecognizer = UIPanGestureRecognizer(target: nil, action: nil)
|
||||||
|
self.topAreaPanGestureRecognizer.cancelsTouchesInView = false
|
||||||
|
self.topAreaPanGestureRecognizer.delaysTouchesBegan = false
|
||||||
|
self.topAreaPanGestureRecognizer.delaysTouchesEnded = false
|
||||||
|
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
self.contentView.clipsToBounds = true
|
self.contentView.clipsToBounds = true
|
||||||
@@ -101,6 +111,10 @@ class AppCardCollectionViewCell: UICollectionViewCell
|
|||||||
tapGestureRecognizer.delaysTouchesEnded = false
|
tapGestureRecognizer.delaysTouchesEnded = false
|
||||||
self.screenshotsCollectionView.addGestureRecognizer(tapGestureRecognizer)
|
self.screenshotsCollectionView.addGestureRecognizer(tapGestureRecognizer)
|
||||||
|
|
||||||
|
self.topAreaPanGestureRecognizer.delegate = self
|
||||||
|
self.screenshotsCollectionView.panGestureRecognizer.require(toFail: self.topAreaPanGestureRecognizer)
|
||||||
|
self.screenshotsCollectionView.addGestureRecognizer(self.topAreaPanGestureRecognizer)
|
||||||
|
|
||||||
self.screenshotsCollectionView.register(AppScreenshotCollectionViewCell.self, forCellWithReuseIdentifier: RSTCellContentGenericCellIdentifier)
|
self.screenshotsCollectionView.register(AppScreenshotCollectionViewCell.self, forCellWithReuseIdentifier: RSTCellContentGenericCellIdentifier)
|
||||||
|
|
||||||
self.stackView.isLayoutMarginsRelativeArrangement = true
|
self.stackView.isLayoutMarginsRelativeArrangement = true
|
||||||
@@ -324,3 +338,51 @@ extension AppCardCollectionViewCell
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension AppCardCollectionViewCell: UIGestureRecognizerDelegate
|
||||||
|
{
|
||||||
|
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool
|
||||||
|
{
|
||||||
|
// Never recognize topAreaPanGestureRecognizer unless prefersPagingScreenshots is false.
|
||||||
|
guard !self.prefersPagingScreenshots else { return false }
|
||||||
|
|
||||||
|
let point = gestureRecognizer.location(in: self.screenshotsCollectionView)
|
||||||
|
|
||||||
|
// Top area = Top 3/4
|
||||||
|
let isTopArea = point.y < (self.screenshotsCollectionView.bounds.height / 4) * 3
|
||||||
|
return isTopArea
|
||||||
|
}
|
||||||
|
|
||||||
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool
|
||||||
|
{
|
||||||
|
guard let panGestureRecognizer = otherGestureRecognizer as? UIPanGestureRecognizer, let view = panGestureRecognizer.view else { return false }
|
||||||
|
|
||||||
|
if view.isDescendant(of: self.screenshotsCollectionView)
|
||||||
|
{
|
||||||
|
// Only allow nested gesture recognizers if topAreaPanGestureRecognizer fails.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Always allow parent gesture recognizers.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool
|
||||||
|
{
|
||||||
|
guard let panGestureRecognizer = otherGestureRecognizer as? UIPanGestureRecognizer, let view = panGestureRecognizer.view else { return true }
|
||||||
|
|
||||||
|
if view.isDescendant(of: self.screenshotsCollectionView)
|
||||||
|
{
|
||||||
|
// Don't recognize topAreaPanGestureRecognizer alongside nested gesture recognizers.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Allow recognizing simultaneously with parent gesture recognizers.
|
||||||
|
// This fixes accidentally breaking scrolling in parent.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user