From 8ebde97b923d869e96033496ad192a1a5e2fcbaa Mon Sep 17 00:00:00 2001 From: Allen Hsu Date: Thu, 1 Nov 2018 14:53:16 -0700 Subject: [PATCH] Fix logic flaw of of shouldInvalidateLayoutForBoundsChange in IGListCollectionViewLayout (#1236) Summary: Issue fixed: #1235 - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1236 Reviewed By: lorixx Differential Revision: D12839081 Pulled By: rnystrom fbshipit-source-id: 3e9e1192f16912d560d76f3730a377f303708cd7 --- CHANGELOG.md | 1 + Source/IGListCollectionViewLayout.mm | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf448613..d69f3595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Fixed crash when using `-[IGListCollectionContext dequeueReusableCellOfClass:withReuseIdentifier:forSectionController:atIndex:]` [Jeremy Lawrence](https://github.com/ziewvater) (tbd) +- Fixed logic flaw in `[IGListCollectionViewLayout shouldInvalidateLayoutForBoundsChange:]`. [Allen Hsu](https://github.com/allenhsu) (tbd) 3.4.0 ----- diff --git a/Source/IGListCollectionViewLayout.mm b/Source/IGListCollectionViewLayout.mm index 98288ce4..5a439c23 100644 --- a/Source/IGListCollectionViewLayout.mm +++ b/Source/IGListCollectionViewLayout.mm @@ -415,13 +415,17 @@ static void adjustZIndexForAttributes(UICollectionViewLayoutAttributes *attribut - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { const CGRect oldBounds = self.collectionView.bounds; + // always invalidate for size changes + if (!CGSizeEqualToSize(oldBounds.size, newBounds.size)) { + return YES; + } + // if the y origin has changed, only invalidate when using sticky headers if (CGRectGetMinInDirection(newBounds, self.scrollDirection) != CGRectGetMinInDirection(oldBounds, self.scrollDirection)) { return self.stickyHeaders; } - // always invalidate for size changes - return !CGSizeEqualToSize(oldBounds.size, newBounds.size); + return NO; } - (void)prepareLayout {