From afbfcbdf04682dcecc7c16558d58e02039ad1e6a Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 12 Mar 2018 15:27:37 -0700 Subject: [PATCH] fixed Footer is sticky to the top Summary: if `stickyHeader` is true, the footer could be sticky to the top Issue fixed: #1093 - [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) Closes https://github.com/Instagram/IGListKit/pull/1094 Differential Revision: D7246636 Pulled By: rnystrom fbshipit-source-id: 9b7da52ab46229606b530a378c01d799767e27f2 --- CHANGELOG.md | 2 ++ Source/IGListCollectionViewLayout.mm | 39 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03c8efb0..47fcfed9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag ### Fixes - Copy objects when retrieving from datasource to prevent modification of models in binding section controller. [Kashish Goel](https://github.com/kashishgoel) [(#1109)](https://github.com/Instagram/IGListKit/pull/1109) +- Fixed footer is sticky when `stickyHeader` is `true` [aelam](https://github.com/aelam) [(#1094)](https://github.com/Instagram/IGListKit/pull/1094) + 3.2.0 ----- diff --git a/Source/IGListCollectionViewLayout.mm b/Source/IGListCollectionViewLayout.mm index 06c5097a..8ee577a5 100644 --- a/Source/IGListCollectionViewLayout.mm +++ b/Source/IGListCollectionViewLayout.mm @@ -319,29 +319,30 @@ static void adjustZIndexForAttributes(UICollectionViewLayoutAttributes *attribut if ([elementKind isEqualToString:UICollectionElementKindSectionHeader]) { frame = entry.headerBounds; + + + if (self.stickyHeaders) { + CGFloat offset = CGPointGetCoordinateInDirection(collectionView.contentOffset, self.scrollDirection) + self.topContentInset + self.stickyHeaderYOffset; + + if (section + 1 == _sectionData.size()) { + offset = MAX(minOffset, offset); + } else { + const CGFloat maxOffset = CGRectGetMinInDirection(_sectionData[section + 1].bounds, self.scrollDirection) - CGRectGetLengthInDirection(frame, self.scrollDirection); + offset = MIN(MAX(minOffset, offset), maxOffset); + } + switch (self.scrollDirection) { + case UICollectionViewScrollDirectionVertical: + frame.origin.y = offset; + break; + case UICollectionViewScrollDirectionHorizontal: + frame.origin.x = offset; + break; + } + } } else if ([elementKind isEqualToString:UICollectionElementKindSectionFooter]) { frame = entry.footerBounds; } - if (self.stickyHeaders) { - CGFloat offset = CGPointGetCoordinateInDirection(collectionView.contentOffset, self.scrollDirection) + self.topContentInset + self.stickyHeaderYOffset; - - if (section + 1 == _sectionData.size()) { - offset = MAX(minOffset, offset); - } else { - const CGFloat maxOffset = CGRectGetMinInDirection(_sectionData[section + 1].bounds, self.scrollDirection) - CGRectGetLengthInDirection(frame, self.scrollDirection); - offset = MIN(MAX(minOffset, offset), maxOffset); - } - switch (self.scrollDirection) { - case UICollectionViewScrollDirectionVertical: - frame.origin.y = offset; - break; - case UICollectionViewScrollDirectionHorizontal: - frame.origin.x = offset; - break; - } - } - attributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:elementKind withIndexPath:indexPath]; attributes.frame = frame; adjustZIndexForAttributes(attributes);