-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Alignment horizontal scroll collection view #60
Comments
Hey @palozinski ! So sorry for the late reply 😢 I've been soo busy at work and life. |
Hi Maher, thanks for this library. I'm going to hijack this issue because I think I'm looking for the same thing. I was thinking about how to do this, and I think it's rather complicated? I guess you would need to make If my designer doesn't reconsider, I could then help implement it. |
Hello @julianvogels ! I'm so sorry for the late reply... |
Hey, @MaherKSantina here is an example from the AppStore. Please look at the first item it is always great aligned to left and you can see the next item. Then further items are really great center and you can see both left and right side items. |
Hello @palozinski ! Thanks for the recording! So here's my explanation If you look closely you would see that there is some padding but since the peeking is small in width it doesn't show, here's another screenshot of the space with arrows showing that there is actually space on the left: The arrows on the left and right have the same width, and essentially you can fit a peeking cell on the left within that space and it will look exactly like the one on the right. To validate that using this library you can run the demo project and set the peeking width to something small (Something between 10-15 points) and it should look something similar to the app store Hope this helps, please let me know if you have any questions 🙏 |
If anyone still needs a solution for showing first and last cells with custom paddings, I think I might have found a workaround. Basically, all you need to do is to change contentInset property of the collection view, that is using MSCollectionViewPeekingBehavior. Let's assume, that you have some constants CellSpacing and VisibleCellWidth, that are used for initializing MSCollectionViewPeekingBehavior object (or if you just change its properties). Something like:
To calculate proper collection view's content insets, you have to calculate left and right insets separately (I have no idea why they are different, but I found out by trial and error that right content inset should differ from the left one by exactly one cell spacing). So it will look like this:
And now the magic workaround part. You have to use calculated values but with opposite sign (i.e. negative values) as collection view content insets like this:
This should remove left inset for the first cell and right inset for the last cell. Note, that I tested this only for collection view with HORIZONTAL scroll direction, that shows 1 cell, but I think it should work for collection view with vertical scroll direction too, only that you should calculate top and bottom insets, obviously. Might even work for more cells in the screen. Now, if you want to add insets and not just remove them, then you have to add preferred values to the NEGATIVE calculated values, and use new calculated value AS IT IS like this:
Hope it helps to anyone. And also @MaherKSantina thank you for your work on this library. Saved a lot of time by using it. 🔥 UPD: Added gifs showing workaround applied to the example project
|
Hey,
any idea hot to align horizontal collection view items to left when it is first item then after that could work normally with centered item. Like AppStore product carousel ...
The text was updated successfully, but these errors were encountered: