Skip to content

Commit

Permalink
Swift format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bryankeller committed Sep 19, 2023
1 parent dbcac1a commit e73aca7
Show file tree
Hide file tree
Showing 57 changed files with 520 additions and 506 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Lint Swift
run: swift package format --allow-writing-to-package-directory format --lint
run: swift package --allow-writing-to-package-directory format --lint


1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added the ability to change the aspect ratio of individual day-of-the-week items
- Added support for self-sizing month headers
- Added a new `setContent(_:animated:)` function, enabling developers to perform animated content updates
- Added Swift format integration to enforce consistent code style

### Fixed
- Fixed an issue that could cause the calendar to programmatically scroll to a month or day to which it had previously scrolled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import UIKit
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: Internal

var window: UIWindow?

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?)
-> Bool
{
window = UIWindow(frame: UIScreen.main.bounds)
Expand All @@ -38,4 +36,3 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ final class DayRangeIndicatorView: UIView {
backgroundColor = .clear
}

required init?(coder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: Internal

override func draw(_ rect: CGRect) {
override func draw(_: CGRect) {
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(indicatorColor.cgColor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum DayRangeSelectionHelper {
{
switch state {
case .began:
if day != existingDayRange?.lowerBound && day != existingDayRange?.upperBound {
if day != existingDayRange?.lowerBound, day != existingDayRange?.upperBound {
existingDayRange = day...day
}
initialDayRange = existingDayRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ final class DayRangeSelectionDemoViewController: BaseDemoViewController {

DayRangeSelectionHelper.updateDayRange(
afterTapSelectionOf: day,
existingDayRange: &self.selectedDayRange)
existingDayRange: &selectedDayRange)

self.calendarView.setContent(self.makeContent())
calendarView.setContent(makeContent())
}

calendarView.multiDaySelectionDragHandler = { [weak self, calendar] day, state in
guard let self else { return }

DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &self.selectedDayRange,
initialDayRange: &self.selectedDayRangeAtStartOfDrag,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: state,
calendar: calendar)

self.calendarView.setContent(self.makeContent())
calendarView.setContent(makeContent())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BaseDemoViewController: UIViewController, DemoViewController {
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ final class MonthBackgroundDemoViewController: BaseDemoViewController {
private var selectedDate: Date?

}

Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ final class PartialMonthVisibilityDemoViewController: BaseDemoViewController {
calendarView.daySelectionHandler = { [weak self] day in
guard let self else { return }

self.selectedDate = self.calendar.date(from: day.components)
self.calendarView.setContent(self.makeContent())
selectedDate = calendar.date(from: day.components)
calendarView.setContent(makeContent())
}
}

override func makeContent() -> CalendarViewContent {
let startDate = calendar.date(from: DateComponents(year: 2020, month: 01, day: 16))!
let endDate = calendar.date(from: DateComponents(year: 2020, month: 12, day: 05))!

let selectedDate = self.selectedDate
let selectedDate = selectedDate

return CalendarViewContent(
calendar: calendar,
Expand Down Expand Up @@ -59,4 +59,3 @@ final class PartialMonthVisibilityDemoViewController: BaseDemoViewController {
private var selectedDate: Date?

}

Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ final class SelectedDayTooltipDemoViewController: BaseDemoViewController {
calendarView.daySelectionHandler = { [weak self] day in
guard let self else { return }

self.selectedDate = self.calendar.date(from: day.components)
self.calendarView.setContent(self.makeContent())
selectedDate = calendar.date(from: day.components)
calendarView.setContent(makeContent())
}
}

override func makeContent() -> CalendarViewContent {
let startDate = calendar.date(from: DateComponents(year: 2020, month: 01, day: 01))!
let endDate = calendar.date(from: DateComponents(year: 2021, month: 12, day: 31))!

let selectedDate = self.selectedDate
let selectedDate = selectedDate

let overlaidItemLocations: Set<OverlaidItemLocation>
if let selectedDate = selectedDate {
if let selectedDate {
overlaidItemLocations = [.day(containingDate: selectedDate)]
} else {
overlaidItemLocations = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ final class SingleDaySelectionDemoViewController: BaseDemoViewController {
selectedDate = calendar.date(from: DateComponents(year: 2020, month: 01, day: 19))!
}

required init?(coder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: Internal

override func viewDidLoad() {
Expand All @@ -39,16 +39,16 @@ final class SingleDaySelectionDemoViewController: BaseDemoViewController {
calendarView.daySelectionHandler = { [weak self] day in
guard let self else { return }

self.selectedDate = self.calendar.date(from: day.components)
self.calendarView.setContent(self.makeContent())
selectedDate = calendar.date(from: day.components)
calendarView.setContent(makeContent())
}
}

override func makeContent() -> CalendarViewContent {
let startDate = calendar.date(from: DateComponents(year: 2020, month: 01, day: 01))!
let endDate = calendar.date(from: DateComponents(year: 2021, month: 12, day: 31))!

let selectedDate = self.selectedDate
let selectedDate = selectedDate

return CalendarViewContent(
calendar: calendar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.

import HorizonCalendar
import UIKit
import SwiftUI
import UIKit

final class SwiftUIItemModelsDemoViewController: BaseDemoViewController {

Expand All @@ -29,16 +29,16 @@ final class SwiftUIItemModelsDemoViewController: BaseDemoViewController {
calendarView.daySelectionHandler = { [weak self] day in
guard let self else { return }

self.selectedDate = self.calendar.date(from: day.components)
self.calendarView.setContent(self.makeContent())
selectedDate = calendar.date(from: day.components)
calendarView.setContent(makeContent())
}
}

override func makeContent() -> CalendarViewContent {
let startDate = calendar.date(from: DateComponents(year: 2020, month: 01, day: 01))!
let endDate = calendar.date(from: DateComponents(year: 2021, month: 12, day: 31))!

let selectedDate = self.selectedDate
let selectedDate = selectedDate

return CalendarViewContent(
calendar: calendar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class SwiftUIScreenDemoViewController: UIViewController, DemoViewControlle
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down Expand Up @@ -92,78 +92,78 @@ struct SwiftUIScreenDemo: View {
dataDependency: selectedDayRange,
proxy: calendarViewProxy)

.interMonthSpacing(24)
.verticalDayMargin(8)
.horizontalDayMargin(8)

.monthHeaders { month in
let monthHeaderText = monthDateFormatter.string(from: calendar.date(from: month.components)!)
if case .vertical = monthsLayout {
HStack {
.interMonthSpacing(24)
.verticalDayMargin(8)
.horizontalDayMargin(8)

.monthHeaders { month in
let monthHeaderText = monthDateFormatter.string(from: calendar.date(from: month.components)!)
if case .vertical = monthsLayout {
HStack {
Text(monthHeaderText)
.font(.title2)
Spacer()
}
.padding()
} else {
Text(monthHeaderText)
.font(.title2)
Spacer()
.padding()
}
.padding()
} else {
Text(monthHeaderText)
.font(.title2)
.padding()
}
}

.days { day in
SwiftUIDayView(dayNumber: day.day, isSelected: isDaySelected(day))
}

.dayRangeItemProvider(for: selectedDateRanges) { dayRangeLayoutContext in
let framesOfDaysToHighlight = dayRangeLayoutContext.daysAndFrames.map { $0.frame }
// UIKit view
return DayRangeIndicatorView.calendarItemModel(
invariantViewProperties: .init(),
content: .init(framesOfDaysToHighlight: framesOfDaysToHighlight))
}
.days { day in
SwiftUIDayView(dayNumber: day.day, isSelected: isDaySelected(day))
}

.onDaySelection { day in
DayRangeSelectionHelper.updateDayRange(
afterTapSelectionOf: day,
existingDayRange: &selectedDayRange)
}
.dayRangeItemProvider(for: selectedDateRanges) { dayRangeLayoutContext in
let framesOfDaysToHighlight = dayRangeLayoutContext.daysAndFrames.map { $0.frame }
// UIKit view
return DayRangeIndicatorView.calendarItemModel(
invariantViewProperties: .init(),
content: .init(framesOfDaysToHighlight: framesOfDaysToHighlight))
}

.onMultipleDaySelectionDrag(
began: { day in
DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: .began,
calendar: calendar)
},
changed: { day in
DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: .changed,
calendar: calendar)
},
ended: { day in
.onDaySelection { day in
DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: .ended,
calendar: calendar)
})

.onAppear {
calendarViewProxy.scrollToDay(
containing: calendar.date(from: DateComponents(year: 2023, month: 07, day: 19))!,
scrollPosition: .centered,
animated: false)
}
afterTapSelectionOf: day,
existingDayRange: &selectedDayRange)
}

.onMultipleDaySelectionDrag(
began: { day in
DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: .began,
calendar: calendar)
},
changed: { day in
DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: .changed,
calendar: calendar)
},
ended: { day in
DayRangeSelectionHelper.updateDayRange(
afterDragSelectionOf: day,
existingDayRange: &selectedDayRange,
initialDayRange: &selectedDayRangeAtStartOfDrag,
state: .ended,
calendar: calendar)
})

.onAppear {
calendarViewProxy.scrollToDay(
containing: calendar.date(from: DateComponents(year: 2023, month: 07, day: 19))!,
scrollPosition: .centered,
animated: false)
}

.frame(maxWidth: 375, maxHeight: .infinity)
.frame(maxWidth: 375, maxHeight: .infinity)
}

// MARK: Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ final class DemoPickerViewController: UIViewController {

}

// MARK: - UITableViewDataSource
// MARK: UITableViewDataSource

extension DemoPickerViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
monthsLayoutPicker.selectedSegmentIndex == 0
? verticalDemoDestinations.count
: horizontalDemoDestinations.count
Expand All @@ -130,11 +130,11 @@ extension DemoPickerViewController: UITableViewDataSource {

}

// MARK: - UITableViewDelegate
// MARK: UITableViewDelegate

extension DemoPickerViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
let demoDestination = monthsLayoutPicker.selectedSegmentIndex == 0
? verticalDemoDestinations[indexPath.item]
: horizontalDemoDestinations[indexPath.item]
Expand Down
Loading

0 comments on commit e73aca7

Please sign in to comment.