kishikawakatsumi / IBPCollectionViewCompositionalLayout

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

Fix supplementary content insets #81

Closed notjosh closed 5 years ago

notjosh commented 5 years ago

~(Cherry-picked #80 so the example builds)~ rebased! 💅

Fixes #79.

Boundary supplementary items have two contributing contentInsets:

  1. via its own insets
  2. via its containing section (but only if supplementariesFollowContentInsets is enabled).

This PR does a few things towards that:

  1. defaults supplementariesFollowContentInsets to true
  2. starts boundary item frame relative to section frame (not the inset frame via solver)
  3. adds boundary item insets
  4. adds section insets, if supplementariesFollowContentInsets enabled
  5. calculates available frame with above insets

To illustrate this, we can set some large leading insets to highlight this:

section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 50, bottom: 0, trailing: 10)
sectionHeader.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 100, bottom: 0, trailing: 10)
sectionFooter.contentInsets = .zero

And then toggling: supplementariesFollowContentInsets gives:

iOS 12.4 (before) iOS 12.4 (after) iOS 13
true image image image
false image image image
kishikawakatsumi commented 5 years ago

Looks good to me. I completely forgot to implement supplementariesFollowContentInsets, Thanks!