Skip to content

Commit

Permalink
Update access modifiers of the API #242
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtop committed Feb 18, 2020
1 parent fc4939c commit 9dc96ea
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 106 deletions.
4 changes: 4 additions & 0 deletions CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
75776AF58133F6BBDDCF1CE7 /* Pods_CalendarApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */; };
791ACF5023FC887D00B2D602 /* TimeChunk+DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */; };
7924834B23CB7B57003E3D27 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834923CB7B57003E3D27 /* Main.storyboard */; };
7924834D23CB7B58003E3D27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7924834C23CB7B58003E3D27 /* Assets.xcassets */; };
7924835023CB7B58003E3D27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834E23CB7B58003E3D27 /* LaunchScreen.storyboard */; };
Expand All @@ -21,6 +22,7 @@

/* Begin PBXFileReference section */
786F0C3439DCA027A1D04664 /* Pods-CalendarApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CalendarApp.release.xcconfig"; path = "Target Support Files/Pods-CalendarApp/Pods-CalendarApp.release.xcconfig"; sourceTree = "<group>"; };
791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeChunk+DateComponents.swift"; sourceTree = "<group>"; };
7924834023CB7B57003E3D27 /* CalendarApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CalendarApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
7924834A23CB7B57003E3D27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
7924834C23CB7B58003E3D27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -79,6 +81,7 @@
isa = PBXGroup;
children = (
7924836523CB7BFE003E3D27 /* AppDelegate.swift */,
791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */,
7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */,
7924836423CB7BFE003E3D27 /* DatePickerController.swift */,
7924836723CB7BFE003E3D27 /* ExampleController.swift */,
Expand Down Expand Up @@ -220,6 +223,7 @@
7924836E23CB7BFE003E3D27 /* ExampleNotificationController.swift in Sources */,
7924836C23CB7BFE003E3D27 /* CustomCalendarExampleController.swift in Sources */,
7924836923CB7BFE003E3D27 /* StyleGenerator.swift in Sources */,
791ACF5023FC887D00B2D602 /* TimeChunk+DateComponents.swift in Sources */,
7924836D23CB7BFE003E3D27 /* ExampleController.swift in Sources */,
7924836A23CB7BFE003E3D27 /* DatePickerController.swift in Sources */,
);
Expand Down
20 changes: 20 additions & 0 deletions CalendarKitDemo/CalendarApp/TimeChunk+DateComponents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import DateToolsSwift

extension TimeChunk {
static func dateComponents(seconds: Int = 0,
minutes: Int = 0,
hours: Int = 0,
days: Int = 0,
weeks: Int = 0,
months: Int = 0,
years: Int = 0) -> TimeChunk {
return TimeChunk(seconds: seconds,
minutes: minutes,
hours: hours,
days: days,
weeks: weeks,
months: months,
years: years)
}
}
4 changes: 2 additions & 2 deletions Source/Extensions/Date+AddChunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension Date {
* - returns: A date with components increased by the values of the
* corresponding `TimeChunk` variables
*/
public func add(_ chunk: TimeChunk, calendar: Calendar) -> Date {
func add(_ chunk: TimeChunk, calendar: Calendar) -> Date {
var components = DateComponents()
components.year = chunk.years
components.month = chunk.months
Expand All @@ -33,7 +33,7 @@ extension Date {
* - returns: A date with components decreased by the values of the
* corresponding `TimeChunk` variables
*/
public func subtract(_ chunk: TimeChunk, calendar: Calendar) -> Date {
func subtract(_ chunk: TimeChunk, calendar: Calendar) -> Date {
var components = DateComponents()
components.year = -chunk.years
components.month = -chunk.months
Expand Down
14 changes: 7 additions & 7 deletions Source/Extensions/TimeChunk+DateComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import Foundation
import DateToolsSwift

extension TimeChunk {
public static func dateComponents(seconds: Int = 0,
minutes: Int = 0,
hours: Int = 0,
days: Int = 0,
weeks: Int = 0,
months: Int = 0,
years: Int = 0) -> TimeChunk {
static func dateComponents(seconds: Int = 0,
minutes: Int = 0,
hours: Int = 0,
days: Int = 0,
weeks: Int = 0,
months: Int = 0,
years: Int = 0) -> TimeChunk {
return TimeChunk(seconds: seconds,
minutes: minutes,
hours: hours,
Expand Down
33 changes: 16 additions & 17 deletions Source/Header/DayHeaderView.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import UIKit
import DateToolsSwift

public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

public var daysInWeek = 7
public final class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
public private(set) var daysInWeek = 7
public let calendar: Calendar

var style = DayHeaderStyle()
var currentSizeClass = UIUserInterfaceSizeClass.compact
private var style = DayHeaderStyle()
private var currentSizeClass = UIUserInterfaceSizeClass.compact

public weak var state: DayViewState? {
willSet(newValue) {
Expand All @@ -19,17 +18,17 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U
}
}

var currentWeekdayIndex = -1
private var currentWeekdayIndex = -1

var daySymbolsViewHeight: CGFloat = 20
var pagingScrollViewHeight: CGFloat = 40
var swipeLabelViewHeight: CGFloat = 20
private var daySymbolsViewHeight: CGFloat = 20
private var pagingScrollViewHeight: CGFloat = 40
private var swipeLabelViewHeight: CGFloat = 20

let daySymbolsView: DaySymbolsView
var pagingViewController = UIPageViewController(transitionStyle: .scroll,
private let daySymbolsView: DaySymbolsView
private var pagingViewController = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: .horizontal,
options: nil)
let swipeLabelView: SwipeLabelView
private let swipeLabelView: SwipeLabelView

public init(calendar: Calendar) {
self.calendar = calendar
Expand All @@ -45,13 +44,13 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U
fatalError("init(coder:) has not been implemented")
}

func configure() {
private func configure() {
[daySymbolsView, swipeLabelView].forEach(addSubview)
backgroundColor = style.backgroundColor
configurePagingViewController()
}

func configurePagingViewController() {
private func configurePagingViewController() {
let selectedDate = Date()
let vc = makeSelectorController(startDate: beginningOfWeek(selectedDate))
vc.selectedDate = selectedDate
Expand All @@ -62,7 +61,7 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U
addSubview(pagingViewController.view!)
}

func makeSelectorController(startDate: Date) -> DaySelectorController {
private func makeSelectorController(startDate: Date) -> DaySelectorController {
let new = DaySelectorController()
new.calendar = calendar
new.transitionToHorizontalSizeClass(currentSizeClass)
Expand All @@ -72,7 +71,7 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U
return new
}

func beginningOfWeek(_ date: Date) -> Date {
private func beginningOfWeek(_ date: Date) -> Date {
let weekOfYear = component(component: .weekOfYear, from: date)
let yearForWeekOfYear = component(component: .yearForWeekOfYear, from: date)
return calendar.date(from: DateComponents(calendar: calendar,
Expand Down Expand Up @@ -108,7 +107,7 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U

// MARK: DaySelectorDelegate

func dateSelectorDidSelectDate(_ date: Date) {
public func dateSelectorDidSelectDate(_ date: Date) {
state?.move(to: date)
}

Expand Down
22 changes: 11 additions & 11 deletions Source/Header/DaySelector/DateLabel.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import UIKit
import DateToolsSwift

class DateLabel: UILabel, DaySelectorItemProtocol {
var calendar = Calendar.autoupdatingCurrent {
public final class DateLabel: UILabel, DaySelectorItemProtocol {
public var calendar = Calendar.autoupdatingCurrent {
didSet {
updateState()
}
}

var date = Date() {
public var date = Date() {
didSet {
text = String(date.day)
updateState()
Expand All @@ -19,15 +19,15 @@ class DateLabel: UILabel, DaySelectorItemProtocol {
return calendar.isDateInToday(date)
}

var selected: Bool = false {
public var selected: Bool = false {
didSet {
animate()
}
}

var style = DaySelectorStyle()
private var style = DaySelectorStyle()

override var intrinsicContentSize: CGSize {
override public var intrinsicContentSize: CGSize {
return CGSize(width: 35, height: 35)
}

Expand All @@ -41,13 +41,13 @@ class DateLabel: UILabel, DaySelectorItemProtocol {
configure()
}

func configure() {
private func configure() {
isUserInteractionEnabled = true
textAlignment = .center
clipsToBounds = true
}

func updateStyle(_ newStyle: DaySelectorStyle) {
public func updateStyle(_ newStyle: DaySelectorStyle) {
style = newStyle
updateState()
}
Expand Down Expand Up @@ -79,7 +79,7 @@ class DateLabel: UILabel, DaySelectorItemProtocol {
return false
}

func animate(){
private func animate(){
UIView.transition(with: self,
duration: 0.4,
options: .transitionCrossDissolve,
Expand All @@ -88,10 +88,10 @@ class DateLabel: UILabel, DaySelectorItemProtocol {
}, completion: nil)
}

override func layoutSubviews() {
override public func layoutSubviews() {
layer.cornerRadius = bounds.height / 2
}
override func tintColorDidChange() {
override public func tintColorDidChange() {
updateState()
}
}
28 changes: 14 additions & 14 deletions Source/Header/DaySelector/DayDateCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import UIKit
import DateToolsSwift
import Neon

class DayDateCell: UIView, DaySelectorItemProtocol {
public final class DayDateCell: UIView, DaySelectorItemProtocol {

let dateLabel = DateLabel()
let dayLabel = UILabel()
private let dateLabel = DateLabel()
private let dayLabel = UILabel()

var regularSizeClassFontSize: CGFloat = 16
private var regularSizeClassFontSize: CGFloat = 16

var date = Date() {
public var date = Date() {
didSet {
dateLabel.date = date
updateState()
}
}

var calendar = Calendar.autoupdatingCurrent {
public var calendar = Calendar.autoupdatingCurrent {
didSet {
dateLabel.calendar = calendar
updateState()
}
}


var selected: Bool {
public var selected: Bool {
get {
return dateLabel.selected
}
Expand All @@ -35,7 +35,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol {

var style = DaySelectorStyle()

override var intrinsicContentSize: CGSize {
override public var intrinsicContentSize: CGSize {
return CGSize(width: 75, height: 35)
}

Expand All @@ -49,18 +49,18 @@ class DayDateCell: UIView, DaySelectorItemProtocol {
configure()
}

func configure() {
private func configure() {
clipsToBounds = true
[dayLabel, dateLabel].forEach(addSubview(_:))
}

func updateStyle(_ newStyle: DaySelectorStyle) {
public func updateStyle(_ newStyle: DaySelectorStyle) {
style = newStyle
dateLabel.updateStyle(newStyle)
updateState()
}

func updateState() {
private func updateState() {
let isWeekend = isAWeekend(date: date)
dayLabel.font = UIFont.systemFont(ofSize: regularSizeClassFontSize)
dayLabel.textColor = isWeekend ? style.weekendTextColor : style.inactiveTextColor
Expand All @@ -69,7 +69,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol {
setNeedsLayout()
}

func updateDayLabel() {
private func updateDayLabel() {
let daySymbols = calendar.shortWeekdaySymbols
let weekendMask = [true] + [Bool](repeating: false, count: 5) + [true]
var weekDays = Array(zip(daySymbols, weekendMask))
Expand All @@ -90,7 +90,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol {
return false
}

override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
dayLabel.sizeToFit()
dayLabel.center.y = center.y
Expand All @@ -106,7 +106,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol {
label.frame.origin.x += padding
}
}
override func tintColorDidChange() {
override public func tintColorDidChange() {
updateState()
}
}
Loading

0 comments on commit 9dc96ea

Please sign in to comment.