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

calendar.currentSection() skips the multiple of 10th section #1266

Open
kushsolitary opened this issue May 9, 2020 · 2 comments
Open

calendar.currentSection() skips the multiple of 10th section #1266

kushsolitary opened this issue May 9, 2020 · 2 comments

Comments

@kushsolitary
Copy link

Version: 8.0.3

So, I have only tested this with the weekly view, but when I check for calendar.currentSection in the didScrollToDateSegmentWith delegate method, it skips the multiples of 10th (id: 9) section. So if I print these values and start scrolling from the first section, I get the following:

0
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
18
20

As you can see, it misses the 9th and 19th section. This is not a major issue, but I found it while debugging calendarView.scrollToDate function when it's invoked with triggerScrollToDateDelegate: true, animateScroll: true. The problem is that for certain sections, the triggerScrollToDateDelegate triggers before the animation completes.

I narrowed it down to this function:

    func calendarOffsetIsAlreadyAtScrollPosition(forOffset offset: CGPoint) -> Bool {
        var retval = false
        // If the scroll is set to animate, and the target content
        // offset is already on the screen, then the
        // didFinishScrollingAnimation
        // delegate will not get called. Once animation is on let's
        // force a scroll so the delegate MUST get caalled
        let theOffset = scrollDirection == .horizontal ? offset.x : offset.y
        let divValue = scrollDirection == .horizontal ? frame.width : frame.height
        let sectionForOffset = Int(theOffset / divValue)
        let calendarCurrentOffset = scrollDirection == .horizontal ? contentOffset.x : contentOffset.y
        if calendarCurrentOffset == theOffset || (scrollingMode.pagingIsEnabled() && (sectionForOffset ==  currentSection())) {
            retval = true
        }
        return retval
    }

The currentSection() call in the above function returns the wrong section in some cases and hence it satisfies the condition which invokes the didScrollToDateSegmentWith prematurely.

I couldn't find a way to fix it but I am hoping someone here can point me to the right direction. Thank you!

@kushsolitary
Copy link
Author

For now, I have exposed a new function in the delegate scrollDidEndScrollingAnimation which fires after the didScrollToDateSegmentWith. This is a small hack to go around the issue but it seems to be working fine for me.

kushsolitary@a79b7af

@patchthecode
Copy link
Owner

patchthecode commented May 10, 2020

Thank you.
Will look at this in more detail once the covid19 situation is less.

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