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

sizeForItem delegate function is not called when peek behavior is configured #63

Closed
johnCbogil opened this issue May 7, 2020 · 6 comments

Comments

@johnCbogil
Copy link

johnCbogil commented May 7, 2020

Hi there,

I noticed that when I have MSPeekCollectionViewDelegateImplementation implemented, that my collectionView's sizeForItem delegate function is not called. I'm not sure why though. Is this expected or perhaps I have a bug in my code? sizeForItem is called as expected when the peeking behavior is not configured.

I need to be able to configure my item's size while also implementing peek behavior. Does anybody have any advice?

@MaherKSantina
Copy link
Owner

Hello @johnCbogil ! Thanks for contributing to this repository by opening this issue!
After the last major update, this library started using a custom layout to position its cells. Since the sizeForItem function is only defined for the UICollectionViewDelegateFlowLayout protocol, technically it doesn't exist from this library's perspective.
The reason why this is done this way is because it's not feasible to let the developer change the size of each item manually. The idea of it is for the developer to specify the peeking and it will automatically calculate the cell sizes and display them.
The init for the behavior has a bunch of attributes you can set to make the library do what you want it to do:

init(cellSpacing: CGFloat = 20, cellPeekWidth: CGFloat = 20, minimumItemsToScroll: Int? = nil, maximumItemsToScroll: Int? = nil, numberOfItemsToShow: Int = 1, scrollDirection: UICollectionView.ScrollDirection = .horizontal, velocityThreshold: CGFloat = 0.2)

You can check the comments in the MSCollectionViewPeekingBehavior class to have more insights on each variable.
If this is not enough for you to be able to move forward happy to discuss with you here what you need to achieve and if it makes sense to add it to the library I'll work on it

Have a great day!

@johnCbogil
Copy link
Author

johnCbogil commented May 7, 2020

Ok that makes sense, I appreciate your speedy and thorough response @MaherKSantina!

If I understand you correctly, I should attempt to get my desired itemSize via the behavior's initializer? I only need 1 item size so I think this could work.

Thank you!

@MaherKSantina
Copy link
Owner

As far as I remember you can't get the item size from the library, it calculates it internally and updates the cells to be of that size, so you don't have to worry about you setting it. But do you want the item size to drive something outside the collection view? I'm still a bit confused on why you need the item size 😕

@johnCbogil
Copy link
Author

johnCbogil commented May 8, 2020

Sorry for the confusion. I understand now that I can't use the itemSize delegate function with the library. That makes sense.

My goal is for my items to be square (equal height and width). I believe that I can configure this via the behavior's initialization parameters.

@johnCbogil
Copy link
Author

I have solved my issue by doing a bit of math to determine the necessary cellSpacing to create square items.

Thank you @MaherKSantin !

@MaherKSantina
Copy link
Owner

Hahah I was just writing a comment about how to calculate it using spacing and peeking width 😆 I'm glad you were able to solve it on your own! Thank you so much for contributing and feel free to close this issue if your issue is resolved 👍

Have a wonderful day!

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

No branches or pull requests

2 participants