Skip to content

Conversation

@wtmoose
Copy link

@wtmoose wtmoose commented Jun 27, 2022

In my project, I have a calendar view that scrolls horizontaly one month at a time:

image

When calling calendar.scrollToDate(), the calendar was scrolling to the wrong month anytime the specified date was a Sunday. Specifically, it was scrolling to the next previous month.

The problem is due to the formula floor(frameSection) in targetPointForItemAt(). Naturally, frameSection may have small numerical errors. For example, a Sunday may yield frameSection == 49.9999999999999. However, floor(49.9999999999999) == 49 when the correct calculation should be 50.

One potential fix, which is the one I'm submitting in this PR, is to reduce the numerical precision of frameSection from double to single before calling floor(). This correctly results in floor(50) == 50.

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

Successfully merging this pull request may close these issues.

1 participant