From acc897d6a8600e56344732bda97af7690a47ac20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=9C=E5=A3=B0=E4=B8=96=E7=BA=AA?= <> Date: Sat, 27 Dec 2025 14:33:40 +0800 Subject: [PATCH] 1 --- .../NRExploreNovelGenresViewController.swift | 27 ++++++++++--------- .../Class/Store/V/NRStoreCoinsView.swift | 20 +++++++++----- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/ReaderHive/Class/Explore/VC/NRExploreNovelGenresViewController.swift b/ReaderHive/Class/Explore/VC/NRExploreNovelGenresViewController.swift index ef7e396..c2677c5 100644 --- a/ReaderHive/Class/Explore/VC/NRExploreNovelGenresViewController.swift +++ b/ReaderHive/Class/Explore/VC/NRExploreNovelGenresViewController.swift @@ -16,18 +16,21 @@ class NRExploreNovelGenresViewController: NRViewController { lazy var collectionViewLayout: UICollectionViewCompositionalLayout = { - let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(0.5), heightDimension: .fractionalHeight(1))) - - let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(48)), subitems: [item]) - group.interItemSpacing = .fixed(8) - - let section = NSCollectionLayoutSection(group: group) - section.interGroupSpacing = 8 - section.contentInsets = .init(top: 0, leading: 12, bottom: 0, trailing: 12) - - let configuration = UICollectionViewCompositionalLayoutConfiguration() - - let layout = UICollectionViewCompositionalLayout(section: section, configuration: configuration) + let layout = UICollectionViewCompositionalLayout(sectionProvider: { (section, environment) in + let contentWidth = environment.container.effectiveContentSize.width + let witemWidth = floor((contentWidth - 8 - 24) / 2) + + let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .absolute(witemWidth), heightDimension: .fractionalHeight(1))) + + let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(48)), subitems: [item]) + group.interItemSpacing = .fixed(8) + + let section = NSCollectionLayoutSection(group: group) + section.interGroupSpacing = 8 + section.contentInsets = .init(top: 0, leading: 12, bottom: 0, trailing: 12) + + return section + }) return layout }() diff --git a/ReaderHive/Class/Store/V/NRStoreCoinsView.swift b/ReaderHive/Class/Store/V/NRStoreCoinsView.swift index 1581953..78d360e 100644 --- a/ReaderHive/Class/Store/V/NRStoreCoinsView.swift +++ b/ReaderHive/Class/Store/V/NRStoreCoinsView.swift @@ -30,16 +30,16 @@ class NRStoreCoinsView: UIView { let config = UICollectionViewCompositionalLayoutConfiguration() config.interSectionSpacing = 12 - let layout = UICollectionViewCompositionalLayout { [weak self] section, _ in + let layout = UICollectionViewCompositionalLayout { [weak self] section, environment in guard let self = self else { return nil} guard let model = dataArr[section].first else { return nil } if model.buy_type == .subCoins { return self.coinsBigLayoutSection() } else if model.size == .big { - return self.bigLayoutSection() + return self.bigLayoutSection(environment: environment) } else { - return self.smallLayoutSection() + return self.smallLayoutSection(environment: environment) } } layout.configuration = config @@ -156,8 +156,11 @@ extension NRStoreCoinsView { extension NRStoreCoinsView { - private func bigLayoutSection() -> NSCollectionLayoutSection { - let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(0.5), heightDimension: .fractionalHeight(1))) + private func bigLayoutSection(environment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection { + let containerWidth = environment.container.effectiveContentSize.width + let itemWidth = floor((containerWidth - 32 - 15) / 2) + + let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .absolute(itemWidth), heightDimension: .fractionalHeight(1))) let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(100)), subitems: [item]) group.interItemSpacing = .fixed(15) @@ -168,8 +171,11 @@ extension NRStoreCoinsView { return layoutSection } - private func smallLayoutSection() -> NSCollectionLayoutSection { - let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1 / 3), heightDimension: .fractionalHeight(1))) + private func smallLayoutSection(environment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection { + let containerWidth = environment.container.effectiveContentSize.width + let itemWidth = floor((containerWidth - 32 - 30) / 3) + + let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .absolute(itemWidth), heightDimension: .fractionalHeight(1))) let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(84)), subitems: [item]) group.interItemSpacing = .fixed(15)