mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-19 19:53:25 +01:00
Improves paging screenshots with different aspect ratios
We now page by the smallest screenshot width to ensure we never overshoot an item.
This commit is contained in:
@@ -65,12 +65,25 @@ private extension AppScreenshotsViewController
|
|||||||
let preferredHeight = 400.0
|
let preferredHeight = 400.0
|
||||||
let estimatedWidth = preferredHeight * (AppScreenshot.defaultAspectRatio.width / AppScreenshot.defaultAspectRatio.height)
|
let estimatedWidth = preferredHeight * (AppScreenshot.defaultAspectRatio.width / AppScreenshot.defaultAspectRatio.height)
|
||||||
|
|
||||||
let layout = UICollectionViewCompositionalLayout(sectionProvider: { (sectionIndex, layoutEnvironment) -> NSCollectionLayoutSection? in
|
let layout = UICollectionViewCompositionalLayout(sectionProvider: { [dataSource] (sectionIndex, layoutEnvironment) -> NSCollectionLayoutSection? in
|
||||||
|
let screenshotWidths = dataSource.items.map { screenshot in
|
||||||
|
var aspectRatio = screenshot.size ?? AppScreenshot.defaultAspectRatio
|
||||||
|
if aspectRatio.width > aspectRatio.height
|
||||||
|
{
|
||||||
|
aspectRatio = CGSize(width: aspectRatio.height, height: aspectRatio.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
let screenshotWidth = (preferredHeight * (aspectRatio.width / aspectRatio.height)).rounded()
|
||||||
|
return screenshotWidth
|
||||||
|
}
|
||||||
|
|
||||||
let itemSize = NSCollectionLayoutSize(widthDimension: .estimated(estimatedWidth), heightDimension: .fractionalHeight(1.0))
|
let smallestWidth = screenshotWidths.sorted().first
|
||||||
|
let itemWidth = smallestWidth ?? estimatedWidth // Use smallestWidth to ensure we never overshoot an item when paging.
|
||||||
|
|
||||||
|
let itemSize = NSCollectionLayoutSize(widthDimension: .estimated(itemWidth), heightDimension: .fractionalHeight(1.0))
|
||||||
let item = NSCollectionLayoutItem(layoutSize: itemSize)
|
let item = NSCollectionLayoutItem(layoutSize: itemSize)
|
||||||
|
|
||||||
let groupSize = NSCollectionLayoutSize(widthDimension: .estimated(estimatedWidth), heightDimension: .absolute(preferredHeight))
|
let groupSize = NSCollectionLayoutSize(widthDimension: .estimated(itemWidth), heightDimension: .absolute(preferredHeight))
|
||||||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
|
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
|
||||||
|
|
||||||
let layoutSection = NSCollectionLayoutSection(group: group)
|
let layoutSection = NSCollectionLayoutSection(group: group)
|
||||||
|
|||||||
Reference in New Issue
Block a user