Calendar icon indicating copy to clipboard operation
Calendar copied to clipboard

updateMonthRange changes scroll position when hasBoundaries=false

Open TanyaYu opened this issue 2 years ago • 3 comments

I am making an infinite scroll calendar without month sections. My configurations are

app:cv_scrollMode="continuous"
app:cv_hasBoundaries="false"
app:cv_inDateStyle="firstMonth"
app:cv_outDateStyle="endOfGrid"

This is how I setup the calendar

val firstMonth = YearMonth.now().withMonth(1)
val lastMonth = YearMonth.now().withMonth(1).plusYears(1)
val firstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek
calendarView.setup(firstMonth, lastMonth, firstDayOfWeek)
calendarView.scrollToDate(LocalDate.now(), DayOwner.THIS_MONTH)

When I want to expand the month range I use this function

calendarView.updateMonthRange(
    startMonth = YearMonth.now().withMonth(1).minusYears(1),
    endMonth = YearMonth.now().withMonth(1).plusYears(2)
)

When hasBoundaries is false,updateMonthRange always scrolls to the first month in the range (Jan 2021 in my case). It doesn't do it if hasBoundaries is true and is able to maintain it's scroll position.

How is it possible to update the month range unnoticeably to a user in my scenario?

TanyaYu avatar Aug 16 '22 19:08 TanyaYu

I know that I could use scrollToDate/smoothScrollToDate after updating the month range. But because I am using continuous scroll mode the days might not be perfectly alined and manual scrolling will be visible to a user.

TanyaYu avatar Aug 16 '22 20:08 TanyaYu

This looks like an issue from the diff util which is used to dispatch updates to the adapter internally, can you try this workaround?

kizitonwose avatar Aug 28 '22 13:08 kizitonwose

Thank you, @kizitonwose, but the workaround didn't help. I want to add that updating end month works for me just fine. However, when I update start month, the scroll position always changes to that month.

TanyaYu avatar Sep 06 '22 20:09 TanyaYu

This is now fixed in version 2.0.0

But the best part is that you do not need the infinite scroll logic anymore as the calendar now handles large date ranges efficiently.

kizitonwose avatar Oct 15 '22 19:10 kizitonwose