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 version #311

Draft
wants to merge 56 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
978aaa9
replaced all day view
kvyatkovskys Mar 18, 2023
6ede593
working on list view
kvyatkovskys Mar 19, 2023
96b741b
working on YearView (SwiftUI)
kvyatkovskys Mar 27, 2023
a4edd20
test
kvyatkovskys Mar 27, 2023
9f6712d
working on month view
kvyatkovskys Mar 28, 2023
ee4e9b0
month view view for iphone
kvyatkovskys Mar 30, 2023
f81c021
working on month view for ipad
kvyatkovskys Apr 1, 2023
b578ef8
fixes for YearView
kvyatkovskys Apr 1, 2023
7c99bd9
working on scroll header view
kvyatkovskys Apr 2, 2023
155095a
replaced the WeekScrollableView on SwiftUI
kvyatkovskys Apr 2, 2023
c37ca85
started to work on timeline view
kvyatkovskys Apr 3, 2023
40b56ba
working on timeline view
kvyatkovskys Apr 9, 2023
a3b40f3
working on timeline views
kvyatkovskys Apr 23, 2023
3f7ff08
fixes
kvyatkovskys Apr 23, 2023
8a18c98
working on column events
kvyatkovskys Apr 29, 2023
63644cf
finished alpha version of timeline
kvyatkovskys May 6, 2023
2cd45ef
created the new week view
kvyatkovskys May 6, 2023
4d35797
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys May 8, 2023
f956187
working on WeekView (timeline + header week)
kvyatkovskys May 9, 2023
d85b37f
added swipe between pages
kvyatkovskys May 11, 2023
f795762
opened the ListView
kvyatkovskys May 22, 2023
d1341ff
working on day view inside week view
kvyatkovskys May 22, 2023
225c338
minor event view improvements
kvyatkovskys May 29, 2023
d87ae16
clean project
kvyatkovskys Jun 6, 2023
1dd4acc
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Jun 6, 2023
e56041a
working on all view in SUI
kvyatkovskys Jun 18, 2023
1135b1f
display events
kvyatkovskys Jun 18, 2023
ef2f20f
working on week view
kvyatkovskys Jul 21, 2023
4d7a160
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Aug 7, 2023
05e33e0
Squashed commit of the following:
kvyatkovskys Sep 11, 2023
ff801e9
Squashed commit of the following:
kvyatkovskys Sep 11, 2023
2b80863
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Jan 7, 2024
d3d62e3
refactoring and fixes
kvyatkovskys Jan 8, 2024
387de2e
horizontal week view
kvyatkovskys Jan 12, 2024
71dadbd
new scrollable week view, timeline fixes when scrolling between pages
kvyatkovskys Jan 14, 2024
4e3a706
working on month view
kvyatkovskys Jan 15, 2024
6bf41d3
fixed issue with non main thread
kvyatkovskys Jan 18, 2024
af83892
switched to @Observable for month view
kvyatkovskys Jan 20, 2024
b9e5524
some fixes and improvements for month and year views
kvyatkovskys Jan 21, 2024
892dfd7
corrections
kvyatkovskys Jan 21, 2024
c48e19c
fixed freezes and problems on year and month view
kvyatkovskys Jan 24, 2024
d9c5791
fixes for month and year view
kvyatkovskys Jan 25, 2024
1a9e9a5
views improvements
kvyatkovskys Feb 4, 2024
54bb6f3
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Feb 4, 2024
ce534e7
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Feb 18, 2024
5883341
some fixes and improvements - Scroll week view, Month view
kvyatkovskys Feb 18, 2024
11a02a3
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Jul 6, 2024
fac0a8c
sui color property
kvyatkovskys Jul 11, 2024
c9f5e4f
Merge branch 'master' into feature/v_0.7.0
kvyatkovskys Oct 4, 2024
b9d0ae8
continue working on SUI version
kvyatkovskys Oct 7, 2024
ba63680
issue with adding a new event on timeline view
kvyatkovskys Oct 23, 2024
59ca43b
no need additional checks
kvyatkovskys Oct 23, 2024
f15271f
fixes
kvyatkovskys Oct 24, 2024
91c9872
checking delegate
kvyatkovskys Oct 24, 2024
2ae80af
Merge branch 'feature/v_0.6.28' into feature/v_0.7.0
kvyatkovskys Oct 24, 2024
1625e3f
use ui collection view to display the horizontal weeks view
kvyatkovskys Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 43 additions & 51 deletions Example/Example For SwiftUI/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,62 @@
import SwiftUI
import KVKCalendar

@available(iOS 14.0, *)
@available(iOS 18.0, *)
struct CalendarView: View {

@State private var typeCalendar = CalendarType.day
@State private var events: [Event] = []
@State private var updatedDate: Date?
@State private var orientation: UIInterfaceOrientation = .unknown
@ObservedObject private var viewModel = CalendarViewModel()

@State private var vm = CalendarViewModel()
@State private var date = Date()

var body: some View {
kvkHandleNavigationView(calendarView)
NavigationStack {
calendarView
.task {
await vm.loadEvents()
}
}
}

private var calendarView: some View {
CalendarViewDisplayable(events: $events,
type: $typeCalendar,
updatedDate: $updatedDate,
orientation: $orientation)
.kvkOnRotate(action: { (newOrientation) in
orientation = newOrientation
})
.onAppear {
viewModel.loadEvents { (items) in
events = items
}
}
.navigationBarTitle("KVKCalendar", displayMode: .inline)
.edgesIgnoringSafeArea(.bottom)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
HStack {
ItemsMenu<CalendarType>(type: $typeCalendar,
items: CalendarType.allCases,
showCheckmark: true,
showDropDownIcon: true)

Button {
updatedDate = Date()
} label: {
Text("Today")
.font(.headline)
.foregroundColor(.red)
KVKCalendarSwiftUIView(type: vm.type,
date: $vm.date,
events: vm.events,
event: $vm.selectedEvent,
style: vm.style)
.kvkOnRotate(action: { (newOrientation) in
vm.orientation = newOrientation
})
.toolbar {
ToolbarItemGroup(placement: .topBarLeading) {
Picker(vm.type.title, selection: $vm.type) {
ForEach(CalendarType.allCases) { (type) in
Text(type.title)
}
}
.tint(.red)
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
if let event = viewModel.addNewEvent() {
events.append(event)
ToolbarItemGroup(placement: .topBarTrailing) {
if UIDevice.current.userInterfaceIdiom == .phone {
Button {
vm.date = .now
} label: {
Text("Today")
.font(.headline)
}
.tint(.red)
}
} label: {
Image(systemName: "plus")
.foregroundColor(.red)
Button {
vm.addNewEvent()
} label: {
Image(systemName: "plus")
}
.tint(.red)
}

}
}
}

}

@available(iOS 14.0, *)
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
CalendarView()
}
@available(iOS 18.0, *)
#Preview {
CalendarView()
}
3 changes: 0 additions & 3 deletions Example/Example For SwiftUI/CalendarViewDisplayable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ struct CalendarViewDisplayable: UIViewRepresentable, KVKCalendarSettings, KVKCal
@Binding var updatedDate: Date?
@Binding var orientation: UIInterfaceOrientation

var style: Style {
createCalendarStyle()
}
var selectDate = Date()

private var calendar = KVKCalendarView(frame: .zero)
Expand Down
32 changes: 20 additions & 12 deletions Example/Example For SwiftUI/CalendarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,35 @@
// Copyright © 2022 CocoaPods. All rights reserved.
//

import Foundation
import SwiftUI
import KVKCalendar

final class CalendarViewModel: ObservableObject, KVKCalendarSettings, KVKCalendarDataModel {
@available(iOS 17.0, *)
@Observable final class CalendarViewModel: KVKCalendarSettings, KVKCalendarDataModel {

// 🤔👹🍻😬🥸
// only for example
var type = CalendarType.week
var orientation: UIInterfaceOrientation = .unknown
var events: [Event] = []

var style: KVKCalendar.Style {
createCalendarStyle()
var date = Date()
var selectedEvent: KVKCalendar.Event?

init() {
date = defaultDate
}

func loadEvents(completion: @escaping ([Event]) -> Void) {
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 3) {
self.loadEvents(dateFormat: self.style.timeSystem.format, completion: completion)
func loadEvents() async {
try? await Task.sleep(nanoseconds: 300_000_000)
let result = await loadEvents(dateFormat: style.timeSystem.format)
await MainActor.run {
events = result
}
}

func addNewEvent() -> Event? {
handleNewEvent(Event(ID: "-1"), date: Date())
func addNewEvent() {
var components = DateComponents(year: date.kvkYear, month: date.kvkMonth, day: date.kvkDay)
components.minute = date.kvkMinute + 30
guard let newEvent = handleNewEvent(Event(ID: "\(events.count + 1)"), date: components.date ?? date) else { return }
events.append(newEvent)
}

}
4 changes: 2 additions & 2 deletions Example/KVKCalendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 60;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -300,7 +300,7 @@
};
};
buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "KVKCalendar" */;
compatibilityVersion = "Xcode 14.0";
compatibilityVersion = "Xcode 15.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down
27 changes: 18 additions & 9 deletions Example/KVKCalendar/KVKCalendarSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import EventKit
protocol KVKCalendarDataModel {

var events: [Event] { get set }
var style: Style { get }

}

protocol KVKCalendarSettings {}

extension KVKCalendarSettings where Self: KVKCalendarDataModel {

var style: Style {
createCalendarStyle()
}

func handleChangingEvent(_ event: Event, start: Date?, end: Date?) -> (range: Range<Int>, events: [Event])? {
var eventTemp = event
guard let startTemp = start, let endTemp = end else { return nil }
Expand Down Expand Up @@ -63,7 +66,7 @@ extension KVKCalendarSettings where Self: KVKCalendarDataModel {
let endTime = timeFormatter(date: end, format: style.timeSystem.format, local: style.locale)
newEvent.start = start
newEvent.end = end
newEvent.ID = "\(events.count + 1)"
newEvent.uniqID = "\(events.count + 1)"
newEvent.title = TextEvent(timeline: "\(startTime) - \(endTime)\n new time",
month: "\(startTime) - \(endTime)\n new time",
list: "\(startTime) - \(endTime)\n new time")
Expand All @@ -84,18 +87,26 @@ extension KVKCalendarSettings where Self: KVKCalendarDataModel {
}

func loadEvents(dateFormat: String, completion: ([Event]) -> Void) {
completion(prepareEvents(dateFormat: dateFormat))
}

func loadEvents(dateFormat: String) async -> [Event] {
prepareEvents(dateFormat: dateFormat)
}

private func prepareEvents(dateFormat: String) -> [Event] {
let decoder = JSONDecoder()

guard let path = Bundle.main.path(forResource: "events", ofType: "json"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe),
let result = try? decoder.decode(ItemData.self, from: data) else { return }
let result = try? decoder.decode(ItemData.self, from: data) else { return [] }

let events = result.data.compactMap({ (item) -> Event in
return result.data.compactMap({ (item) -> Event in
let startDate = formatter(date: item.start, local: style.locale)
let endDate = formatter(date: item.end, local: style.locale)
let startTime = timeFormatter(date: startDate, format: dateFormat, local: style.locale)
let endTime = timeFormatter(date: endDate, format: dateFormat, local: style.locale)

var event = Event(ID: item.id)
event.start = startDate
event.end = endDate
Expand Down Expand Up @@ -127,15 +138,13 @@ extension KVKCalendarSettings where Self: KVKCalendarDataModel {
}
return event
})
completion(events)
}

}

extension KVKCalendarSettings {

var defaultStringDate: String {
"14.11.2022"
"14.11.2024"
}

var defaultDate: Date {
Expand All @@ -149,7 +158,7 @@ extension KVKCalendarSettings {
}

func handleCustomEventView(event: Event, style: Style, frame: CGRect) -> EventViewGeneral? {
switch event.ID {
switch event.uniqID {
case "2":
return CustomViewEvent(style: style, event: event, frame: frame)
case "1400":
Expand Down
2 changes: 1 addition & 1 deletion Example/KVKCalendar/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
return navVC
}

if #available(iOS 14.0, *) {
if #available(iOS 18.0, *) {
#if DEBUG_SwiftUI
return UIHostingController(rootView: CalendarView())
#else
Expand Down
Loading