kizitonwose / Calendar

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

Bug: monthCalendarView.findFirstVisibleDay()?.date & weekCalendarView.findFirstVisibleDay()?.date returns null after setup the calendar #458

Closed jay22794 closed 1 year ago

jay22794 commented 1 year ago

Library information:

Describe the bug**

I am using Example 1 from the view module and encountered one bug. Once the setup method is called for the monthly and weekly calendars, when I try to get the first & last visible day using monthCalendarView.findFirstVisibleDay()?.date or weekCalendarView.findFirstVisibleDay()?.date, it always returns null.

To Reproduce (if applicable)

Steps to reproduce the behavior:

  1. Go to Example 1
  2. Log the monthCalendarView.findFirstVisibleDay()?.date or weekCalendarView.findFirstVisibleDay()?.date after the setup. It will be null. The same goes for the last date.

Expected behavior (if applicable)

It should return the first/last date

Can you please look into it, and provide a fix or workaround?

Thanks for the fantastic library!

kizitonwose commented 1 year ago

After the setup, the calendar still needs a layout pass to determine the first/last visible days. Did you try with

calendarView.post { 
// find day here
}
jay22794 commented 1 year ago

Yes, It worked. Thanks