Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add horizontal scrolling support to IGListCollectionViewLayout #857

Closed
11 changes: 0 additions & 11 deletions Source/IGListCollectionViewLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ NS_SWIFT_NAME(ListCollectionViewLayout)
header position as UI like the navigation bar is scrolled offscreen. In a vertically scrolling layout, changing
this to the height of the navigation bar will give the effect of the headers sticking to the nav as it is collapsed.

@note Changing the value on this method will invalidate the layout every time.
*/
@property (nonatomic, assign) CGFloat stickyHeaderOriginOffset;

/**

**This property is expected to be removed in IGListKit 4.0. Use `stickyHeaderOriginOffset` instead.** Set this to adjust
the Y offset of the sticky headers. Can be used to change the sticky header position as UI like the navigation bar is scrolled
offscreen. Changing this to the height of the navigation bar will give the effect of the headers sticking to the
nav as it is collapsed.

@note Changing the value on this method will invalidate the layout every time.
*/
@property (nonatomic, assign) CGFloat stickyHeaderYOffset;
Expand Down
17 changes: 4 additions & 13 deletions Source/IGListCollectionViewLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind
CGRect frame = entry.headerBounds;

if (self.stickyHeaders) {
CGFloat offset = CGPointGetCoordinateInDirection(collectionView.contentOffset, self.scrollDirection) + self.topContentInset + self.stickyHeaderOriginOffset;
CGFloat offset = CGPointGetCoordinateInDirection(collectionView.contentOffset, self.scrollDirection) + self.topContentInset + self.stickyHeaderYOffset;

if (section + 1 == _sectionData.size()) {
offset = MAX(minOffset, offset);
Expand Down Expand Up @@ -372,27 +372,18 @@ - (void)prepareLayout {

#pragma mark - Public API

- (void)setStickyHeaderOriginOffset:(CGFloat)stickyHeaderOriginOffset {
- (void)setStickyHeaderYOffset:(CGFloat)stickyHeaderYOffset {
IGAssertMainThread();

if (_stickyHeaderOriginOffset != stickyHeaderOriginOffset) {
_stickyHeaderOriginOffset = stickyHeaderOriginOffset;
if (_stickyHeaderYOffset != stickyHeaderYOffset) {
_stickyHeaderYOffset = stickyHeaderYOffset;

IGListCollectionViewLayoutInvalidationContext *invalidationContext = [IGListCollectionViewLayoutInvalidationContext new];
invalidationContext.ig_invalidateSupplementaryAttributes = YES;
[self invalidateLayoutWithContext:invalidationContext];
}
}

// For backwards compatibility
- (CGFloat)stickyHeaderYOffset {
return _stickyHeaderOriginOffset;
}

- (void)setStickyHeaderYOffset:(CGFloat)stickyHeaderYOffset {
[self setStickyHeaderOriginOffset:stickyHeaderYOffset];
}

#pragma mark - Private API

- (void)cacheLayout {
Expand Down
11 changes: 2 additions & 9 deletions Tests/IGListCollectionViewLayoutTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ - (void)test_whenAdjustingTopYInset_withVaryingHeaderHeights_thatYPositionsUpdat
IGAssertEqualFrame([self headerForSection:0].frame, 0, 30, 100, 10);
IGAssertEqualFrame([self headerForSection:1].frame, 0, 45, 100, 10);

self.layout.stickyHeaderOriginOffset = -10;
self.layout.stickyHeaderYOffset = -10;
[self.collectionView layoutIfNeeded];
IGAssertEqualFrame([self headerForSection:0].frame, 0, 30, 100, 10);
IGAssertEqualFrame([self headerForSection:1].frame, 0, 40, 100, 10);

self.layout.stickyHeaderOriginOffset = 10;
self.layout.stickyHeaderYOffset = 10;
[self.collectionView layoutIfNeeded];
IGAssertEqualFrame([self headerForSection:0].frame, 0, 30, 100, 10);
IGAssertEqualFrame([self headerForSection:1].frame, 0, 55, 100, 10);
Expand Down Expand Up @@ -919,11 +919,4 @@ - (void)test_whenQueryingAttributes_withItemOOB_thatReturnsNil {
XCTAssertNil([self.layout layoutAttributesForItemAtIndexPath:genIndexPath(0, 4)]);
}

- (void)test_whenStickyHeaderYOffsetIsChanged_thatStickyHeaderOriginOffsetIsChangedToo {
[self setUpWithStickyHeaders:YES topInset:0 stretchToEdge:YES];
self.layout.stickyHeaderYOffset = 44.0;
XCTAssertEqual(self.layout.stickyHeaderOriginOffset, 44.0);
XCTAssertEqual(self.layout.stickyHeaderYOffset, 44.0);
}

@end