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

Make DayComponentRange initializer public to support pre-selected date range in the calendar. #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IvanUshakov
Copy link

Details

Make initializer of DayComponentRange with Date range public

Related Issue

programmatically update de selection range

Motivation and Context

In the application that I am currently developing there is a need for a calendar with a selection of date ranges. In this case, I need to pass the date range already selected by the user to the calendar itself, and he can edit it. In your example you use DayComponentsRange to represent date ranges, this is very convenient and works for me. But I can't initialize it with Date objects. So I'll just make initializer public

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller
Copy link
Contributor

bryankeller commented Jan 28, 2024

Hi @IvanUshakov, there's no need to create this type yourself - its initializer is intentionally private.

What exactly is your use case? There are no parts of the public API of HorizonCalendar that require you to pass in these types, so I'd like to better understand what you're trying to do.

My recommendation is to convert DayComponents and DayRangeComponents to Foundation Dates, using the correct Foundation Calendar instance.

@IvanUshakov
Copy link
Author

In the example there is a class DayRangeSelectionTracker which shows well how you can select a range of dates. SwiftUIScreenDemo and DayRangeSelectionTracker uses DayComponentsRange for this. I need to pass the current selected dates by the user to a class similar to SwiftUIScreenDemo, but I cannot do because the initializer is declared as internal. Of course I can use system types for this, but it's not as easy as with DayComponentsRange. And if the user has to use system types, then perhaps the example should also use system types. Because in a large number of cases the user will edit the selected dates, and not just select them from scratch.

Сode is not correct, but it shows the idea:

struct AppCalendarView: View {
    @State private var selectedDayRange: DayComponentsRange?
    @Binding private var selectedRange: ClosedRange<Date>?

    init(selectedRange: Binding<ClosedRange<Date>?>) {
        _selectedRange = selectedRange
        if let selectedRangeBinding = selectedRangeBinding?.wrappedValue {
            self.selectedDayRange = .init(containing: selectedRangeBinding, in: calendar)
        }
        ...
    }
    ...
}

@IvanUshakov
Copy link
Author

@bryankeller have you any updates on this?

@varyamereon
Copy link

@bryankeller Was there an issue with this pull request? Seems it's been waiting to merge for a while and this would be very useful for me!!

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

Successfully merging this pull request may close these issues.

3 participants