kizitonwose / Calendar

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.
MIT License
4.78k stars 508 forks source link

How to focus the month with VerticalYearCalendar on first load? #587

Open zeroarst opened 2 months ago

zeroarst commented 2 months ago

Library information:

Question:

When opening up VerticalYearCalendar, it focus on the given year at the top, but I want to make current day and the the current month visible when loaded.

For example, by chaning the Example11Page sample code.

Change https://github.com/kizitonwose/Calendar/blob/f0ddb8105b4e4c269bbf18f9e4428570ca4b0d43/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example11Page.kt#L53 to

val selections = remember { mutableStateListOf(CalendarDay(LocalDate.of(2024, 9, 10), DayPosition.MonthDate)) }

Change monthColumn to 2 to ensure that not all months are visible. Add code above to https://github.com/kizitonwose/Calendar/blob/f0ddb8105b4e4c269bbf18f9e4428570ca4b0d43/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example11Page.kt#L73 with

monthColumns = 2,

Change https://github.com/kizitonwose/Calendar/blob/f0ddb8105b4e4c269bbf18f9e4428570ca4b0d43/sample/src/main/java/com/kizitonwose/calendar/sample/compose/Example11Page.kt#L91-L93 to

// isMonthVisible = {
//     it.yearMonth >= currentMonth
// },

Launch the example. We can see that it does not focus on 2024 Sep. image

Is there any workaround for it?

kizitonwose commented 2 months ago

In the view version, there are scrollToMonth and scrollToDay functions in the year calendar, but these unfortunately do not yet exist in the compose library. I am hoping to add them at some point in the future when I have some time.