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

SwiftUI visible month #280

Open
berbaspin opened this issue Oct 25, 2023 · 4 comments
Open

SwiftUI visible month #280

berbaspin opened this issue Oct 25, 2023 · 4 comments

Comments

@berbaspin
Copy link

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.

@4erenkevi4
Copy link

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

@jl-mobitech
Copy link

jl-mobitech commented Dec 22, 2023

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?

@theoks
Copy link

theoks commented Apr 21, 2024

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.

@jonathansds
Copy link

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!

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

5 participants