tyagishi / SDSCalendarViews

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SDSCalendarViews

platform macOS iOS iOS macOS SPM is supported license

view collection for Calendar

DayView

View for calendar event in one day

Screenshot

text

Usage

use together with CalendarViewModel

struct ContentView: View {
    @StateObject var calViewModel = CalendarViewModel.example()
    var body: some View {
        VStack {
            ScrollViewReader { scrollProxy in
                ScrollView(.vertical){
                    DayView(calViewModel, now: Date())
                        .frame(width: 200)
                        .frame(height: 1000)
                }
                .onAppear {
                    withAnimation {
                        scrollProxy.scrollTo(CalendarViewModel.formattedHour(Date()), anchor: .center)
                    }
                }
            }
        }
    }
}

ViewModel

/// ViewModel for CalendarViews(DayView/WeekView/MonthView in SDSCalendarViews)
public class CalendarViewModel: ObservableObject {
    // views will show startHour...endHour range
    @Published public private(set) var startHour: Int
    @Published public private(set) var endHour: Int

    /// events which will be shown on view
    /// note: might have allDayEvent
    @Published public private(set) var events: [Event] = []

    /// strategy how to put events in parallel (might be changed in the future, still under designing)
    public let layoutMode: LayoutMode// eventAlignMode: AlignMode

    let timeLabelWidth: CGFloat = 0
    ...
}
public struct Event: Identifiable {
    public var id: String // store calendarItemIdentifier in case of EKEvent, otherwise UUID().uuidString
    public var title: String
    public var start: Date
    public var end: Date
    public var color: Color
    public var isAllDay: Bool

    ...
}

About

License:MIT License


Languages

Language:Swift 100.0%