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

IndexPath.row "3" Issues #3

Closed
alessign opened this issue Mar 3, 2018 · 8 comments
Closed

IndexPath.row "3" Issues #3

alessign opened this issue Mar 3, 2018 · 8 comments
Labels

Comments

@alessign
Copy link

alessign commented Mar 3, 2018

Hello, thanks for sharing this library. Exactly what I was looking for. I found one problem which I can't explain its behaviour and where is it coming from. I need to use the index of the visible cell to save it as a progress, so next time the user loads the collection view with the specific theme, it can scroll to index where it was left last time.

It's straight forward implementation, but the issue is, for whatever reason, the count always ignores index "3" and it goes like this: 1, 2, 2, 4, 5, .... even swiping backwards ...5, 4, 2, 2, 1

Home.swift:

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        let visibleIndexPath = collectionView.indexPathsForVisibleItems
        let lastCardIndex = visibleIndexPath[0].row + 1
        print("visible index: \(lastCardIndex)")
    }

Where do I look within the code to tackle this?

Also, the very last card has an offset on Y axe. I couldn't figure out where to disable it. I'd like to animate the last card the same way and keep it in centre of the view as the other cards. The idea is to:

  • display "Done" statement
  • assign same BG colour as a view, so it looks it disappeared into it after the scroll animation finishes
  • disable user interaction with bool

Thank you for your suggestions

Kind regards

A.

@JoniVR
Copy link
Owner

JoniVR commented Mar 3, 2018

Hi @alessign,

I'm glad you like it, I built this because I was looking for something like this myself and couldn't find anything.

I looked into the index bug, and it seems like you're right, I haven't figured out what is causing it yet, but I'll look into it when I get some more time.

About the card having an offset on the Y-axis, this is also something I wasn't aware of, but it's been noted and I'll look into it when I have time as well.

Keep in mind that I'm still working out some bugs, and it's not ready for use in applications yet (for example, if you scroll down some cards and then try to swipe to dismiss the first card, sometimes the animation glitches). You're free to use it, just be aware that there still are some bugs in there.

I'm trying to work on it whenever I have time but I'm currently pretty busy, feel free to submit a pull request if you can fix the bug before I do, it's always appreciated.

Best Regards,
Joni

@JoniVR JoniVR added the bug label Mar 3, 2018
@alessign
Copy link
Author

alessign commented Mar 3, 2018

Hi Joni, thanks for the swift answer! Of course I am aware there will be some little bugs to improve, but great job so far!

If I'll find solution/s before you do, I'll share it of course.

Best,

A.

@JoniVR
Copy link
Owner

JoniVR commented Mar 3, 2018

Hi @alessign,

I looked into the code some more and did some testing, from what I could find, there's no problem with the indexpaths after all (you can test this by adding a label to the cardcell and assigning the indexpath.row value to the label in the cellforitem function)

as for finding which cell is currently being displayed, I think I've found something that might help you out with this (if I understand what you're trying to do correctly).

Could you try the following and let me know if it works for you?

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        
        var visibleRect = CGRect()
        visibleRect.origin = collectionView.contentOffset
        visibleRect.size = collectionView.bounds.size
        
        let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
        
        let visibleIndexPath: IndexPath? = collectionView.indexPathForItem(at: visiblePoint)!
        
        guard let indexPath = visibleIndexPath else { return }
        print(indexPath)
    }

I'll look more into your second issue whenever I get some more time, because that's definitely one that needs fixing ;)

@alessign
Copy link
Author

alessign commented Mar 4, 2018

Great! Thanks for looking into this. I was about to implement manual counter updating method, but this is much simpler.

Cheers!

@alessign
Copy link
Author

alessign commented Mar 6, 2018

Also, I came across VegaScroll repo just now. It may be helpful for you when improving your repo: https://github.com/ApplikeySolutions/VegaScroll

@JoniVR
Copy link
Owner

JoniVR commented Mar 6, 2018

I'm aware of VegaScroll (I actually did a small PR there once), but I think their system is completely different, they also don't really have to deal with cell based paging as far as I'm aware, but thanks for sharing 🙂 I'll probably end up rewriting the targetContentOffset function, as it's not perfect yet.

JoniVR pushed a commit that referenced this issue Mar 8, 2018
@JoniVR
Copy link
Owner

JoniVR commented Mar 8, 2018

Hi @alessign,

I pushed a commit (9c428f7) to the development branch which should fix the offset at the Y-axis at the bottom.

For the "disable user interaction with a bool", you could try looking at collectionView.isUserInteractionEnabled.

Hope this helps, where there any other issues or things I missed?
(I'll probably rewrite the cell paging code later when I get some time but this should work for now)

Best regards,
Joni

@alessign
Copy link
Author

alessign commented Mar 8, 2018

Great, thanks! That was easy enough. I wasn't able to figure it out. And yes, I will use the method you suggested to lock the completed "flashcard deck"

Cheers!

@alessign alessign closed this as completed Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants