Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when switching between different calendars #307

Open
Mina-H-Samy opened this issue May 25, 2024 · 0 comments
Open

Crash when switching between different calendars #307

Mina-H-Samy opened this issue May 25, 2024 · 0 comments

Comments

@Mina-H-Samy
Copy link

Mina-H-Samy commented May 25, 2024

First, thanks for a great library! I have a usecase where I want to allow users to pick a date in whichever calendar they choose. I also do not have any limits on date ranges. There seems to be an issue with switching the calendar, like so:

import SwiftUI
import HorizonCalendar

struct CalView : View {
    @State private var calendarIdentifier: Calendar.Identifier = .gregorian
    private var calendar: Calendar { Calendar(identifier: calendarIdentifier) }
    
    var body: some View {
        VStack {
            Picker("calendarType", selection: $calendarIdentifier) {
                Text("Gregorian").tag(Calendar.Identifier.gregorian)
                Text("Coptic").tag(Calendar.Identifier.coptic)
            }.pickerStyle(.segmented).fixedSize()
            
            CalendarViewRepresentable(
                calendar: calendar,
                visibleDateRange: (Date.distantPast...Date.distantFuture),
                monthsLayout: .horizontal(options: HorizontalMonthsLayoutOptions()),
                dataDependency: calendarIdentifier,
                proxy: nil
            )
        }
    }
}

Selecting "Coptic" in the picker will crash with:

HorizonCalendar/VisibleItemsProvider.swift:431: Fatal error:   Could not determine the origin of the month containing the layout item type day(0001-01-01).

This doesn't happen if the visibleDateRange is smaller, for example (Date(timeIntervalSince1970: 0)...Date()) works just fine.

It seems there is some cached state that needs to be refreshed when the calendar is changed? Or perhaps I'm doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant