peterent/MultiDatePicker

Binding does not work

Opened this issue · 1 comments

The Binding does not seem to work under iOS16.2, SwiftUI, XCode 14.2

I call the CalendarView like so:

.sheet(item: $activeSheet) { sheet in
    switch sheet {
    case .mySheet:
        CalendarView(dateRange: $dateRange)
    }
}
.onAppear {
    let dateComponents = DateComponents(year: 2023, month: 01, day: 10)
    let startDate = Calendar.current.date(from: dateComponents)!
    let endDate = startDate.addingTimeInterval(60 * 60 * 24 * 10)
    dateRange = startDate...endDate
}

Once opened, then I try to make the dateRange show your MultiDatePicker plus an extra Button.

When pressing the "New Date Range" Button, I try to show a completely new date-range in the opened CalendarView.

But this does not work !

I suspect the binding to be wrong.

Or how would you change the dateRange upon button click ?

import SwiftUI
import FSCalendar

struct CalendarView: View {
    
    @Binding var dateRange: ClosedRange<Date>?
    
    var body: some View {
        VStack {
            MultiDatePicker(dateRange: $dateRange)
            HStack {
                Button {
                    let dateComponents = DateComponents(year: 2023, month: 02, day: 21)
                    let startDate = Calendar.current.date(from: dateComponents)!
                    let endDate = startDate.addingTimeInterval(60 * 60 * 24 * 5)
                    dateRange = startDate...endDate
                } label: {
                    Text("New Date Range")
                }
            }
        }
    }
}