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

KDCalendar not compatible with SwiftUI #108

Open
shahedhossain opened this issue Jan 21, 2020 · 4 comments
Open

KDCalendar not compatible with SwiftUI #108

shahedhossain opened this issue Jan 21, 2020 · 4 comments

Comments

@shahedhossain
Copy link

MyCalendar structure for getting support in SwiftUI as following:

import SwiftUI
import KDCalendar

public struct MyCalendar: UIViewRepresentable {

    public func makeUIView(context: Context) -> CalendarView {
        return CalendarView()
    }

    public func updateUIView(_ calendar: CalendarView, context: Context) {
        let date: Date = Date()
        calendar.selectDate(date)
    }
}

It's shows only the week name and other parts of this calendar omitted from view and following errors occurred:

[Assert] negative or zero item sizes are not supported in the flow layout

Please find the details in StackOverflow

@shahedhossain shahedhossain changed the title KDCalendar not compatible for SwiftUI KDCalendar not compatible with SwiftUI Jan 21, 2020
@mmick66
Copy link
Owner

mmick66 commented Jan 21, 2020

I have not built it for SwiftUI, that is true. If however you would like to add this support and do a Pull Request I would be forever grateful ;-)

@suvov
Copy link
Contributor

suvov commented May 2, 2020

@shahedhossain It works with SwiftUI. The common problem is having keyboard on screen, when presenting UIViewRepresented view (or any other actually).
Zero or negative size assertion seems not to cause problems.

@shahedhossain
Copy link
Author

Hello @suvov. Good day!
Actually we are stacked on it. It would be best if you share your code snippet to the community to resolve such issues.

@suvov
Copy link
Contributor

suvov commented May 12, 2020

Hello @shahedhossain ! What I do is resign first responders (if any) before presenting the calendar.
It might look like this in code:

// Resign first responder, using UIKit (
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)

// Present view with calendar
self.isCalendarPresented = true

Might look like this in context:

Button(action: {
   UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder),  to: nil, from: nil, for: nil)
   self.isCalendarPresented = true
}, label: {
   Image(systemName: "calendar")
}).sheet(isPresented: $isCalendarPresented, content: {
   self.calendarView()
})

Hope this helps, have a good day!

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

3 participants