From e198e8e0ccadce749eb70f6a089ee028641bdb88 Mon Sep 17 00:00:00 2001 From: kviatkovskii <> Date: Mon, 17 Jun 2019 19:05:01 +0300 Subject: [PATCH 1/2] small fixes --- CalendarModel.swift | 116 ------------------ Example/Pods/Pods.xcodeproj/project.pbxproj | 8 -- KVKCalendar/Classes/CalendarView.swift | 108 ++++++++++++++++ KVKCalendar/Classes/ScrollDayHeaderView.swift | 11 +- KVKCalendar/Classes/TimelineView.swift | 13 +- View+Extension.swift | 19 --- 6 files changed, 129 insertions(+), 146 deletions(-) delete mode 100644 CalendarModel.swift delete mode 100644 View+Extension.swift diff --git a/CalendarModel.swift b/CalendarModel.swift deleted file mode 100644 index 48e38cdb..00000000 --- a/CalendarModel.swift +++ /dev/null @@ -1,116 +0,0 @@ -// -// CalendarModel.swift -// KVKCalendar -// -// Created by Sergei Kviatkovskii on 17/06/2019. -// - -import Foundation - -public enum TimeHourSystem: Int { - case twelveHour = 12 - case twentyFourHour = 24 - - var hours: [String] { - switch self { - case .twelveHour: - var array = [String]() - - for idx in 0...11 { - if idx == 0 { - array.append("12") - } else { - let string = String(idx) - array.append(string) - } - } - var am = array.map { $0 + " AM" } - var pm = array.map { $0 + " PM" } - - am.append("Noon") - pm.removeFirst() - pm.append(am.first!) - - return am + pm - case .twentyFourHour: - var array = [String]() - - for i in 0...24 { - if i == 0 { - array.append("00:00") - } else { - let i = i % 24 - var string = i < 10 ? "0" + "\(i)" : "\(i)" - string.append(":00") - array.append(string) - } - } - - return array - } - } -} - -public enum CalendarType: String, CaseIterable { - case day, week, month, year -} - -public struct Event { - public var id: Any = 0 - public var text: String = "" - public var start: Date = Date() - public var end: Date = Date() - public var color: UIColor? = nil { - didSet { - guard let color = color else { return } - backgroundColor = color.withAlphaComponent(0.3) - var hue: CGFloat = 0, saturation: CGFloat = 0, brightness: CGFloat = 0, alpha: CGFloat = 0 - color.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) - colorText = UIColor(hue: hue, saturation: saturation, brightness: brightness * 0.4, alpha: alpha) - } - } - public var backgroundColor: UIColor = UIColor.blue.withAlphaComponent(0.3) - public var colorText: UIColor = .black - public var isAllDay: Bool = false - public var isContainsFile: Bool = false - public var textForMonth: String = "" - public var eventData: Any? - - public init() {} -} - -protocol CalendarFrameProtocol { - func reloadFrame(frame: CGRect) -} - -protocol CalendarPrivateDelegate: AnyObject { - func didSelectCalendarDate(_ date: Date?, type: CalendarType) - func didSelectCalendarEvents(_ events: [Event]) - func didSelectCalendarEvent(_ event: Event, frame: CGRect?) - func didSelectCalendarMore(_ date: Date, frame: CGRect?) - func getEventViewerFrame(frame: CGRect) -} - -extension CalendarPrivateDelegate { - func getEventViewerFrame(frame: CGRect) {} -} - -public protocol CalendarDataSource: AnyObject { - func eventsForCalendar() -> [Event] -} - -public protocol CalendarDelegate: AnyObject { - func didSelectDate(date: Date?, type: CalendarType) - func didSelectEvents(_ events: [Event]) - func didSelectEvent(_ event: Event, type: CalendarType, frame: CGRect?) - func didSelectMore(_ date: Date, frame: CGRect?) - func eventViewerFrame(_ frame: CGRect) -} - -public extension CalendarDelegate { - func didSelectDate(date: Date?, type: CalendarType) {} - func didSelectEvents(_ events: [Event]) {} - func didSelectEvent(_ event: Event, type: CalendarType, frame: CGRect?) {} - func didSelectMore(_ date: Date, frame: CGRect?) {} - func eventViewerFrame(_ frame: CGRect) {} -} diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index e40ce0ee..93069294 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -38,8 +38,6 @@ F91321A421DE1A670076B714 /* AllDayEventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F91321A321DE1A670076B714 /* AllDayEventView.swift */; }; F91321A621DE24D60076B714 /* CalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F91321A521DE24D60076B714 /* CalendarView.swift */; }; F91321A821DE40590076B714 /* YearHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F91321A721DE40590076B714 /* YearHeaderView.swift */; }; - F987481B22B509F200E9F4C5 /* View+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F987481A22B509F200E9F4C5 /* View+Extension.swift */; }; - F987481D22B7E24800E9F4C5 /* CalendarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F987481C22B7E24800E9F4C5 /* CalendarModel.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -112,8 +110,6 @@ F91321A321DE1A670076B714 /* AllDayEventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AllDayEventView.swift; path = KVKCalendar/Classes/AllDayEventView.swift; sourceTree = ""; }; F91321A521DE24D60076B714 /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CalendarView.swift; path = KVKCalendar/Classes/CalendarView.swift; sourceTree = ""; }; F91321A721DE40590076B714 /* YearHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = YearHeaderView.swift; path = KVKCalendar/Classes/YearHeaderView.swift; sourceTree = ""; }; - F987481A22B509F200E9F4C5 /* View+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extension.swift"; sourceTree = ""; }; - F987481C22B7E24800E9F4C5 /* CalendarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarModel.swift; sourceTree = ""; }; FA2CDFE87246C08EF83AEEA2FA5D1E0A /* Pods-KVKCalendar_Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-KVKCalendar_Example-acknowledgements.plist"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -189,7 +185,6 @@ F913219B21DE1A0A0076B714 /* DayData.swift */, F913219D21DE1A1F0076B714 /* Date+Extension.swift */, F91321A121DE1A500076B714 /* Array+Extension.swift */, - F987481A22B509F200E9F4C5 /* View+Extension.swift */, F913218D21DE19560076B714 /* ScrollHeaderDayCollectionViewCell.swift */, F913218F21DE197B0076B714 /* ScrollDayHeaderView.swift */, F913218321DE18D90076B714 /* WeekHeaderView.swift */, @@ -199,7 +194,6 @@ F913218921DE19260076B714 /* TimelineLabel.swift */, F913218B21DE193A0076B714 /* Style.swift */, F91321A521DE24D60076B714 /* CalendarView.swift */, - F987481C22B7E24800E9F4C5 /* CalendarModel.swift */, ); name = KVKCalendar; path = ../..; @@ -450,8 +444,6 @@ F913217E21DE18740076B714 /* YearData.swift in Sources */, F913217C21DE185E0076B714 /* YearViewCalendar.swift in Sources */, F91321A421DE1A670076B714 /* AllDayEventView.swift in Sources */, - F987481B22B509F200E9F4C5 /* View+Extension.swift in Sources */, - F987481D22B7E24800E9F4C5 /* CalendarModel.swift in Sources */, F913219821DE19E00076B714 /* EventPageView.swift in Sources */, F913219A21DE19F80076B714 /* DayViewCalendar.swift in Sources */, F913218021DE18980076B714 /* YearCollectionViewCell.swift in Sources */, diff --git a/KVKCalendar/Classes/CalendarView.swift b/KVKCalendar/Classes/CalendarView.swift index dcc5e49f..c458a8a9 100644 --- a/KVKCalendar/Classes/CalendarView.swift +++ b/KVKCalendar/Classes/CalendarView.swift @@ -177,3 +177,111 @@ extension CalendarView: CalendarFrameProtocol { yearCalendar.reloadFrame(frame: frame) } } + +public enum TimeHourSystem: Int { + case twelveHour = 12 + case twentyFourHour = 24 + + var hours: [String] { + switch self { + case .twelveHour: + var array = [String]() + + for idx in 0...11 { + if idx == 0 { + array.append("12") + } else { + let string = String(idx) + array.append(string) + } + } + var am = array.map { $0 + " AM" } + var pm = array.map { $0 + " PM" } + + am.append("Noon") + pm.removeFirst() + pm.append(am.first!) + + return am + pm + case .twentyFourHour: + var array = [String]() + + for i in 0...24 { + if i == 0 { + array.append("00:00") + } else { + let i = i % 24 + var string = i < 10 ? "0" + "\(i)" : "\(i)" + string.append(":00") + array.append(string) + } + } + + return array + } + } +} + +public enum CalendarType: String, CaseIterable { + case day, week, month, year +} + +public struct Event { + public var id: Any = 0 + public var text: String = "" + public var start: Date = Date() + public var end: Date = Date() + public var color: UIColor? = nil { + didSet { + guard let color = color else { return } + backgroundColor = color.withAlphaComponent(0.3) + var hue: CGFloat = 0, saturation: CGFloat = 0, brightness: CGFloat = 0, alpha: CGFloat = 0 + color.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) + colorText = UIColor(hue: hue, saturation: saturation, brightness: brightness * 0.4, alpha: alpha) + } + } + public var backgroundColor: UIColor = UIColor.blue.withAlphaComponent(0.3) + public var colorText: UIColor = .black + public var isAllDay: Bool = false + public var isContainsFile: Bool = false + public var textForMonth: String = "" + public var eventData: Any? + + public init() {} +} + +protocol CalendarFrameProtocol { + func reloadFrame(frame: CGRect) +} + +protocol CalendarPrivateDelegate: AnyObject { + func didSelectCalendarDate(_ date: Date?, type: CalendarType) + func didSelectCalendarEvents(_ events: [Event]) + func didSelectCalendarEvent(_ event: Event, frame: CGRect?) + func didSelectCalendarMore(_ date: Date, frame: CGRect?) + func getEventViewerFrame(frame: CGRect) +} + +extension CalendarPrivateDelegate { + func getEventViewerFrame(frame: CGRect) {} +} + +public protocol CalendarDataSource: AnyObject { + func eventsForCalendar() -> [Event] +} + +public protocol CalendarDelegate: AnyObject { + func didSelectDate(date: Date?, type: CalendarType) + func didSelectEvents(_ events: [Event]) + func didSelectEvent(_ event: Event, type: CalendarType, frame: CGRect?) + func didSelectMore(_ date: Date, frame: CGRect?) + func eventViewerFrame(_ frame: CGRect) +} + +public extension CalendarDelegate { + func didSelectDate(date: Date?, type: CalendarType) {} + func didSelectEvents(_ events: [Event]) {} + func didSelectEvent(_ event: Event, type: CalendarType, frame: CGRect?) {} + func didSelectMore(_ date: Date, frame: CGRect?) {} + func eventViewerFrame(_ frame: CGRect) {} +} diff --git a/KVKCalendar/Classes/ScrollDayHeaderView.swift b/KVKCalendar/Classes/ScrollDayHeaderView.swift index 8e1d8752..03b3071c 100644 --- a/KVKCalendar/Classes/ScrollDayHeaderView.swift +++ b/KVKCalendar/Classes/ScrollDayHeaderView.swift @@ -64,7 +64,7 @@ final class ScrollDayHeaderView: UIView { func scrollHeaderTitleByTransform(_ transform: CGAffineTransform) { guard !transform.isIdentity else { - UIView.identityViews([titleLabel]) + identityViews([titleLabel]) return } titleLabel.transform = transform @@ -150,6 +150,15 @@ final class ScrollDayHeaderView: UIView { } } + private func identityViews(duration: TimeInterval = 0.4, delay: TimeInterval = 0.07, _ views: [UIView], action: @escaping (() -> Void) = {}) { + UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: .curveLinear, animations: { + views.forEach { (view) in + view.transform = .identity + } + action() + }, completion: nil) + } + required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/KVKCalendar/Classes/TimelineView.swift b/KVKCalendar/Classes/TimelineView.swift index 7fc156f4..98f39df8 100644 --- a/KVKCalendar/Classes/TimelineView.swift +++ b/KVKCalendar/Classes/TimelineView.swift @@ -102,11 +102,11 @@ final class TimelineView: UIView { gesture.state = .ended case .failed: delegate?.swipeX(transform: .identity) - UIView.identityViews(eventViews) + identityViews(eventViews) case .cancelled, .ended: guard endGesure else { delegate?.swipeX(transform: .identity) - UIView.identityViews(eventViews) + identityViews(eventViews) break } @@ -349,6 +349,15 @@ final class TimelineView: UIView { return pointY } + private func identityViews(duration: TimeInterval = 0.4, delay: TimeInterval = 0.07, _ views: [UIView], action: @escaping (() -> Void) = {}) { + UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: .curveLinear, animations: { + views.forEach { (view) in + view.transform = .identity + } + action() + }, completion: nil) + } + func scrollToCurrentTime(startHour: Int) { guard let time = getTimelineLabel(hour: Date().hour), style.timelineStyle.scrollToCurrentHour else { scrollView.setContentOffset(.zero, animated: true) diff --git a/View+Extension.swift b/View+Extension.swift deleted file mode 100644 index 3a4c3bfd..00000000 --- a/View+Extension.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// View+Extension.swift -// KVKCalendar -// -// Created by Sergei Kviatkovskii on 15/06/2019. -// - -import UIKit - -extension UIView { - static func identityViews(duration: TimeInterval = 0.4, delay: TimeInterval = 0.07, _ views: [UIView], action: @escaping (() -> Void) = {}) { - UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: .curveLinear, animations: { - views.forEach { (view) in - view.transform = .identity - } - action() - }, completion: nil) - } -} From 0a1b9f93b45d84e677e6ba7bca2a3fb0b98921e0 Mon Sep 17 00:00:00 2001 From: kviatkovskii <> Date: Mon, 17 Jun 2019 19:11:27 +0300 Subject: [PATCH 2/2] created a new version --- .travis.yml | 2 +- KVKCalendar.podspec | 2 +- README.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4507bc08..e7fe6ef2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,5 @@ language: swift # - gem install cocoapods # Since Travis is not always on latest version # - pod install --project-directory=Example script: -- set -o pipefail && xcodebuild test -workspace KVKCalendar.xcworkspace -scheme KVKCalendar -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty +- set -o pipefail && xcodebuild test -workspace Example/KVKCalendar.xcworkspace -scheme KVKCalendar-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty - pod lib lint diff --git a/KVKCalendar.podspec b/KVKCalendar.podspec index fdc51958..efc951b7 100644 --- a/KVKCalendar.podspec +++ b/KVKCalendar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'KVKCalendar' - s.version = '0.1.6' + s.version = '0.1.7' s.summary = 'A most fully customization calendar library for iOS.' s.description = <<-DESC diff --git a/README.md b/README.md index ab51e978..27d34426 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ it, simply add the following line to your Podfile or Cartfile: ```ruby pod 'KVKCalendar' + github 'kvyatkovskys/KVKCalendar' ```