kishikawakatsumi/IBPCollectionViewCompositionalLayout

the below code of layout section before iOS 13 is not work correctly

Opened this issue · 2 comments

     // i.e.  all iOS version is work correctly
    func layoutSection(layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? {
        let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                              heightDimension: .fractionalHeight(1.0))
        let item = NSCollectionLayoutItem(layoutSize: itemSize)
        
        let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(185),
                                               heightDimension: .absolute(160))
        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
        
        let section = NSCollectionLayoutSection(group: group)
        section.contentInsets = .init(top: 0, leading: 15, bottom: 0, trailing: 15)
        section.orthogonalScrollingBehavior = .continuous
        section.interGroupSpacing = 10
        return section
    }
    
    // i.e.  before iOS 13 is not work correctly
    func layoutSection_v1(layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? {
        let itemCount = items.count
        guard itemCount > 0 else {
            return nil
        }
        
        let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(185),
                                              heightDimension: .fractionalHeight(1.0))
        let item = NSCollectionLayoutItem(layoutSize: itemSize)
        
        let width = CGFloat(15 + 185 * itemCount + 10 * (itemCount - 1) + 15)
        let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(width),
                                               heightDimension: .absolute(160))
        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
        group.contentInsets = .init(top: 0, leading: 15, bottom: 0, trailing: 15)
        group.interItemSpacing = .fixed(10)
        
        let section = NSCollectionLayoutSection(group: group)
        section.orthogonalScrollingBehavior = .continuous
        section.interGroupSpacing = 0
        return section
    }

I think you need to add IBP before NS eg) IBPNSCollectionLayoutSize instead of NSCollectionLayoutSize.

@seleemdeveloper it is typealias NS* for IBP*:
typealias_IBP_NS