Skip to content

Commit

Permalink
updates delegate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yshrkt committed Oct 9, 2017
1 parent ce7a6e5 commit bc0efd3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
16 changes: 9 additions & 7 deletions Sources/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ open class CalendarView: UIView {
dateIndexs.removeAll()
let dates = caleandarDatesAt(year: year, month: month)
//print("\(dates)")
delegate?.calendarView(self, willUpdateCellsFor: dates)
dates.enumerated().forEach{
dateIndexs[$0.element] = $0.offset
let cell = cells[$0.offset]
Expand All @@ -167,15 +168,16 @@ open class CalendarView: UIView {
cell.isSelected = false
cell.isHighlighted = false
cell.isEnabled = true
let _ = delegate?.calendarView(self, willUpdateCellAtDate: $0.element)
let _ = delegate?.calendarView(self, willUpdateCellAt: $0.element)
cell.update(with: $0.element)
if $0.element.year == year && $0.element.month == month {
cell.setEnabled(true, animated: false)
}else {
cell.setEnabled(false, animated: false)
}
delegate?.calendarView(self, didUpdateCellAtDate: $0.element)
delegate?.calendarView(self, didUpdateCellAt: $0.element)
}
delegate?.calendarView(self, didUpdateCellsFor: dates)
}

public func select(at date: CalendarDate, animated: Bool) {
Expand All @@ -185,23 +187,23 @@ open class CalendarView: UIView {
guard let cell = cellForDate(date), !cell.isSelected else {
return
}
if let delegate = delegate, delegate.calendarView(self, willSelectCellAtDate: date) == nil {
if let delegate = delegate, delegate.calendarView(self, willSelectCellAt: date) == nil {
return
}

cell.setSelected(true, animated: animated)
delegate?.calendarView(self, didSelectCellAtDate: date)
delegate?.calendarView(self, didSelectCellAt: date)
}

public func deselect(at date: CalendarDate, animated: Bool) {
guard let cell = cellForDate(date), cell.isSelected else {
return
}
if let delegate = delegate, delegate.calendarView(self, willDeselectCellAtDate: date) == nil {
if let delegate = delegate, delegate.calendarView(self, willDeselectCellAt: date) == nil {
return
}
cell.setSelected(false, animated: animated)
delegate?.calendarView(self, didDeselectCellAtDate: date)
delegate?.calendarView(self, didDeselectCellAt: date)
}

func didTap(sender: UITapGestureRecognizer) {
Expand Down Expand Up @@ -433,7 +435,7 @@ fileprivate extension CalendarView {
right: 0.0)
if let weekday = Weekday(rawValue: i + 1) {
cell.configure(with: weekday)
delegate?.calendarView(self, configureHeaderCellAtWeekday: weekday)
delegate?.calendarView(self, configureHeaderCellAt: weekday)
}

headerView.addSubview(cell)
Expand Down
14 changes: 0 additions & 14 deletions Sources/CalendarViewDataSource.swift

This file was deleted.

39 changes: 25 additions & 14 deletions Sources/CalendarViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,54 @@
import UIKit

public protocol CalendarViewDelegate: class {
func calendarView(_ calendarView: CalendarView, willUpdateCellAtDate date: CalendarDate) -> CalendarDate?
func calendarView(_ calendarView: CalendarView, didUpdateCellAtDate date: CalendarDate)
func calendarView(_ calendarView: CalendarView, willUpdateCellsFor dates: [CalendarDate])
func calendarView(_ calendarView: CalendarView, didUpdateCellsFor dates: [CalendarDate])

func calendarView(_ calendarView: CalendarView, willSelectCellAtDate date: CalendarDate) -> CalendarDate?
func calendarView(_ calendarView: CalendarView, didSelectCellAtDate date: CalendarDate)
func calendarView(_ calendarView: CalendarView, willUpdateCellAt date: CalendarDate) -> CalendarDate?
func calendarView(_ calendarView: CalendarView, didUpdateCellAt date: CalendarDate)

func calendarView(_ calendarView: CalendarView, willDeselectCellAtDate date: CalendarDate) -> CalendarDate?
func calendarView(_ calendarView: CalendarView, didDeselectCellAtDate date: CalendarDate)
func calendarView(_ calendarView: CalendarView, willSelectCellAt date: CalendarDate) -> CalendarDate?
func calendarView(_ calendarView: CalendarView, didSelectCellAt date: CalendarDate)

func calendarView(_ calendarView: CalendarView, configureHeaderCellAtWeekday weekday: Weekday)
func calendarView(_ calendarView: CalendarView, willDeselectCellAt date: CalendarDate) -> CalendarDate?
func calendarView(_ calendarView: CalendarView, didDeselectCellAt date: CalendarDate)

func calendarView(_ calendarView: CalendarView, configureHeaderCellAt weekday: Weekday)

func heightForHeaderView(in calendarView: CalendarView) -> CGFloat
}

public extension CalendarViewDelegate {
func calendarView(_ calendarView: CalendarView, willUpdateCellAtDate date: CalendarDate) -> CalendarDate? {
func calendarView(_ calendarView: CalendarView, willUpdateCellsFor dates: [CalendarDate]) {

}

func calendarView(_ calendarView: CalendarView, didUpdateCellsFor dates: [CalendarDate]) {

}

func calendarView(_ calendarView: CalendarView, willUpdateCellAt date: CalendarDate) -> CalendarDate? {
return date
}
func calendarView(_ calendarView: CalendarView, didUpdateCellAtDate date: CalendarDate) {
func calendarView(_ calendarView: CalendarView, didUpdateCellAt date: CalendarDate) {

}

func calendarView(_ calendarView: CalendarView, willSelectCellAtDate date: CalendarDate) -> CalendarDate? {
func calendarView(_ calendarView: CalendarView, willSelectCellAt date: CalendarDate) -> CalendarDate? {
return date
}
func calendarView(_ calendarView: CalendarView, didSelectCellAtDate date: CalendarDate) {
func calendarView(_ calendarView: CalendarView, didSelectCellAt date: CalendarDate) {

}

func calendarView(_ calendarView: CalendarView, willDeselectCellAtDate date: CalendarDate) -> CalendarDate? {
func calendarView(_ calendarView: CalendarView, willDeselectCellAt date: CalendarDate) -> CalendarDate? {
return date
}
func calendarView(_ calendarView: CalendarView, didDeselectCellAtDate date: CalendarDate) {
func calendarView(_ calendarView: CalendarView, didDeselectCellAt date: CalendarDate) {

}

func calendarView(_ calendarView: CalendarView, configureHeaderCellAtWeekday weekday: Weekday) {
func calendarView(_ calendarView: CalendarView, configureHeaderCellAt weekday: Weekday) {

}

Expand Down
6 changes: 1 addition & 5 deletions TinyCalendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
9230D0871F4F0920000E8A9A /* LineStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9230D0861F4F0920000E8A9A /* LineStyle.swift */; };
9266F81B1F51580F0067E687 /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9266F81A1F51580F0067E687 /* GridView.swift */; };
92A22D451F515372003AD9D5 /* LineAxis.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92A22D441F515372003AD9D5 /* LineAxis.swift */; };
92D5B42C1F516FC500E80368 /* CalendarViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D5B42B1F516FC500E80368 /* CalendarViewDataSource.swift */; };
92D5B42E1F51702C00E80368 /* CalendarViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D5B42D1F51702C00E80368 /* CalendarViewDelegate.swift */; };
92D5B4301F5172DD00E80368 /* CalendarDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D5B42F1F5172DD00E80368 /* CalendarDate.swift */; };
92D5B4321F5172E800E80368 /* Weekday.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D5B4311F5172E800E80368 /* Weekday.swift */; };
Expand All @@ -39,9 +38,8 @@
9230D0841F4EFE51000E8A9A /* Utility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = "<group>"; };
9230D0861F4F0920000E8A9A /* LineStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineStyle.swift; sourceTree = "<group>"; };
9266F81A1F51580F0067E687 /* GridView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GridView.swift; sourceTree = "<group>"; };
92A22D431F5150F0003AD9D5 /* TinyCalendar.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = TinyCalendar.playground; path = Example/TinyCalendar.playground; sourceTree = "<group>"; };
92A22D431F5150F0003AD9D5 /* TinyCalendar.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = TinyCalendar.playground; path = Example/TinyCalendar.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
92A22D441F515372003AD9D5 /* LineAxis.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineAxis.swift; sourceTree = "<group>"; };
92D5B42B1F516FC500E80368 /* CalendarViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarViewDataSource.swift; sourceTree = "<group>"; };
92D5B42D1F51702C00E80368 /* CalendarViewDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarViewDelegate.swift; sourceTree = "<group>"; };
92D5B42F1F5172DD00E80368 /* CalendarDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarDate.swift; sourceTree = "<group>"; };
92D5B4311F5172E800E80368 /* Weekday.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weekday.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -113,7 +111,6 @@
isa = PBXGroup;
children = (
9230D0801F4EF489000E8A9A /* CalendarView.swift */,
92D5B42B1F516FC500E80368 /* CalendarViewDataSource.swift */,
92D5B42D1F51702C00E80368 /* CalendarViewDelegate.swift */,
9230D0821F4EF5C0000E8A9A /* CalendarViewCell.swift */,
92D5B4351F51A4BD00E80368 /* CalendarHeaderView.swift */,
Expand Down Expand Up @@ -208,7 +205,6 @@
9230D0831F4EF5C0000E8A9A /* CalendarViewCell.swift in Sources */,
9266F81B1F51580F0067E687 /* GridView.swift in Sources */,
9230D0811F4EF489000E8A9A /* CalendarView.swift in Sources */,
92D5B42C1F516FC500E80368 /* CalendarViewDataSource.swift in Sources */,
92D5B42E1F51702C00E80368 /* CalendarViewDelegate.swift in Sources */,
92D5B4321F5172E800E80368 /* Weekday.swift in Sources */,
9230D0871F4F0920000E8A9A /* LineStyle.swift in Sources */,
Expand Down

0 comments on commit bc0efd3

Please sign in to comment.