kishikawakatsumi / IBPCollectionViewCompositionalLayout

Backport of UICollectionViewCompositionalLayout to earlier iOS 12
MIT License
1.55k stars 148 forks source link

interItemSpacing issue for nested group #163

Open iAllenC opened 1 year ago

iAllenC commented 1 year ago

when i setted interItemSpacing for a vertical group which cotnains two or more horizontal groups, the interItemSpacing for the vertical group is ignored if run on iOS 12 or earlier, but it behaviors fine on iOS 13 or later.To reproduce this issue, just replace the function createLayout of TwoColumnViewController with codes below:

` func createLayout() -> UICollectionViewLayout { let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0)) let item = NSCollectionLayoutItem(layoutSize: itemSize)

    let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                          heightDimension: .absolute(44))
    let group1 = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: 2)
    group1.interItemSpacing = .fixed(10)
    let group2 = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: 2)
    group2.interItemSpacing = .fixed(10)
    let group = NSCollectionLayoutGroup.vertical(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(44+10+44)), subitems: [group1, group2])
    let spacing = CGFloat(10)
    group.interItemSpacing = .fixed(spacing)

    let section = NSCollectionLayoutSection(group: group)
    section.interGroupSpacing = 20
    section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10)

    let layout = UICollectionViewCompositionalLayout(section: section)
    return layout
}

` Hope you can reply me !

mgray88 commented 1 year ago

@iAllenC Just fyi, this library provides a limited amount of support for the compositional layout pre iOS 13. iOS 13 and onward it just delegates to the builtin UIKit class