Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia3546 committed Sep 26, 2023
1 parent c2d1df8 commit 854edb4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
11 changes: 3 additions & 8 deletions Sources/Models/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ public struct FastisConfig {
config.todayCell.circleViewUnavailableColor = .cyan
```
*/
public static var `default` = FastisConfig(showCurrentDate: false)
public static var withCurrentDate = FastisConfig(showCurrentDate: true)
public static var `default` = FastisConfig()

private init(showCurrentDate: Bool) {
self.showCurrentDate = showCurrentDate
}
private init() { }

/**
Base calendar used to build a view
Expand All @@ -72,7 +69,7 @@ public struct FastisConfig {
public var dayCell = FastisConfig.DayCell()

/// Today cell (selection parameters, font, etc.)
public var todayCell = FastisConfig.TodayCell()
public var todayCell: FastisConfig.TodayCell?

/// Top header view with week day names
public var weekView = FastisConfig.WeekView()
Expand All @@ -86,6 +83,4 @@ public struct FastisConfig {
/// Shortcut item in the bottom view
public var shortcutItemView = FastisConfig.ShortcutItemView()

/// Flag to show or hide the current date indication
public let showCurrentDate: Bool
}
4 changes: 1 addition & 3 deletions Sources/Views/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ open class FastisController<Value: FastisValue>: UIViewController, JTACMonthView
newConfig.dateLabelText = self.dayFormatter.string(from: date)
}

if self.config.showCurrentDate,
Calendar.current.isDateInToday(date)
{
if Calendar.current.isDateInToday(date) {
newConfig.isToday = true
}

Expand Down
38 changes: 19 additions & 19 deletions Sources/Views/DayCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class DayCell: JTACDayCell {
// MARK: - Variables

private var config: FastisConfig.DayCell = FastisConfig.default.dayCell
private var todayConfig: FastisConfig.TodayCell = FastisConfig.default.todayCell
private var todayConfig: FastisConfig.TodayCell? = FastisConfig.default.todayCell
private var rangeViewTopAnchorConstraints: [NSLayoutConstraint] = []
private var rangeViewBottomAnchorConstraints: [NSLayoutConstraint] = []

Expand Down Expand Up @@ -295,10 +295,10 @@ final class DayCell: JTACDayCell {
self.dateLabel.isHidden = false
self.dateLabel.text = dateLabelText

if config.isToday {
self.configAsTodayCell(viewConfig: config)
if config.isToday, let todayConfig {
self.configureTodayCell(viewConfig: config, todayConfig: todayConfig)
} else {
self.configAsDayCell(viewConfig: config)
self.configureDayCell(viewConfig: config)
}

} else {
Expand Down Expand Up @@ -329,7 +329,7 @@ final class DayCell: JTACDayCell {

}

private func configAsDayCell(viewConfig: ViewConfig) {
private func configureDayCell(viewConfig: ViewConfig) {
if !viewConfig.isDateEnabled {
self.dateLabel.textColor = self.config.dateLabelUnavailableColor
} else if !viewConfig.isSelectedViewHidden {
Expand All @@ -341,31 +341,31 @@ final class DayCell: JTACDayCell {
}
}

private func configAsTodayCell(viewConfig: ViewConfig) {
self.dateLabel.font = self.todayConfig.dateLabelFont
private func configureTodayCell(viewConfig: ViewConfig, todayConfig: FastisConfig.TodayCell) {
self.dateLabel.font = todayConfig.dateLabelFont

if !viewConfig.isDateEnabled {
self.dateLabel.textColor = self.todayConfig.dateLabelUnavailableColor
self.circleView.backgroundColor = self.todayConfig.circleViewUnavailableColor
self.dateLabel.textColor = todayConfig.dateLabelUnavailableColor
self.circleView.backgroundColor = todayConfig.circleViewUnavailableColor
} else if !viewConfig.isSelectedViewHidden {
self.dateLabel.textColor = self.todayConfig.selectedLabelColor
self.circleView.backgroundColor = self.todayConfig.circleViewSelectedColor
self.dateLabel.textColor = todayConfig.selectedLabelColor
self.circleView.backgroundColor = todayConfig.circleViewSelectedColor
} else if !viewConfig.rangeView.isHidden {
self.dateLabel.textColor = self.todayConfig.onRangeLabelColor
self.circleView.backgroundColor = self.todayConfig.onRangeLabelColor
self.dateLabel.textColor = todayConfig.onRangeLabelColor
self.circleView.backgroundColor = todayConfig.onRangeLabelColor
} else {
self.dateLabel.textColor = self.todayConfig.dateLabelColor
self.circleView.backgroundColor = self.todayConfig.circleViewColor
self.dateLabel.textColor = todayConfig.dateLabelColor
self.circleView.backgroundColor = todayConfig.circleViewColor
}

self.circleView.layer.cornerRadius = self.todayConfig.circleSize * 0.5
self.circleView.layer.cornerRadius = todayConfig.circleSize * 0.5
self.circleView.removeFromSuperview()
self.contentView.addSubview(self.circleView)
NSLayoutConstraint.activate([
self.circleView.centerXAnchor.constraint(equalTo: self.dateLabel.centerXAnchor),
self.circleView.topAnchor.constraint(equalTo: self.dateLabel.bottomAnchor, constant: self.todayConfig.circleVerticalInset),
self.circleView.widthAnchor.constraint(equalToConstant: self.todayConfig.circleSize),
self.circleView.heightAnchor.constraint(equalToConstant: self.todayConfig.circleSize)
self.circleView.topAnchor.constraint(equalTo: self.dateLabel.bottomAnchor, constant: todayConfig.circleVerticalInset),
self.circleView.widthAnchor.constraint(equalToConstant: todayConfig.circleSize),
self.circleView.heightAnchor.constraint(equalToConstant: todayConfig.circleSize)
])
}

Expand Down

0 comments on commit 854edb4

Please sign in to comment.