How to Use View Controller (Calendarkit) in Swiftui Application

Can I use View Controller (CalendarKit) in SwiftUI application?

Lol I don't know why it didn't work before, but if you are looking for something like this

struct CustomController: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIViewController, context: Context){
}

func makeUIViewController(context: Context) -> UIViewController {
let dayViewController = CustomCalendarExampleController()
return dayViewController
}
}

CalendarKit SwiftUI Events

Looks like you're using CalendarKit with SwiftUI.As of right now, SwiftUI is not supported out-of-the box.

Moreover, this API's purpose is to provide animations / gesture handling for the user, it doesn't actually creates events in the datasource.


dayView.updateStyle(style)
var testingEvents: [Event] = [Event]()
var event = Event()
event.startDate = Date()
event.endDate = Date()
event.isAllDay = true
event.text = "Testing Event"
dayView.create(event: event)

In order to solve your issue, I suggest making the following changes:

  1. Implement DayViewDataSource and any other CalendarKit interaction in the domain of UIKit.
  2. Bridge your custom subclass of DayViewController to SwiftUI and use that subclass in the SwiftUI domain (similar to the way you've provided in your code snippet)


Related Topics



Leave a reply



Submit