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

Conversation

nguyenhuy
Copy link
Member

No description provided.

@nguyenhuy nguyenhuy changed the title [Table and collection views] Consider content inset when calculating element size range [Table and collection views] Consider content inset when calculating (default) element size range Aug 22, 2017
Copy link
Member

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

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

This is a good change @nguyenhuy . One open question for you.

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.

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.

👍

- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout {
return (flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) ? ASScrollDirectionHorizontalDirections : ASScrollDirectionVerticalDirections;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This method isn't used anywhere.

@@ -66,6 +66,7 @@ - (instancetype)init
- (instancetype)initWithCollectionViewLayout:(ASPagerFlowLayout *)flowLayout;
{
ASDisplayNodeAssert([flowLayout isKindOfClass:[ASPagerFlowLayout class]], @"ASPagerNode requires a flow layout.");
ASDisplayNodeAssertTrue(flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal);
Copy link
Member Author

@nguyenhuy nguyenhuy Aug 22, 2017

Choose a reason for hiding this comment

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

The existing implementation of this class (e.g -currentPageIndex and - scrollToPageAtIndex: animated:) assumes a horizontal scroll direction. Let's formalize that.

@@ -112,7 +113,15 @@ - (void)didLoad

- (NSInteger)currentPageIndex
{
return (self.view.contentOffset.x / CGRectGetWidth(self.view.bounds));
return (self.view.contentOffset.x / [self pageSize].width);
Copy link
Member Author

Choose a reason for hiding this comment

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

The old implementation works as expected, but let's not assume that self.view.bounds.width == self.pageSize.width.

@ghost
Copy link

ghost commented Aug 22, 2017

🚫 CI failed with log

Copy link
Member

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

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

Looks good once the CI is sorted 👍

@garrettmoon garrettmoon merged commit 884a4f5 into TextureGroup:master Aug 22, 2017
bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
…(default) element size range (TextureGroup#525)

* Table and collection views to consider their content inset when calculating element size range

* Update CHANGELOG

* Address comments

* -[ASPagerNode currentPageIndex] to use pageSize instead of bounds

* Update documentation in ASPagerNode

* Minor change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants