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

Horizontal grid/property #90

Open
samirda opened this issue Jan 21, 2014 · 10 comments
Open

Horizontal grid/property #90

samirda opened this issue Jan 21, 2014 · 10 comments

Comments

@samirda
Copy link

samirda commented Jan 21, 2014

Horizontal grid layout or horizontal property on JNWCollectionViewGridLayout.

@jwilling
Copy link
Owner

Yes I had this planned, although I can't give a timeframe for this at the moment.

@samirda
Copy link
Author

samirda commented Jan 22, 2014

Great, which solution do you prefer? If I get some spare time.

@kettch
Copy link
Contributor

kettch commented Jan 25, 2014

Worked a bit on this, as a new layout. Is that OK with you guys this way?

@jwilling
Copy link
Owner

I was thinking perhaps the best way to implement this was to add a readonly property onto the base layout class that determines the scroll direction (vertical or horizontal).

Then quite a bit of the logic in the grid layout could be reused, although there would have to be quite a bit of conditionalization for the layout direction. Like so:

@interface JNWCollectionViewLayout : NSObject
...
@property (nonatomic, assign, readonly) JNWCollectionViewScrollDirection scrollDirection;
...
@end

Then layouts can specifically return which scroll direction they support, or alternatively they can override this property making it readwrite if they support both (which the grid layout would). This makes it a bit more generalized for all layouts, instead of making it specifically for the grid layout, since this requires changing behavior on the scroll view itself.

@kettch
Copy link
Contributor

kettch commented Jan 25, 2014

This is a hard one, because the code for this would be largely similar, but yet different in a lot of places... Even delegate calls like collectionView:heightForHeaderSection: wouldn't make much sense anymore.

But then maybe we're not even talking about the same thing, what would be a horizontal grid layout in your mind? Single-row layout, with one item per column, or multiple rows, but limited in height to the visible size?

@jwilling
Copy link
Owner

That's true, I hadn't thought about that. I was thinking of something more along the lines of having multiple rows by default with the height limited, with an option to restrict the maximum number of rows to effectively allow it to have both behaviors.

But yes unfortunately there's a lot of terminology here that doesn't mix well between the different layout directions. I just really don't like code duplication.

Also for what it's worth, I'd love to eventually write a fully featured flow layout (like UICollectionViewFlowLayout) and have the grid layout be a subclass of the flow layout. That's really how I wanted it to be originally but I just didn't have enough time to get a functioning flow layout working.

@kettch
Copy link
Contributor

kettch commented Jan 25, 2014

OK, so what I worked on so far is something else, more of a "horizontal list view", if you could call it that... I'll sleep on the horizontal grid thingie, maybe there's some way to make it work anyway.

@samirda
Copy link
Author

samirda commented Jan 26, 2014

I wrote a subclass of JNWCollectionViewLayout. It's basically a copy of JNWCollectionViewGridLayout, without the header and footer part. Logic is reversed to be horizontal. Not generic and should only be used with one row.

I think the logic for the placement in a generic horizontal layout should be

numberOfRows = collectionView.bounds.size.height / itemSize.height;
numberOfColumns = ceil(numberOfItems / numberOfRows);

placement of 3 rows and 10 items

1 2 3 4
5 6 7 8
9 10

My implementation only need one row so the default placement behaviour satisfies my needs but the same example using my layout would use a placement layout like this, which I think is wrong.

1 4 7 10
2 5 8
3 6 9

I'll be happy to share it.

@jwilling
Copy link
Owner

@samirda I'd love to see it! I'm not sure it's something I'd merge as I'm still attempting to go forward with a flow layout, but if you want to publish it as a separate repo (or as a fork if that's how you implemented it) then I'd be happy to take a look.

@samirda
Copy link
Author

samirda commented Feb 11, 2014

Sorry for the delay. https://gist.github.com/samirda/8942538 Logic is reversed to be horizontal. Not generic and should only be used with one row.

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

No branches or pull requests

3 participants