Skip to content

Commit ad4fb3a

Browse files
Merge pull request #7 from SimformSolutionsPvtLtd/UNT-T20406-time-picker-ui
Hours and Minutes editing enabled on double tap
2 parents 90836cd + e309b75 commit ad4fb3a

27 files changed

Lines changed: 633 additions & 333 deletions

DateTimePicker/DateTimePicker.xcodeproj/project.pbxproj

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
650720F72B1DDF3600AC1FB6 /* SSTimePickerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 650720F62B1DDF3600AC1FB6 /* SSTimePickerManager.swift */; };
3131
650720F92B1DE9FD00AC1FB6 /* SSTimeTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 650720F82B1DE9FD00AC1FB6 /* SSTimeTextField.swift */; };
3232
650720FB2B1DEF8300AC1FB6 /* SSTimePickerConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 650720FA2B1DEF8300AC1FB6 /* SSTimePickerConfiguration.swift */; };
33+
651668582B20842000AD02A1 /* Int+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651668572B20842000AD02A1 /* Int+Extension.swift */; };
3334
654A7F952B1F04DF00EB9B33 /* SSClockPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 654A7F942B1F04DF00EB9B33 /* SSClockPicker.swift */; };
35+
6552AF272B22CCDC00518870 /* SSDatePickerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6552AF262B22CCDC00518870 /* SSDatePickerDelegate.swift */; };
36+
6552AF292B22CCEB00518870 /* SSDatePickerDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6552AF282B22CCEB00518870 /* SSDatePickerDataSource.swift */; };
37+
6552AF2B2B22D67C00518870 /* SSTimePickerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6552AF2A2B22D67C00518870 /* SSTimePickerDelegate.swift */; };
3438
65E058102B0E2B260049A7BA /* DateTimePicker.docc in Sources */ = {isa = PBXBuildFile; fileRef = 65E0580F2B0E2B260049A7BA /* DateTimePicker.docc */; };
3539
65E058162B0E2B260049A7BA /* DateTimePicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0580B2B0E2B260049A7BA /* DateTimePicker.framework */; };
3640
65E0581B2B0E2B260049A7BA /* DateTimePickerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E0581A2B0E2B260049A7BA /* DateTimePickerTests.swift */; };
@@ -71,7 +75,11 @@
7175
650720F62B1DDF3600AC1FB6 /* SSTimePickerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSTimePickerManager.swift; sourceTree = "<group>"; };
7276
650720F82B1DE9FD00AC1FB6 /* SSTimeTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSTimeTextField.swift; sourceTree = "<group>"; };
7377
650720FA2B1DEF8300AC1FB6 /* SSTimePickerConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSTimePickerConfiguration.swift; sourceTree = "<group>"; };
78+
651668572B20842000AD02A1 /* Int+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+Extension.swift"; sourceTree = "<group>"; };
7479
654A7F942B1F04DF00EB9B33 /* SSClockPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSClockPicker.swift; sourceTree = "<group>"; };
80+
6552AF262B22CCDC00518870 /* SSDatePickerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSDatePickerDelegate.swift; sourceTree = "<group>"; };
81+
6552AF282B22CCEB00518870 /* SSDatePickerDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSDatePickerDataSource.swift; sourceTree = "<group>"; };
82+
6552AF2A2B22D67C00518870 /* SSTimePickerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSTimePickerDelegate.swift; sourceTree = "<group>"; };
7583
65E0580B2B0E2B260049A7BA /* DateTimePicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DateTimePicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7684
65E0580E2B0E2B260049A7BA /* DateTimePicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DateTimePicker.h; sourceTree = "<group>"; };
7785
65E0580F2B0E2B260049A7BA /* DateTimePicker.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = DateTimePicker.docc; sourceTree = "<group>"; };
@@ -101,12 +109,9 @@
101109
650720A32B0F645000AC1FB6 /* Views */ = {
102110
isa = PBXGroup;
103111
children = (
104-
650720A12B0F644000AC1FB6 /* WeekDatesView.swift */,
105-
650720A52B0F6BE600AC1FB6 /* DateView.swift */,
106-
650720B22B10880900AC1FB6 /* MonthSelectionView.swift */,
107-
650720B42B10881900AC1FB6 /* YearSelectionView.swift */,
108-
650720C52B13BE4D00AC1FB6 /* SSDatePicker.swift */,
109-
650720F42B1DAFFB00AC1FB6 /* SSTimePicker.swift */,
112+
650720EE2B19FD7A00AC1FB6 /* ThemeButton.swift */,
113+
6516685A2B21F5F500AD02A1 /* Time Picker */,
114+
651668592B21F5ED00AD02A1 /* Date picker */,
110115
);
111116
path = Views;
112117
sourceTree = "<group>";
@@ -119,8 +124,6 @@
119124
6507209D2B0F538400AC1FB6 /* SSPickerConstants.swift */,
120125
650720A92B0F819F00AC1FB6 /* ImageConstant.swift */,
121126
650720CC2B18257600AC1FB6 /* CornerRadiusStyle.swift */,
122-
650720F82B1DE9FD00AC1FB6 /* SSTimeTextField.swift */,
123-
650720EE2B19FD7A00AC1FB6 /* ThemeButton.swift */,
124127
);
125128
path = Common;
126129
sourceTree = "<group>";
@@ -135,25 +138,50 @@
135138
650720BF2B10CBA100AC1FB6 /* Bundle+Extension.swift */,
136139
650720C12B10CBC500AC1FB6 /* Color+Extension.swift */,
137140
650720CA2B181E5400AC1FB6 /* View+Extension.swift */,
141+
651668572B20842000AD02A1 /* Int+Extension.swift */,
138142
);
139143
path = Extensions;
140144
sourceTree = "<group>";
141145
};
146+
651668592B21F5ED00AD02A1 /* Date picker */ = {
147+
isa = PBXGroup;
148+
children = (
149+
650720C52B13BE4D00AC1FB6 /* SSDatePicker.swift */,
150+
650720B42B10881900AC1FB6 /* YearSelectionView.swift */,
151+
650720B22B10880900AC1FB6 /* MonthSelectionView.swift */,
152+
650720A52B0F6BE600AC1FB6 /* DateView.swift */,
153+
650720A12B0F644000AC1FB6 /* WeekDatesView.swift */,
154+
);
155+
path = "Date picker";
156+
sourceTree = "<group>";
157+
};
158+
6516685A2B21F5F500AD02A1 /* Time Picker */ = {
159+
isa = PBXGroup;
160+
children = (
161+
654A7F942B1F04DF00EB9B33 /* SSClockPicker.swift */,
162+
650720F82B1DE9FD00AC1FB6 /* SSTimeTextField.swift */,
163+
650720F42B1DAFFB00AC1FB6 /* SSTimePicker.swift */,
164+
);
165+
path = "Time Picker";
166+
sourceTree = "<group>";
167+
};
142168
654A7F962B1F2CEC00EB9B33 /* Date picker */ = {
143169
isa = PBXGroup;
144170
children = (
145171
650720C72B146E9500AC1FB6 /* SSDatePickerManager.swift */,
146172
6507209B2B0F4D4500AC1FB6 /* SSDatePickerConfiguration.swift */,
173+
6552AF262B22CCDC00518870 /* SSDatePickerDelegate.swift */,
174+
6552AF282B22CCEB00518870 /* SSDatePickerDataSource.swift */,
147175
);
148176
path = "Date picker";
149177
sourceTree = "<group>";
150178
};
151179
654A7F972B1F2CF400EB9B33 /* Time picker */ = {
152180
isa = PBXGroup;
153181
children = (
154-
654A7F942B1F04DF00EB9B33 /* SSClockPicker.swift */,
155182
650720FA2B1DEF8300AC1FB6 /* SSTimePickerConfiguration.swift */,
156183
650720F62B1DDF3600AC1FB6 /* SSTimePickerManager.swift */,
184+
6552AF2A2B22D67C00518870 /* SSTimePickerDelegate.swift */,
157185
);
158186
path = "Time picker";
159187
sourceTree = "<group>";
@@ -312,20 +340,24 @@
312340
650720B82B10CB0300AC1FB6 /* Calendar+Extension.swift in Sources */,
313341
650720CB2B181E5400AC1FB6 /* View+Extension.swift in Sources */,
314342
650720C02B10CBA100AC1FB6 /* Bundle+Extension.swift in Sources */,
343+
6552AF292B22CCEB00518870 /* SSDatePickerDataSource.swift in Sources */,
315344
650720A62B0F6BE600AC1FB6 /* DateView.swift in Sources */,
316345
650720C62B13BE4D00AC1FB6 /* SSDatePicker.swift in Sources */,
317346
650720B32B10880900AC1FB6 /* MonthSelectionView.swift in Sources */,
318347
650720CD2B18257600AC1FB6 /* CornerRadiusStyle.swift in Sources */,
319348
650720AA2B0F819F00AC1FB6 /* ImageConstant.swift in Sources */,
349+
651668582B20842000AD02A1 /* Int+Extension.swift in Sources */,
320350
650720BE2B10CB7300AC1FB6 /* DateFormatter+Extension.swift in Sources */,
321351
650720B52B10881900AC1FB6 /* YearSelectionView.swift in Sources */,
322352
654A7F952B1F04DF00EB9B33 /* SSClockPicker.swift in Sources */,
323353
650720F72B1DDF3600AC1FB6 /* SSTimePickerManager.swift in Sources */,
324354
650720C82B146E9500AC1FB6 /* SSDatePickerManager.swift in Sources */,
325355
650720F92B1DE9FD00AC1FB6 /* SSTimeTextField.swift in Sources */,
326356
6507209E2B0F538400AC1FB6 /* SSPickerConstants.swift in Sources */,
357+
6552AF2B2B22D67C00518870 /* SSTimePickerDelegate.swift in Sources */,
327358
650720FB2B1DEF8300AC1FB6 /* SSTimePickerConfiguration.swift in Sources */,
328359
65E058102B0E2B260049A7BA /* DateTimePicker.docc in Sources */,
360+
6552AF272B22CCDC00518870 /* SSDatePickerDelegate.swift in Sources */,
329361
650720BC2B10CB5000AC1FB6 /* Date+Extension.swift in Sources */,
330362
650720F52B1DAFFB00AC1FB6 /* SSTimePicker.swift in Sources */,
331363
650720EF2B19FD7A00AC1FB6 /* ThemeButton.swift in Sources */,

DateTimePicker/DateTimePicker.xcodeproj/xcuserdata/rizwana.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>DateTimePicker.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>1</integer>
10+
<integer>0</integer>
1111
</dict>
1212
</dict>
1313
</dict>

DateTimePicker/DateTimePicker/Common/Date picker/SSDatePickerConfiguration.swift

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,32 @@
88
import Foundation
99
import SwiftUI
1010

11-
11+
/// A configuration structure for customizing the appearance and behavior of the SSDatePicker.
1212
public struct SSDatePickerConfiguration {
1313

14-
// Colors
14+
// MARK: - Colors
15+
16+
/** Color for the header title -"Select date". */
1517
public var headerTitleColor: Color = Color.gray
18+
/** Color for the header date text. */
1619
public var headerDateColor: Color = Color.black
1720
public var weekdayTextColor: Color = Color.gray
21+
/** list of Date, month, and year's text color in picker. */
1822
public var dateMonthYearTextColor: Color = Color.black
19-
public var selectionForegroundColor: Color = Color.white
23+
/** Selected date font color */
24+
public var selectedDateTextColor: Color = Color.white
2025
public var selectionBackgroundColor: Color
2126
public var todayColor: Color = Color.black
22-
public var todaySelectionColor: Color = Color.clear
27+
public var todaySelectionBgColor: Color?
2328
public var buttonsForegroundColor: Color
2429
public var pickerBackgroundColor: Color
2530
public var nextPrevButtonColor: Color = Color.black
26-
public var monthYearNavigationLabelColor: Color = Color.black
31+
/** Color for the text of navigation labels, such as "June, 2023" or "2023". */
32+
public var navigationLabelColor: Color = Color.black
2733
public var popupOverlayColor: Color = Color.black.opacity(0.5)
2834

29-
// Corner radius
30-
public var pickerViewRadius: CGFloat = 15
31-
32-
// Configuration options for date selection.
35+
// MARK: - Date selection behavior configuration properties
36+
3337
public var allowMultipleSelection: Bool = false
3438
public var allowRangeSelection: Bool = false
3539
public var minimumDate: Date?
@@ -38,21 +42,40 @@ public struct SSDatePickerConfiguration {
3842
public var disablePastDates: Bool = false
3943
public var calendar: Calendar = Calendar.current
4044

41-
// Date format
45+
// MARK: - Font properties
46+
47+
/** Color for the header title -"Select date". */
48+
public var headerTitleFont: Font = .system(size: 12, weight: .bold)
49+
/** Font for the header date text. */
50+
public var headerDateFont: Font = .system(size: 20, weight: .semibold)
51+
public var weekdayTextFont: Font = .caption
52+
public var dateTextFont: Font = .footnote
53+
public var monthTextFont: Font = .system(size: 14, weight: .regular)
54+
public var selectedMonthTextFont: Font = .system(size: 14, weight: .bold)
55+
public var yearTextFont: Font = .system(size: 14, weight: .regular)
56+
public var selectedYearTextFont: Font = .system(size: 14, weight: .bold)
57+
public var buttonsFont: Font = .system(size: 15, weight: .semibold)
58+
public var currentMonthYearBottomLabelFont: Font = .system(size: 14, weight: .medium)
59+
60+
// MARK: - Additional Properties
61+
62+
public var pickerViewRadius: CGFloat = 15
4263
public var headerDateFormat: String = DateFormat.monthDateYear
4364

44-
public init(pickerBackgroundColor: Color, selectionColor: Color) {
45-
self.selectionBackgroundColor = selectionColor
46-
self.buttonsForegroundColor = selectionColor
65+
// MARK: - Initializer
66+
67+
/// Creates a custom-themed date picker.
68+
///
69+
/// - Parameters:
70+
/// - pickerBackgroundColor: The color for the background of the picker view. Default is light pink.
71+
/// - primaryColor: This parameter determines the color for both the selected date's background and the buttons in the date picker.
72+
///
73+
/// Use this instance to set up the appearance and behavior of the SSDatePicker according to your prefrence.
74+
public init(pickerBackgroundColor: Color = Color.lightPink, primaryColor: Color = Color.darkPink) {
75+
self.selectionBackgroundColor = primaryColor
76+
self.buttonsForegroundColor = primaryColor
4777
self.pickerBackgroundColor = pickerBackgroundColor
4878
}
49-
50-
public init() {
51-
self.selectionBackgroundColor = .darkPink
52-
self.buttonsForegroundColor = .darkPink
53-
self.pickerBackgroundColor = .lightPink
54-
}
55-
5679
}
5780

5881
protocol DatePickerConfigurationDirectAccess {
@@ -83,8 +106,8 @@ extension DatePickerConfigurationDirectAccess {
83106
configuration.dateMonthYearTextColor
84107
}
85108

86-
var selectionForegroundColor: Color {
87-
configuration.selectionForegroundColor
109+
var selectedDateTextColor: Color {
110+
configuration.selectedDateTextColor
88111
}
89112

90113
var selectionBackgroundColor: Color {
@@ -95,8 +118,8 @@ extension DatePickerConfigurationDirectAccess {
95118
configuration.todayColor
96119
}
97120

98-
var todaySelectionColor: Color {
99-
configuration.todaySelectionColor
121+
var todaySelectionBgColor: Color? {
122+
configuration.todaySelectionBgColor
100123
}
101124

102125
var buttonsForegroundColor: Color {
@@ -121,7 +144,7 @@ extension DatePickerConfigurationDirectAccess {
121144
}
122145

123146
var monthYearNavigationLabelColor: Color {
124-
configuration.monthYearNavigationLabelColor
147+
configuration.navigationLabelColor
125148
}
126149

127150
var allowMultipleSelection: Bool {
@@ -151,5 +174,45 @@ extension DatePickerConfigurationDirectAccess {
151174
var disableFutureDates: Bool {
152175
configuration.disableFutureDates
153176
}
177+
178+
var headerTitleFont: Font {
179+
configuration.headerTitleFont
180+
}
181+
182+
var headerDateFont: Font {
183+
configuration.headerDateFont
184+
}
185+
186+
var weekdayTextFont: Font {
187+
configuration.weekdayTextFont
188+
}
189+
190+
var dateTextFont: Font {
191+
configuration.dateTextFont
192+
}
193+
194+
var monthTextFont: Font {
195+
configuration.monthTextFont
196+
}
197+
198+
var selectedMonthTextFont: Font {
199+
configuration.selectedMonthTextFont
200+
}
201+
202+
var yearTextFont: Font {
203+
configuration.yearTextFont
204+
}
205+
206+
var buttonsFont: Font {
207+
configuration.buttonsFont
208+
}
209+
210+
var currentMonthYearBottomLabelFont: Font {
211+
configuration.currentMonthYearBottomLabelFont
212+
}
213+
214+
var selectedYearTextFont: Font {
215+
configuration.selectedYearTextFont
216+
}
154217

155218
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// SSDatePickerDataSource.swift
3+
// DateTimePicker
4+
//
5+
// Created by Rizwana Desai on 08/12/23.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
public protocol SSDatePickerDataSource: AnyObject {
12+
13+
func datePicker(canSelectDate date: Date) -> Bool
14+
func datePicker(backgroundColorOpacityForDate date: Date) -> Double
15+
func datePicker(viewForSelectedDate date: Date, dimensions size: CGSize) -> AnyView
16+
17+
}
18+
19+
public extension SSDatePickerDataSource {
20+
21+
func datePicker(canSelectDate date: Date) -> Bool { true }
22+
func datePicker(backgroundColorOpacityForDate date: Date) -> Double { 1 }
23+
func datePicker(viewForSelectedDate date: Date, dimensions size: CGSize) -> AnyView {
24+
AnyView(EmptyView())
25+
}
26+
27+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// SSDatePickerDelegate.swift
3+
// DateTimePicker
4+
//
5+
// Created by Rizwana Desai on 08/12/23.
6+
//
7+
8+
import Foundation
9+
10+
public protocol SSDatePickerDelegate: AnyObject {
11+
12+
/// Notifies the delegate when a single date is selected.
13+
/// - Parameter selectedDate: The selected date.
14+
func datePicker(didSelectDate selectedDate: Date)
15+
16+
/// If the date picker allows multiple date selection, this method notifies the delegate when multiple dates are selected.
17+
/// - Parameter selectedDates: An array of selected dates.
18+
func datePicker(didSelectMultipleDates selectedDates: [Date])
19+
20+
/// If the date picker allows range selection, this method is called when a start date and an end date are selected.
21+
/// - Parameters:
22+
/// - selectedStartDate: The selected start date of the range.
23+
/// - selectedEndDate: The selected end date of the range.
24+
func datePicker(didSelectStartDate selectedStartDate: Date, didSelectEndDate selectedEndDate: Date)
25+
26+
}
27+
28+
public extension SSDatePickerDelegate {
29+
30+
func datePicker(didSelectDate date: Date) { }
31+
func datePicker(didSelectMultipleDates dates: [Date]) { }
32+
func datePicker(didSelectStartDate date: Date, didSelectEndDate: Date) { }
33+
34+
}

0 commit comments

Comments
 (0)