Skip to content

Commit 958f020

Browse files
[CM-1263] Rename YCalendarPicker (#10)
* [OTHER] renamed YCalendarPicker to CalendarPicker and respective classes [OTHER] folder structure changed * [UPDATE] readme file update with new name * [OTHER] restructured and some file renamed * [UPDATE] readme comment updated [UPDATE] remove rename note from readme [UPDATE] dropped swift tool to 5.5
1 parent 5a9b64b commit 958f020

31 files changed

+149
-136
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.5
22

33
import PackageDescription
44

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ Documentation is automatically generated from source code comments and rendered
1818
Usage
1919
----------
2020

21-
### `YCalendarPicker` (UIKit)
22-
`YCalendarPicker` is a subclass of `UIControl` with an api similar to `UIDatePicker`.
21+
### `CalendarPicker` (UIKit)
22+
`CalendarPicker` is a subclass of `UIControl` with an api similar to `UIDatePicker`.
2323

24-
### `YCalendarView` (SwiftUI)
25-
`YCalendarView` is a struct that conforms to the SwiftUI `View` protocol.
24+
### `CalendarView` (SwiftUI)
25+
`CalendarView` is a struct that conforms to the SwiftUI `View` protocol.
2626

2727
### Initializers
2828

29-
Both `YCalendarPicker` and `YCalendarView` can be initialized with the same five parameters (`YCalendarPicker` uses `YCalendarView` internally):
29+
Both `CalendarPicker` and `CalendarView` can be initialized with the same five parameters (`CalendarPicker` uses `CalendarView` internally):
3030

3131
```swift
3232
init(
@@ -39,7 +39,7 @@ init(
3939
```
4040
The standard initializer lets you specify the first day of the week, appearance, optional minimum and maximum dates, and the locale, although it provides sensible defaults for all of these.
4141

42-
`YCalendarPicker` has an additional initializer:
42+
`CalendarPicker` has an additional initializer:
4343

4444
```swift
4545
init?(coder: NSCoder)
@@ -50,12 +50,12 @@ A calendar picker created this way begins with the default appearance, but you c
5050

5151
### Customization
5252

53-
`YCalendarPicker` and `YCalendarView` both have an `appearance` property of type `Appearance`.
53+
`CalendarPicker` and `CalendarView` both have an `appearance` property of type `Appearance`.
5454

5555
`Appearance` lets you customize the picker's appearance. You have full control over the colors, typographies, and images used. The default appearance is dark mode compatible and WCAG 2.0 AA compliant for color contrast.
5656

5757
```swift
58-
/// Appearance for YCalendarPicker that contains typography and color properties
58+
/// Appearance for CalendarPicker that contains typography and color properties
5959
public struct Appearance {
6060
/// Appearance for days within current month
6161
public var normalDayAppearance: Day
@@ -124,7 +124,7 @@ public struct Day {
124124

125125
```swift
126126
// Create calendar picker with default values
127-
let calendarPicker = YCalendarPicker()
127+
let calendarPicker = CalendarPicker()
128128

129129
// add calendar picker to any view
130130
view.addSubview(calendarPicker)
@@ -134,8 +134,8 @@ public struct Day {
134134

135135
```swift
136136
// Create a calendar picker with the weekday text color set to green
137-
var calendarPicker = YCalendarPicker(
138-
appearance: YCalendarPicker.Appearance(weekdayStyle: (textColor: .green, typography: .weekday)
137+
var calendarPicker = CalendarPicker(
138+
appearance: CalendarPicker.Appearance(weekdayStyle: (textColor: .green, typography: .weekday)
139139
)
140140

141141
// Change the weekday text color to red
@@ -162,20 +162,20 @@ public struct Day {
162162
calendarPicker.addTarget(self, action: #selector(onDateChange), for: .valueChanged)
163163
```
164164

165-
If you wish to know when the user has switched months (via the previous and next buttons), you can use the picker's `delegate` property and conform to the `YCalendarPickerDelegate` protocol.
165+
If you wish to know when the user has switched months (via the previous and next buttons), you can use the picker's `delegate` property and conform to the `CalendarPickerDelegate` protocol.
166166

167167
```swift
168168
// Create calendar picker
169-
let calendarPicker = YCalendarPicker()
169+
let calendarPicker = CalendarPicker()
170170

171171
// set the delegate to be notified when the month changes
172172
calendarPicker.delegate = self
173173
```
174174

175175
```swift
176176
// This will notify when the user presses the next/previous buttons
177-
extension DemoViewController: YCalendarPickerDelegate {
178-
func calendarPicker(_ calendarPicker: YCalendarPicker, didChangeMonthTo date: Date) {
177+
extension DemoViewController: CalendarPickerDelegate {
178+
func calendarPicker(_ calendarPicker: CalendarPicker, didChangeMonthTo date: Date) {
179179
print("New month: \(date)")
180180
}
181181
}
@@ -192,20 +192,20 @@ Our calendar picker also supports Swift UI!
192192
```
193193

194194
2. **Create a calendar view**
195-
`YCalendarView` conforms to SwiftUI's `View` protocol so we can directly integrate `YCalendarView` with any SwiftUI view.
195+
`CalendarView` conforms to SwiftUI's `View` protocol so we can directly integrate `CalendarView` with any SwiftUI view.
196196
```swift
197197
var body: some View {
198-
YCalendarView()
198+
CalendarView()
199199
}
200200
```
201201

202202
3. **Customize and then update appearance**
203203

204204
```swift
205205
struct CustomCalendar {
206-
@State var calendar: YCalendarView = {
206+
@State var calendar: CalendarView = {
207207
// Create a calendar picker with the weekday text color set to green
208-
var calendar = YCalendarView()
208+
var calendar = CalendarView()
209209
calendar.appearance.weekdayStyle.textColor = .green
210210
return calendar
211211
}()
@@ -228,7 +228,7 @@ Our calendar picker also supports Swift UI!
228228

229229
```swift
230230
struct CustomCalendar {
231-
@State var calendar = YCalendarView()
231+
@State var calendar = CalendarView()
232232
}
233233

234234
extension CustomCalendar: View {
@@ -250,10 +250,10 @@ Our calendar picker also supports Swift UI!
250250
```
251251

252252
5. **Receive change notifications**
253-
To be notified when the user selects a date or changes the month, you can use the `delegate` property and conform to the `YCalendarViewDelegate` protocol.
253+
To be notified when the user selects a date or changes the month, you can use the `delegate` property and conform to the `CalendarViewDelegate` protocol.
254254

255255
```swift
256-
extension DemoView: YCalendarViewDelegate {
256+
extension DemoView: CalendarViewDelegate {
257257
// Date was selected
258258
func calendarViewDidSelectDate(_ date: Date?) {
259259
if let date {

Sources/YCalendarPicker/Enums/YCalendarPicker+Strings.swift renamed to Sources/YCalendarPicker/Enums/CalendarPicker+Strings.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YCalendarPicker+Strings.swift
2+
// CalendarPicker+Strings.swift
33
// YCalendarPicker
44
//
55
// Created by Mark Pospesel on 1/13/23.
@@ -9,7 +9,7 @@
99
import Foundation
1010
import YCoreUI
1111

12-
extension YCalendarPicker {
12+
extension CalendarPicker {
1313
enum Strings: String, Localizable, CaseIterable {
1414
case previousMonthA11yLabel = "Previous_Month_Button_A11y_Label"
1515
case nextMonthA11yLabel = "Next_Month_Button_A11y_Label"

Sources/YCalendarPicker/Model/CalendarMonthItem+DayAppearance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
extension CalendarMonthItem {
12-
func getDayAppearance(from appearance: YCalendarPicker.Appearance) -> YCalendarPicker.Appearance.Day {
12+
func getDayAppearance(from appearance: CalendarPicker.Appearance) -> CalendarPicker.Appearance.Day {
1313
if isBooked {
1414
return appearance.bookedDayAppearance
1515
} else if !isEnabled {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YCalendarPickerDelegate.swift
2+
// CalendarPickerDelegate.swift
33
// YCalendarPicker
44
//
55
// Created by Sahil Saini on 03/02/23.
@@ -8,8 +8,8 @@
88

99
import Foundation
1010
/// Protocol to observe changes in month
11-
public protocol YCalendarPickerDelegate: AnyObject {
11+
public protocol CalendarPickerDelegate: AnyObject {
1212
/// Observe changes in month (Next/Previous).
1313
/// Called after the user changes the month.
14-
func calendarPicker(_ calendarPicker: YCalendarPicker, didChangeMonthTo date: Date)
14+
func calendarPicker(_ calendarPicker: CalendarPicker, didChangeMonthTo date: Date)
1515
}

Sources/YCalendarPicker/Protocols/YCalendarViewDelegate.swift renamed to Sources/YCalendarPicker/Protocols/CalendarViewDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YCalendarViewDelegate.swift
2+
// CalendarViewDelegate.swift
33
// YCalendarPicker
44
//
55
// Created by Sahil Saini on 07/02/23.
@@ -8,7 +8,7 @@
88

99
import Foundation
1010
/// Protocol to observe changes in date(s)
11-
public protocol YCalendarViewDelegate: AnyObject {
11+
public protocol CalendarViewDelegate: AnyObject {
1212
/// Method for change in selected date.
1313
/// Called after the user changes the selection.
1414
/// - Parameter date: new selected date.

Sources/YCalendarPicker/Views/YCalendarView+AppearanceObserver.swift renamed to Sources/YCalendarPicker/SwiftUI/Observers/CalendarView+AppearanceObserver.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YCalendarView+AppearanceObserver.swift
2+
// CalendarView+AppearanceObserver.swift
33
// YCalendarPicker
44
//
55
// Created by Sahil Saini on 29/11/22.
@@ -9,13 +9,13 @@
99
import Foundation
1010

1111
// Observe changes in appearance.
12-
extension YCalendarView {
12+
extension CalendarView {
1313
class AppearanceObserver: ObservableObject {
14-
@Published var appearance: YCalendarPicker.Appearance
14+
@Published var appearance: CalendarPicker.Appearance
1515

1616
/// Initializes an appearance (theme) observer.
1717
/// - Parameter appearance: appearance object
18-
init(appearance: YCalendarPicker.Appearance = .default) {
18+
init(appearance: CalendarPicker.Appearance = .default) {
1919
self.appearance = appearance
2020
}
2121
}

Sources/YCalendarPicker/Views/YCalendarView+DateObserver.swift renamed to Sources/YCalendarPicker/SwiftUI/Observers/CalendarView+DateObserver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YCalendarView+DateObserver.swift
2+
// CalendarView+DateObserver.swift
33
// YCalendarPicker
44
//
55
// Created by Sahil Saini on 06/01/23.
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
// Observe key dates.
12-
extension YCalendarView {
12+
extension CalendarView {
1313
class DateObserver: ObservableObject {
1414
@Published var minimumDate: Date?
1515
@Published var maximumDate: Date?

Sources/YCalendarPicker/Views/YCalendarView.swift renamed to Sources/YCalendarPicker/SwiftUI/Views/CalendarView.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YCalendarView.swift
2+
// CalendarView.swift
33
// YCalendarPicker
44
//
55
// Created by Sahil on 28/10/22.
@@ -9,7 +9,13 @@
99
import SwiftUI
1010

1111
/// Swift UI month calendar picker
12-
public struct YCalendarView {
12+
///
13+
/// Renamed to `CalendarView`.
14+
@available(*, deprecated, renamed: "CalendarView")
15+
public typealias YCalendarView = CalendarView
16+
17+
/// Swift UI month calendar picker
18+
public struct CalendarView {
1319
/// Unique identifier
1420
///
1521
/// This facilitates connection between SwiftUI & UIKit layers
@@ -24,7 +30,7 @@ public struct YCalendarView {
2430
var firstWeekday: Int = Locale.current.calendar.firstWeekday
2531
var locale: Locale = Locale.current
2632
/// Delegate for date/month change
27-
weak public var delegate: YCalendarViewDelegate?
33+
weak public var delegate: CalendarViewDelegate?
2834

2935
/// Selected date (if any)
3036
public var date: Date? {
@@ -37,7 +43,7 @@ public struct YCalendarView {
3743
}
3844

3945
/// Calendar appearance
40-
public var appearance: YCalendarPicker.Appearance {
46+
public var appearance: CalendarPicker.Appearance {
4147
get {
4248
self.appearanceObserver.appearance
4349
}
@@ -88,7 +94,7 @@ public struct YCalendarView {
8894
/// - locale: locale for data formatting e.g Date format. Default is `nil`.
8995
public init(
9096
firstWeekday: Int? = nil,
91-
appearance: YCalendarPicker.Appearance = .default,
97+
appearance: CalendarPicker.Appearance = .default,
9298
minimumDate: Date? = nil,
9399
maximumDate: Date? = nil,
94100
locale: Locale? = nil
@@ -101,7 +107,7 @@ public struct YCalendarView {
101107
}
102108
}
103109

104-
extension YCalendarView: View {
110+
extension CalendarView: View {
105111
/// :nodoc:
106112
public var body: some View {
107113
VStack(spacing: 0) {
@@ -166,7 +172,7 @@ extension YCalendarView: View {
166172
}
167173
}
168174

169-
extension YCalendarView {
175+
extension CalendarView {
170176
func isDateBeforeMinimumDate(_ date: Date?) -> Bool {
171177
guard let date = date,
172178
let minDate = minimumDate else { return false }
@@ -233,9 +239,9 @@ extension YCalendarView {
233239
}
234240
}
235241

236-
struct YCalendarView_Previews: PreviewProvider {
242+
struct CalendarView_Previews: PreviewProvider {
237243
static var previews: some View {
238-
YCalendarView(
244+
CalendarView(
239245
minimumDate: Date().startDateOfMonth().date(byAddingMonth: -1),
240246
maximumDate: Date().startDateOfMonth().date(byAddingMonth: 2)
241247
)

Sources/YCalendarPicker/Views/DayView.swift renamed to Sources/YCalendarPicker/SwiftUI/Views/DayView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct DayView {
1717
/// horizontal and vertical padding around day view circles
1818
static let padding: CGFloat = 2
1919

20-
let appearance: YCalendarPicker.Appearance
20+
let appearance: CalendarPicker.Appearance
2121
let dateItem: CalendarMonthItem
2222
let locale: Locale
2323
@Binding var selectedDate: Date?
@@ -29,7 +29,7 @@ extension DayView: View {
2929
getDayView(appearance: appearance)
3030
}
3131

32-
func getDayView(appearance: YCalendarPicker.Appearance.Day) -> some View {
32+
func getDayView(appearance: CalendarPicker.Appearance.Day) -> some View {
3333
ZStack {
3434
TextStyleLabel(dateItem.day, typography: appearance.typography, configuration: { label in
3535
label.isUserInteractionEnabled = true
@@ -60,11 +60,11 @@ extension DayView: View {
6060
var accessibilityText = dateItem.date.toString(withTemplate: "dEEEEMMMM", locale: locale) ?? ""
6161

6262
if dateItem.isToday {
63-
accessibilityText.append(YCalendarPicker.Strings.todayDayDescriptor.localized)
63+
accessibilityText.append(CalendarPicker.Strings.todayDayDescriptor.localized)
6464
}
6565

6666
if dateItem.isBooked {
67-
accessibilityText.append(YCalendarPicker.Strings.bookedDayDescriptor.localized)
67+
accessibilityText.append(CalendarPicker.Strings.bookedDayDescriptor.localized)
6868
}
6969

7070
return accessibilityText
@@ -82,10 +82,10 @@ extension DayView: View {
8282
guard dateItem.isSelectable,
8383
!dateItem.isSelected else { return "" }
8484

85-
return YCalendarPicker.Strings.dayButtonA11yHint.localized
85+
return CalendarPicker.Strings.dayButtonA11yHint.localized
8686
}
8787

88-
func getDayAppearance() -> YCalendarPicker.Appearance.Day {
88+
func getDayAppearance() -> CalendarPicker.Appearance.Day {
8989
dateItem.getDayAppearance(from: appearance)
9090
}
9191
}

0 commit comments

Comments
 (0)