Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

Layouts with automatic cell sizing crash when the side insets are non-zero #444

Closed HarshilShah closed 7 years ago

HarshilShah commented 7 years ago

New issue checklist

General information

Self-sizing cell layouts, as shown in the SelfSizingCellsViewController example, break when the inset.right or inset.left values for the section controller are non-zero.

The following console output is shown when inset.left is set to 10, instead of the current value of 0, in the example SelfSizingSectionController.

2017-01-23 21:00:30.619 IGListKitExamples[17836:3387117] The behavior of the UICollectionViewFlowLayout is not defined because:
2017-01-23 21:00:30.619 IGListKitExamples[17836:3387117] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2017-01-23 21:00:30.619 IGListKitExamples[17836:3387117] Please check the values returned by the delegate.
2017-01-23 21:00:30.620 IGListKitExamples[17836:3387117] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7ff28ec159a0>, and it is attached to <IGListCollectionView: 0x7ff28f030200; baseClass = UICollectionView; frame = (0 0; 414 736); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x60000005d220>; layer = <CALayer: 0x600000035920>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x7ff28ec159a0>.
2017-01-23 21:00:30.620 IGListKitExamples[17836:3387117] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

[This set of messages is shown a whole bunch of times, presumably for each separate self-sizing view in the controller.]

zhubofei commented 7 years ago

@HarshilShah This seems to be a flow layout problem. After setting insets to 10, the width of the section is containerWidth + 10 + 10, which is larger than the width of the collectionView. This is not allowed in UICollectionViewFlowLayout.

zhubofei commented 7 years ago

@HarshilShah Set

 func sizeForItem(at index: Int) -> CGSize {
        return CGSize(width: collectionContext!.containerSize.width - 20, height: 55)
 }

in SelfSizingSectionController should solve your issue.

20 = inset.left + inset.right

HarshilShah commented 7 years ago

@zhubofei This solved it, thanks!