From 65562602afba9dd681254065c069cb1fb13f454d Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 20 Oct 2023 17:13:28 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20incorrectly=20centering=20screenshot=20?= =?UTF-8?q?thumbnail=20when=20there=E2=80=99s=20only=20one=20visible=20ini?= =?UTF-8?q?tially?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/AppCardCollectionViewCell.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/AltStore/Components/AppCardCollectionViewCell.swift b/AltStore/Components/AppCardCollectionViewCell.swift index ec00ca0b..26fb00ba 100644 --- a/AltStore/Components/AppCardCollectionViewCell.swift +++ b/AltStore/Components/AppCardCollectionViewCell.swift @@ -161,9 +161,19 @@ private extension AppCardCollectionViewCell // Use .estimated(1) to ensure we don't over-estimate widths, which can cause incorrect layouts for the last group. let itemSize = NSCollectionLayoutSize(widthDimension: .estimated(1), heightDimension: .fractionalHeight(1.0)) - let item = NSCollectionLayoutItem(layoutSize: itemSize) - item.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: .flexible(0), top: nil, trailing: nil, bottom: nil) + + if numberOfVisibleScreenshots == 1 + { + // If there's only one screenshot visible initially, we'll (reluctantly) opt-in to flexible spacing on both sides. + // This ensures the items are always centered, but may result in larger spacings between items than we'd prefer. + item.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: .flexible(0), top: nil, trailing: .flexible(0), bottom: nil) + } + else + { + // Otherwise, only have flexible spacing on the leading edge, which will be balanced by trailingGroup's flexible trailing spacing. + item.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: .flexible(0), top: nil, trailing: nil, bottom: nil) + } let groupItem = NSCollectionLayoutItem(layoutSize: itemSize) let trailingGroup = NSCollectionLayoutGroup.horizontal(layoutSize: itemSize, subitems: [groupItem])