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

MSPeekImplementationDelegate returns under/over index in race conditions #67

Closed
fareast555 opened this issue Jun 26, 2020 · 5 comments
Closed

Comments

@fareast555
Copy link

MSPeekImplementationDelegate method:

func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation,
                            didChangeActiveIndexTo activeIndex: Int)   

Returns -1 if continuous fast swipe attempts made to go below the first cell...
or returns dataSource.count if trying to swipe beyond max cell.

This only happens when I really push it and swipe super fast.

Device: iPhone SE running 13.3.1
Xcode 11.3.1
Installed via cocoapods

pod 'MSPeekCollectionViewDelegateImplementation', '~> 2.0.0'

Screen Shot 2563-06-26 at 20 33 21

@MaherKSantina
Copy link
Owner

Hello @fareast555 ! Thank you so much for raising this issue and pasting all the evidence!
I would like you to try the latest version of the pod (3.1.1) which was completely re-written to use custom collection view layouts, which might solve this issue.
Unfortunately, I'm not supporting v2 anymore because it was painful in the end to try to customize it.
All details related to the setup of this pod are in the Readme, and feel free to ask me anything if something is unclear or not working!

Have a great day!

@fareast555
Copy link
Author

fareast555 commented Jun 28, 2020

Hi @MaherKSantina . Thanks for the reply. One guy in our team had a pull request in updating to 3.1.1, thought it was already in, but it's still under review. Once it gets in I'll run some tests and update you.

Actually, there are two issues, both which will hopefully disappear. The first is as reported here. The second, which I assumed might be related to this one -- which seems like a race time issue -- is that there are occasions where the collection view sends back the active index of the cell before the last cell, but shows the last cell in the array. As with the issue reported here, you have to really try a bunch of times quickly to go over index to get it to do it.

Anyway, for now, I'll close off this issue if that's OK. If I see it in the 3.1.1 I'll open up a new issue. Thanks for making this insanely useful implementation. Getting collection views to work as expected is a pain, so this is really a great bit of software.

@fareast555
Copy link
Author

And...as a PS. I'm digging into the latest code. Is there no longer any callback for an active Index?

@MaherKSantina
Copy link
Owner

MaherKSantina commented Jun 28, 2020

@fareast555 thank you soo much for your kind words! 🙏 Yeah I agree working with collection views is sometimes hard!

Is there no longer any callback for an active Index?

There is one that gives you the current index when the user scrolls to a new cell, you just have to conform to UICollectionViewDelegate and implement scrollViewDidEndDecelerating function. The code to do that is also available in the demo project, I'll write it here:

extension ViewController: UICollectionViewDelegate {

    ...

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        print(behavior.currentIndex)
    }
}

Please let me know if that works 👍

@fareast555
Copy link
Author

I'll give it a try. Cheers!

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

2 participants