1
This commit is contained in:
parent
17669d1412
commit
acc897d6a8
@ -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
|
||||
}()
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user