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

Vertical UICollectionViewLayout supporting inline sections #450

Closed
wants to merge 8 commits into from

Conversation

rnystrom
Copy link
Contributor

@rnystrom rnystrom commented Jan 27, 2017

Working on porting our collection view layout to IGListKit. I'm doing this because its a solid layout, and we just finished preparing it to work with inline sections. It is designed to work in tandem with IGListKit, so we're adding it.

This is still a WIP as I add more tests, but I'd love as much feedback as possible.

Aside from the glob of header documentation, this has the following features:

  • Infinite sections that each have infinite items. Sections and items can fall inline. When they break the width of their container they will fall on the next row.
  • Sections can have their own insets, line spacing, and interitem spacing.
  • Sticky header support! When you use headers, it will always newline the section.
  • Maximum width with a border decoration view
    • Use this to pinch in your content on larger devices

Followup to #423

TODO

  • Move decoration view support to delegate removed
  • Unit test changing top y sticky inset
  • Update initWithCoder: to use sensible defaults
  • Test initWithCoder: throws
  • Test when remaining cells outside of visible bounds
  • Move decorationBorderViewOfKind: internal? C function? (or add unit tests) removed
  • Unit test changing bounds size

@jessesquires
Copy link
Contributor

naming nit: how about just IGListCollectionViewLayout ?

@rnystrom
Copy link
Contributor Author

@jessesquires I dig it. I left "vertical" b/c atm it only supports v-scrolling, but we could maybe add horizontal down the road. Or not. I like that better.

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@jessesquires jessesquires added this to the 3.0.0 milestone Feb 1, 2017
@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@rnystrom
Copy link
Contributor Author

rnystrom commented Feb 2, 2017

@jeremycohen how do you feel about me landing this and setting up our internal tests? This is copy-pasted and cleaned up from D4455662.


Please see the unit tests for more configuration examples and expected output.
*/
IGLK_SUBCLASSING_RESTRICTED
Copy link

@zhubofei zhubofei Feb 2, 2017

Choose a reason for hiding this comment

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

Can we allow subclass here? Subclassing UICollectionViewFlowLayout proved to be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, maybe we could. It's not really designed to be subclassed, but I guess we could let people do that if they wanted. @jessesquires any thoughts?

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;

Sections and items are put into the same horizontal row until the max-y position of an item extends beyond the width
Copy link

@zhubofei zhubofei Feb 2, 2017

Choose a reason for hiding this comment

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

Sections and items are put into the same horizontal row until the max-y position of an item extends beyond the width

Should be max-x here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooops ya


const IGSectionEntry section = _sectionData[sectionCount - 1];
const CGFloat height = CGRectGetMaxY(section.bounds) + section.insets.bottom;
return CGSizeMake(MIN(CGRectGetWidth(self.collectionView.bounds), self.maximumContentWidth), height);
Copy link

Choose a reason for hiding this comment

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

Not sure if we should take collectionView.contentInset into account here.

Copy link

@zhubofei zhubofei Feb 2, 2017

Choose a reason for hiding this comment

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

It is my understanding that maximumContentWidth acts sort of like collectionView.contentInsethere so that we can have paddings on left and right. So, we do not take contentInset into account in this layout at all? However, we don't allow setting bottomInset in this layout. It is a little bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that collectionView.contentInset is used by the actual scroll view and isn't used in the layout calculations. For instance in Instagram we use a variation of this layout and set the content inset to sit underneath the nav bar and it works. But that's a good point I haven't really considered that before. I'm not sure if the layout is supposed to consider that... 🤔

Copy link

Choose a reason for hiding this comment

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

@rnystrom I found this tutorial on Raywenderlich.
screen shot 2017-02-04 at 11 10 35 pm
They took contentInset into account in this sample code. Idk if it is the common practice or not.

Copy link

@zhubofei zhubofei left a comment

Choose a reason for hiding this comment

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

👍👍👍

@rnystrom rnystrom changed the title WIP: Adding a vertical UICollectionViewLayout supporting inline sections Vertical UICollectionViewLayout supporting inline sections Feb 7, 2017
@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@weyert
Copy link
Contributor

weyert commented Feb 9, 2017

Any chance for an example which this new layout will bring us?

@stevejcox
Copy link

This is exactly what I need, arriving at just the right time!

@rnystrom
Copy link
Contributor Author

@weyert yup! We'll add one shortly. Still ironing out some internal kinks as we land this.

@rnystrom
Copy link
Contributor Author

Had a hiccup where we had to unland this, adding back ASAP

@weyert
Copy link
Contributor

weyert commented Feb 13, 2017

Thank you @rnystrom Does it mean you will support horizontal scrolling in inline controllers?

@rnystrom
Copy link
Contributor Author

@weyert you can use embedded lists or scroll views to achieve an h-scroll, inline effect. If you want to use h-scrolling section controllers, check out our example.

facebook-github-bot pushed a commit that referenced this pull request Feb 13, 2017
Summary:
Follow from #450, this layout has been replaced. You served us well!

- [x] All tests pass. Demo project builds and runs.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
Closes #482

Differential Revision: D4553897

Pulled By: rnystrom

fbshipit-source-id: caccb386ba8914fbbf5e81d997524efb78c6e4ea
@weyert
Copy link
Contributor

weyert commented Feb 16, 2017

@rnystrom Aha, so you need to make a collection view cell which in itself contains a UICollectionView instance again? I have to admit that I am really stupid and lost the clue by now. What's the added advantage of inline sections? Somehow I thought it was to add things like horizontal scrolling items.

@rnystrom
Copy link
Contributor Author

@weyert oh sorry, I should have explained better. Inline sections are nice b/c UICollectionViewFlowLayout will "newline" each section. So if you have sections, each with a single cell that is 1/3 the width of the screen (think Instagram grids), flow layout will put each section-cell at x position 0 with a bunch of white space filling the remaining 2/3 of the collection view. It'll look like a single column of cells on the left.

Hope that explains it!

@otymartin
Copy link

otymartin commented Apr 21, 2017

@rnystrom Just curious if the sticky headers is now supported so I can drop my collectionView in a tableviewcell structure?

Nevermind you mention it here #533

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

Successfully merging this pull request may close these issues.

7 participants