airbnb / HorizonCalendar

A declarative, performant, iOS calendar UI component that supports use cases ranging from simple date pickers all the way up to fully-featured calendar apps.
Apache License 2.0
2.8k stars 234 forks source link

Performance issues with `dayItemProvider` in CalendarViewRepresentable #289

Closed kevalkorat closed 9 months ago

kevalkorat commented 9 months ago

I am seeing some jittery scroll when using dayItemProvider in a vertical layout. My use case is to show a yearly calendar with some data for below each calendar day. But even slight customisation of dayItemProvider makes the scroll jittery.

@bryankeller Try to demo this with and without dayItemProvider and you shall notice jittery scroll view. The jitter is not very noticeable but does not feel like a smooth experience.

Not sure if I am missing something here for optimisation.

Below is the code I tested with

struct HorizonCalendarView: View {
    let startDate = Calendar.current.date(from: DateComponents(year: 2020, month: 01, day: 01))!
    let endDate = Date.now

    var body: some View {
        CalendarViewRepresentable(
            visibleDateRange: startDate...endDate,
            monthsLayout: .vertical,
            dataDependency: nil)

            .dayItemProvider { day in
                VStack {
                    Text(day.day.description)
                    Text("0")
                }
                .calendarItemModel
            }
    }
}
kevalkorat commented 9 months ago

Closing the issue as after much testing it seems to be scrolling just fine but in the morning I swear I was seeing laggy scroll view but that could be because of the system.