kizitonwose / Calendar

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

Preload view in MonthDayBinder #536

Open nikunjparadvaAB opened 8 months ago

nikunjparadvaAB commented 8 months ago

Library information:

Question:

for swipe smoothly, How to Preload data in MonthDayBinder for previous and next month?

When i swipe the month then it lags some milliseconds. so what to do for preload views for some months?

  exFiveCalendar.dayBinder = object : MonthDayBinder<DayViewContainer> {
                override fun create(view: View) = DayViewContainer(view)

                override fun bind(container: DayViewContainer, data: CalendarDay) {
                    container.binding.tvDate.text = data.date.dayOfMonth.toString()
                    // Some code for event previews
                }
            }

I have this output

Screenshot_20240312_154634

kizitonwose commented 8 months ago

This is a bit tricky but you'll need to override the internal layout manager and override calculateExtraLayoutSpace.

See documentation

nikunjparadvaAB commented 8 months ago

how to add calculateExtraLayoutSpace for this?

<com.kizitonwose.calendar.view.CalendarView
        android:id="@+id/exFiveCalendar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cv_daySize="rectangle"
        android:background="@color/month_divider"
        app:cv_dayViewResource="@layout/item_month_day"
        app:cv_outDateStyle="endOfGrid" />
kizitonwose commented 7 months ago

There's no way to do this via xml presently.