Skip to content

Commit

Permalink
Merge pull request #9 from kvyatkovskys/feature/fix-bugs
Browse files Browse the repository at this point in the history
small fixes
kvyatkovskys authored Jun 17, 2019

Verified

This commit was signed with the committer’s verified signature.
torkelrogstad Torkel Rogstad
2 parents 06c8356 + 0a1b9f9 commit eeaf494
Showing 9 changed files with 132 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
116 changes: 0 additions & 116 deletions CalendarModel.swift

This file was deleted.

8 changes: 0 additions & 8 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion KVKCalendar.podspec
Original file line number Diff line number Diff line change
@@ -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
108 changes: 108 additions & 0 deletions KVKCalendar/Classes/CalendarView.swift
Original file line number Diff line number Diff line change
@@ -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) {}
}
11 changes: 10 additions & 1 deletion KVKCalendar/Classes/ScrollDayHeaderView.swift
Original file line number Diff line number Diff line change
@@ -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")
}
13 changes: 11 additions & 2 deletions KVKCalendar/Classes/TimelineView.swift
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ it, simply add the following line to your Podfile or Cartfile:

```ruby
pod 'KVKCalendar'

github 'kvyatkovskys/KVKCalendar'
```

19 changes: 0 additions & 19 deletions View+Extension.swift

This file was deleted.

0 comments on commit eeaf494

Please sign in to comment.