From c3c0e36144da565c8556bca16a4608a41b1893fd Mon Sep 17 00:00:00 2001 From: Bofei Zhu Date: Fri, 23 Dec 2016 08:12:05 -0800 Subject: [PATCH] Full width item crashes grid layout Summary: Fixed #352 Closes https://github.com/Instagram/IGListKit/pull/361 Differential Revision: D4365711 Pulled By: jessesquires fbshipit-source-id: 344b0c781cc807e0ff0bf381a5b12eaef3388d72 --- CHANGELOG.md | 2 ++ Source/IGListGridCollectionViewLayout.m | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24369223..e3892781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ This release closes the [2.1.0 milestone](https://github.com/Instagram/IGListKit - Fix out-of-bounds bug when child section controllers in a stack remove cells. [Ryan Nystrom](https://github.com/rnystrom) [(#358)](https://github.com/Instagram/IGListKit/pull/358) +- Fix a grid layout bug when item has full-width and iter-item spacing is not zero. [Bofei Zhu](https://github.com/zhubofei) [(#361)](https://github.com/Instagram/IGListKit/pull/361) + 2.0.0 ----- diff --git a/Source/IGListGridCollectionViewLayout.m b/Source/IGListGridCollectionViewLayout.m index ab1c3d20..a5ca0010 100644 --- a/Source/IGListGridCollectionViewLayout.m +++ b/Source/IGListGridCollectionViewLayout.m @@ -219,6 +219,10 @@ NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:i]; id delegate = (id) collectionView.delegate; const CGSize itemSize = [delegate collectionView:collectionView layout:self sizeForItemAtIndexPath:indexPath]; + + IGAssertMainThread(); + IGAssert(itemSize.width <= self.contentWidth, @"The width of a single item must not exceed the width of the collection view."); + _IGListGridLayoutLine *lastLine = [self.lineCache lastObject]; if (![lastLine addItemToTailWithSize:itemSize]) { // Not enough space for the last line @@ -260,7 +264,7 @@ _minimumInteritemSpacing = spacing; _itemSizes = [NSMutableArray array]; _headIndex = headIndex; - _tailSpace = frame.size.width - self.minimumInteritemSpacing; + _tailSpace = frame.size.width; } return self; }