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

Scroll events for delegate and custom appearance for today and past dates. #65

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion VACalendar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'VACalendar'
s.version = '1.4'
s.version = '1.6'
s.summary = 'Custom Calendar for iOS in Swift'
s.swift_version = '5.0'

Expand Down
15 changes: 11 additions & 4 deletions VACalendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@
60086D54204C707A002097E7 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0920;
LastUpgradeCheck = 1200;
TargetAttributes = {
60086D5C204C707A002097E7 = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 0920;
LastSwiftMigration = 1200;
ProvisioningStyle = Automatic;
};
};
Expand All @@ -144,6 +144,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 60086D53204C707A002097E7;
productRefGroup = 60086D5E204C707A002097E7 /* Products */;
Expand Down Expand Up @@ -203,15 +204,18 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -263,15 +267,18 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -319,7 +326,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -340,7 +347,7 @@
PRODUCT_BUNDLE_IDENTIFIER = vodolazkyi.VACalendar;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>VACalendar.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
18 changes: 17 additions & 1 deletion VACalendar/VACalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public protocol VACalendarViewDelegate: class {
@objc optional func selectedDate(_ date: Date)
// use this method for multi selection style
@objc optional func selectedDates(_ dates: [Date])
// use this method to detect scroll to top
@objc optional func calendarViewDidScrollToTop(_ scrollView: UIScrollView)
// use this method to detect scroll to bottom
@objc optional func calendarViewDidScrollToBottom(_ scrollView: UIScrollView)
// use this method to detect when the scrolling action ended
@objc optional func calendarViewDidEndDecelerating()
}

public class VACalendarView: UIScrollView {
Expand Down Expand Up @@ -196,7 +202,7 @@ public class VACalendarView: UIScrollView {
}
}

private func scrollToStartDate() {
public func scrollToStartDate(startDate: Date = Date()) {
let startMonth = monthViews.first(where: { $0.month.dateInThisMonth(startDate) })
var offset: CGPoint = startMonth?.frame.origin ?? .zero

Expand Down Expand Up @@ -266,6 +272,16 @@ extension VACalendarView: UIScrollViewDelegate {
monthDelegate?.monthDidChange(monthView.month.date)
drawVisibleMonth(with: scrollView.contentOffset)
}

public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y == 0) {
calendarDelegate?.calendarViewDidScrollToTop?(scrollView)
} else if scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height) {
calendarDelegate?.calendarViewDidScrollToBottom?(scrollView)
} else {
calendarDelegate?.calendarViewDidEndDecelerating?()
}
}

}

Expand Down
6 changes: 5 additions & 1 deletion VACalendar/VADay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

@objc
public enum VADayState: Int {
case out, selected, available, unavailable
case out, selected, available, unavailable, today, past
}

@objc
Expand All @@ -29,6 +29,10 @@ public enum VADaySupplementary: Hashable {
return 1
}
}

public func hash(into hasher: inout Hasher) {
hasher.combine(1)
}

public static func ==(lhs: VADaySupplementary, rhs: VADaySupplementary) -> Bool {
return lhs.hashValue == rhs.hashValue
Expand Down
24 changes: 18 additions & 6 deletions VACalendar/VADayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ protocol VADayViewDelegate: class {
}

class VADayView: UIView {

var day: VADay

var isToday: Bool = false
var day: VADay {
didSet { isToday = Calendar.current.isDateInToday(day.date) }
}
weak var delegate: VADayViewDelegate?

weak var dayViewAppearanceDelegate: VADayViewAppearanceDelegate? {
Expand Down Expand Up @@ -99,14 +102,23 @@ class VADayView: UIView {
dateLabel.clipsToBounds = true
dateLabel.layer.cornerRadius = dateLabel.frame.height / 2
}


if Calendar.current.isDateInToday(day.date) && state == .available {
dateLabel.textColor = dayViewAppearanceDelegate?.textColor?(for: .today)
dateLabel.font = dayViewAppearanceDelegate?.font?(for: .today)
} else if Date().compare(day.date) == .orderedDescending && state == .available && state != .selected {
dateLabel.textColor = dayViewAppearanceDelegate?.textColor?(for: .past)
dateLabel.font = dayViewAppearanceDelegate?.font?(for: .past)
} else {
dateLabel.textColor = dayViewAppearanceDelegate?.textColor?(for: state) ?? dateLabel.textColor
}

backgroundColor = dayViewAppearanceDelegate?.backgroundColor?(for: state) ?? backgroundColor
layer.borderColor = dayViewAppearanceDelegate?.borderColor?(for: state).cgColor ?? layer.borderColor
layer.borderWidth = dayViewAppearanceDelegate?.borderWidth?(for: state) ?? dateLabel.layer.borderWidth

dateLabel.textColor = dayViewAppearanceDelegate?.textColor?(for: state) ?? dateLabel.textColor

dateLabel.backgroundColor = dayViewAppearanceDelegate?.textBackgroundColor?(for: state) ?? dateLabel.backgroundColor

updateSupplementaryViews()
}

Expand Down