HorizonCalendar
HorizonCalendar copied to clipboard
SwiftUI visible month
Hello!
Is is possible to get a visible month in SwiftUI?
There is a property visibleMonthRange
in UIKit, but we don't have it in SwiftUI version.
I used
.monthHeaderItemProvider{ month in
viewModel.visibleMonth = month.month
}
for this. Sometimes this may not work correctly, but I haven't found any other API method to view the visible month
I used
.monthHeaderItemProvider{ month in viewModel.visibleMonth = month.month }
for this. Sometimes this may not work correctly, but I haven't found any other API method to view the visible month
@4erenkevi4, when I tried this, the resources my app consumes skyrocketed. I'm wondering if you have a workaround around this?
@bryankeller, perhaps this would be a good API to introduce on the next update?
That's indeed a useful API, and it will also bridge nicely to its UIKit counterpart.
In the meantime, assuming that you know the initially selected date or the date that you use in order to scroll the calendar to the desired month, you could use the following method on the Foundation Calendar
you use in your CalendarViewRepresentable
:
calendar.dateInterval(of: .month, for: date)
This method returns a DateInterval
which contains the start and end Date
of the month in which date
belongs to, which essentially is the same month that's visible on screen.
You could call this method as soon as you have the starting date of your calendar view, either in one of your views (task
or onAppear
modifier) or in a view model.
Any estimate on when this will become available? In my usage of HorizonCalendar I need to track the visible month (horizontal layout). Even if I define a initial selected date and scroll to it (then having the inicial visible month) I still didn't figure out how to track the visible month when the user swipe to next/previous month. As a workaround I could provide the controls to scroll to next/previous months but for that I need to disable the ability to swipe through months and I didn't figure out how to do that either. Is someone able to help with this and/or provide an estimate on when then "visibleMonthRange" will be available for SwifitUI?
Thank you!