HorizonCalendar icon indicating copy to clipboard operation
HorizonCalendar copied to clipboard

SwiftUI visible month

Open berbaspin opened this issue 1 year ago • 4 comments

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.

berbaspin avatar Oct 25 '23 12:10 berbaspin

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 avatar Dec 18 '23 19:12 4erenkevi4

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?

Screenshot 2023-12-22 at 14 13 45

@bryankeller, perhaps this would be a good API to introduce on the next update?

jl-mobitech avatar Dec 22 '23 06:12 jl-mobitech

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.

theoks avatar Apr 21 '24 20:04 theoks

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!

jonathansds avatar Aug 13 '24 10:08 jonathansds