kishikawakatsumi / IBPCollectionViewCompositionalLayout

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

SupplementaryItem does not anchor correctly on items with estimatedHeight #99

Closed JobsIsMyHomeboy closed 5 years ago

JobsIsMyHomeboy commented 5 years ago

I've found that when trying to add a separator as a supplementary item it doesn't update it's position from the original estimated size. If I specify an estimated height of an item as 200 and then the cell lays out as 150 the supplementary item is still anchored to 200. Works fine on iOS13, just breaks on older versions of the OS.

Below is the layout I am using:

let separatorAnchor = NSCollectionLayoutAnchor(edges: .bottom, absoluteOffset: CGPoint(x: 0, y: 1))
let separatorSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(1))
let separator = NSCollectionLayoutSupplementaryItem(layoutSize: separatorSize, elementKind: SeparatorSupplementaryView.kind, containerAnchor: separatorAnchor)

let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(201))
let item = NSCollectionLayoutItem(layoutSize: itemSize, supplementaryItems: [separator])

let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])

let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)

let layout = UICollectionViewCompositionalLayout(section: section)
andersio commented 5 years ago

On a related note, the position of a boundary supplementary item is not updated accordingly when an estimated item preceding it (same section or not) is resolved into its actual size.

Looking into ways to fix it. Posting here just in case it is already a known issue being worked on.

kishikawakatsumi commented 5 years ago

@JobsIsMyHomeboy @andersio Partially fixed by https://github.com/kishikawakatsumi/IBPCollectionViewCompositionalLayout/pull/102. Please open new issue if you find related to this issue.