Skip to content

Conversation

@mirmanov
Copy link

@mirmanov mirmanov commented Mar 14, 2025

Details

This fixes the behaviour of VisibleItemsProvider.correctedScrollToItemFrameForContentBoundaries during animated scroll to a date on calendars with scrollable content where all months can be visible at once, fully or partially.
The main issue is that the calendar scrolls to the very top, when requested to scroll to an arbitrary date of the first month using firstFullyVisiblePosition.
This is due to an incorrect assumption in VisibleItemsProvider.correctedScrollToItemFrameForContentBoundaries, that if context.contentEndBoundary is known, then content is smaller than bounds. There certainly can be cases, when the first and the last months in the calendar are visible (i.e. context.contentStartBoundary and context.contentEndBoundary are known) and the content is still larger than bounds. Therefore, we should explicitly check if the content is actually smaller than bounds, before adjusting scroll towards minimumScrollOffset.

Before fix After fix
https://github.com/user-attachments/assets/c05d249b-5d29-4616-9dbb-43874f6e1281 https://github.com/user-attachments/assets/58be438f-05e0-4ce4-92fb-83b61ea96ed6

Related Issue

N/A

Motivation and Context

Bug fix / animation improvements

How Has This Been Tested

Example app. In SingleDaySelectionDemoViewController, update the endDate, so that the visibleDateRange has a span of three months:

let endDate = calendar.date(from: DateComponents(year: 2020, month: 03, day: 31))!

and add a call to scroll method at the end of daySelectionHandler:

if let selectedDate {
  calendarView.scroll(toDayContaining: selectedDate, scrollPosition: .firstFullyVisiblePosition, animated: true)
}

Build and run.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

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