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

[Table and collection views] Consider content inset when calculating (default) element size range #525

Merged
merged 6 commits into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Remove re-entrant access to self.view when applying initial pending state. [Adlai Holler](https://github.com/Adlai-Holler) [#510](https://github.com/TextureGroup/Texture/pull/510)
- Small improvements in ASCollectionLayout [Huy Nguyen](https://github.com/nguyenhuy) [#509](https://github.com/TextureGroup/Texture/pull/509) [#513](https://github.com/TextureGroup/Texture/pull/513)
- Fix retain cycle between ASImageNode and PINAnimatedImage [Phil Larson](https://github.com/plarson) [#520](https://github.com/TextureGroup/Texture/pull/520)
- Table and collection views to consider content inset when calculating (default) element size range [Huy Nguyen](https://github.com/nguyenhuy) [#525](https://github.com/TextureGroup/Texture/pull/525)

##2.4
- Fix an issue where inserting/deleting sections could lead to inconsistent supplementary element behavior. [Adlai Holler](https://github.com/Adlai-Holler)
Expand Down
15 changes: 13 additions & 2 deletions Source/ASPagerNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ - (NSInteger)currentPageIndex
return (self.view.contentOffset.x / CGRectGetWidth(self.view.bounds));
}

- (CGSize)pageSize
{
CGSize pageSize = self.bounds.size;
UIEdgeInsets contentInset = self.view.contentInset;
if (! UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, contentInset)) {
pageSize.width -= (contentInset.left + contentInset.right);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to apply the horizontal inset here? It makes perfect sense to me that users would want to account for content inset in the cross direction, but I'm not so sure about the scrolling direction. For example, if they have a 50pt left inset so that the carousel starts off inset by a bit, they probably still want each page to be full-width, since the insets will only be applied at the start/end of the feed, not on every page. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point! I'll fix this.

pageSize.height -= (contentInset.top + contentInset.bottom);
}
return pageSize;
}

#pragma mark - Helpers

- (void)scrollToPageAtIndex:(NSInteger)index animated:(BOOL)animated
Expand Down Expand Up @@ -142,7 +153,7 @@ - (NSInteger)indexOfPageWithNode:(ASCellNode *)node
- (CGSize)sizeForElements:(ASElementMap *)elements
{
ASDisplayNodeAssertMainThread();
return self.bounds.size;
return [self pageSize];
}

#pragma mark - ASCollectionDataSource
Expand Down Expand Up @@ -179,7 +190,7 @@ - (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode constrainedSize
}
#pragma clang diagnostic pop

return ASSizeRangeMake(self.bounds.size);
return ASSizeRangeMake([self pageSize]);
}

#pragma mark - Data Source Proxy
Expand Down
3 changes: 2 additions & 1 deletion Source/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ - (void)layoutSubviews
{
// Remeasure all rows if our row width has changed.
_remeasuringCellNodes = YES;
CGFloat constrainedWidth = self.bounds.size.width - [self sectionIndexWidth];
UIEdgeInsets contentInset = self.contentInset;
CGFloat constrainedWidth = self.bounds.size.width - [self sectionIndexWidth] - contentInset.left - contentInset.right;
if (constrainedWidth > 0 && _nodesConstrainedWidth != constrainedWidth) {
_nodesConstrainedWidth = constrainedWidth;

Expand Down
5 changes: 5 additions & 0 deletions Source/Details/ASCollectionViewLayoutInspector.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
// of the collection view
ASSizeRange NodeConstrainedSizeForScrollDirection(ASCollectionView *collectionView) {
CGSize maxSize = collectionView.bounds.size;
UIEdgeInsets contentInset = collectionView.contentInset;
if (! UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, contentInset)) {
maxSize.width -= (contentInset.left + contentInset.right);
maxSize.height -= (contentInset.top + contentInset.bottom);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same principle as in the pager: I think we should not apply these in the scrolling direction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
if (ASScrollDirectionContainsHorizontalDirection(collectionView.scrollableDirections)) {
maxSize.width = CGFLOAT_MAX;
} else {
Expand Down