MaherKSantina / MSPeekCollectionViewDelegateImplementation

A custom paging behavior that peeks the previous and next items in a collection view
https://medium.com/@maher.santina90/how-to-create-cells-that-peek-on-the-sides-like-ios-11-app-store-ef4bb54c0c7d
MIT License
356 stars 32 forks source link

MSPeekImplementationDelegate returns under/over index in race conditions #67

Closed fareast555 closed 4 years ago

fareast555 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

MaherKSantina commented 4 years ago

@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 commented 4 years ago

I'll give it a try. Cheers!