Skip to content

Commit d5a8fb0

Browse files
Merge pull request #9 from SimformSolutionsPvtLtd/UNT-T20604-optimization
Example Updated
2 parents 28dfe21 + 67d4daf commit d5a8fb0

10 files changed

Lines changed: 110 additions & 67 deletions

File tree

Example/Example.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
650720D32B194D2100AC1FB6 /* PickerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 650720D22B194D2100AC1FB6 /* PickerViewModel.swift */; };
11+
6549D9AC2B2C4B4B0089EBB1 /* ThemeCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6549D9AB2B2C4B4B0089EBB1 /* ThemeCard.swift */; };
12+
6549D9B02B2C4DBA0089EBB1 /* View+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6549D9AF2B2C4DBA0089EBB1 /* View+Extension.swift */; };
1113
65AB6B0B2B283131009EA7EC /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 65AB6B0D2B283131009EA7EC /* Localizable.strings */; };
1214
65AB6B102B2839F9009EA7EC /* ThemeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AB6B0F2B2839F9009EA7EC /* ThemeButton.swift */; };
1315
65AB6B122B283AED009EA7EC /* LocalizedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AB6B112B283AED009EA7EC /* LocalizedString.swift */; };
@@ -38,6 +40,8 @@
3840

3941
/* Begin PBXFileReference section */
4042
650720D22B194D2100AC1FB6 /* PickerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerViewModel.swift; sourceTree = "<group>"; };
43+
6549D9AB2B2C4B4B0089EBB1 /* ThemeCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeCard.swift; sourceTree = "<group>"; };
44+
6549D9AF2B2C4DBA0089EBB1 /* View+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extension.swift"; sourceTree = "<group>"; };
4145
65AB6B0C2B283131009EA7EC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
4246
65AB6B0F2B2839F9009EA7EC /* ThemeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeButton.swift; sourceTree = "<group>"; };
4347
65AB6B112B283AED009EA7EC /* LocalizedString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizedString.swift; sourceTree = "<group>"; };
@@ -83,6 +87,7 @@
8387
children = (
8488
65AB6B0F2B2839F9009EA7EC /* ThemeButton.swift */,
8589
65AB6B112B283AED009EA7EC /* LocalizedString.swift */,
90+
6549D9AB2B2C4B4B0089EBB1 /* ThemeCard.swift */,
8691
);
8792
path = Common;
8893
sourceTree = "<group>";
@@ -91,6 +96,7 @@
9196
isa = PBXGroup;
9297
children = (
9398
65AB6B142B285309009EA7EC /* Color+Extension.swift */,
99+
6549D9AF2B2C4DBA0089EBB1 /* View+Extension.swift */,
94100
);
95101
path = Extension;
96102
sourceTree = "<group>";
@@ -249,6 +255,8 @@
249255
files = (
250256
65AB6B122B283AED009EA7EC /* LocalizedString.swift in Sources */,
251257
65AB6B152B285309009EA7EC /* Color+Extension.swift in Sources */,
258+
6549D9B02B2C4DBA0089EBB1 /* View+Extension.swift in Sources */,
259+
6549D9AC2B2C4B4B0089EBB1 /* ThemeCard.swift in Sources */,
252260
650720D32B194D2100AC1FB6 /* PickerViewModel.swift in Sources */,
253261
65E058502B0E3E850049A7BA /* PickerExampleView.swift in Sources */,
254262
65E0584E2B0E3E850049A7BA /* ExampleApp.swift in Sources */,

Example/Example/Common/LocalizedString.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import Foundation
99

1010
class LocalizedString {
1111

12-
static let multipleDateSelectionPicker = "Multiple Date selection Picker"
13-
static let singleDateSelectionPicker = "Single Date selection Picker"
14-
static let dateRangeSelectionPicker = "Date Range selection Picker"
15-
static let timePicker = "Time Picker"
12+
static let multipleDateSelectionExample = "Multiple date selection Example."
13+
static let singleDateSelectionExample = "Single date selection Example."
14+
static let dateRangeSelectionExample = "Date range selection Example."
15+
static let timePickerExample = "Time Picker Example"
16+
static let selectMultipleDate = "Select Multiple Date"
17+
static let selectSingleDate = "Select Single Date"
18+
static let selectDateRange = "Select Date Range"
19+
static let selectTime = "Select Time"
1620
static let customizedDatePicker = "Customized Date Picker Example"
1721
static let startDate = "Start Date:"
1822
static let endDate = "End Date:"

Example/Example/Common/ThemeButton.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@ struct ThemeButton: ViewModifier {
1313
content
1414
.frame(maxWidth: .infinity, minHeight: 44)
1515
.font(.system(size: 14, weight: .semibold))
16-
.background(Color.lightBlue)
17-
.foregroundColor(Color.darkPink)
16+
.background(Color.darkPink)
17+
.foregroundColor(Color.white)
1818
.cornerRadius(10)
1919
.padding(.leading, 20)
2020
.padding(.trailing, 20)
2121
}
2222

2323
}
24-
25-
extension View {
26-
func themeButton() -> some View {
27-
self.modifier(ThemeButton())
28-
}
29-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// ThemeCard.swift
3+
// Example
4+
//
5+
// Created by Rizwana Desai on 15/12/23.
6+
//
7+
8+
import SwiftUI
9+
10+
struct ThemeCard: ViewModifier {
11+
12+
func body(content: Content) -> some View {
13+
content
14+
.padding(20)
15+
.background(Color.lightPink)
16+
.clipShape(RoundedRectangle(cornerRadius: 0.0))
17+
.shadow(color: .peach, radius: 2)
18+
.padding(EdgeInsets(top: 10, leading: 20, bottom: 0, trailing: 20))
19+
}
20+
21+
}
22+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// View+Extension.swift
3+
// Example
4+
//
5+
// Created by Rizwana Desai on 15/12/23.
6+
//
7+
8+
import SwiftUI
9+
10+
extension View {
11+
12+
func themeButton() -> some View {
13+
self.modifier(ThemeButton())
14+
}
15+
16+
func themeCard() -> some View {
17+
self.modifier(ThemeCard())
18+
}
19+
20+
}

Example/Example/View/PickerExampleView.swift

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ struct PickerExampleView: View {
1919
@State var selectedDateCombine: Date?
2020
@ObservedObject var pickerViewModel = PickerViewModel()
2121

22-
// //MARK: - Initializer
23-
//
24-
// init() {
25-
//
26-
// }
27-
2822
//MARK: - Body
2923
var body: some View {
3024
ZStack {
@@ -54,64 +48,74 @@ struct PickerExampleView: View {
5448
headerView
5549
ScrollView {
5650
VStack(alignment: .center, spacing: 10) {
57-
singleSelectionView
58-
multipleSelectionView
59-
rangeSelectionView
60-
btnCustomizedPicker
51+
singleDateSelectionView
52+
multipleDateSelectionView
53+
dateRangeSelectionView
6154
timePickerView
6255
}
6356
}
6457
}
6558
}
6659

67-
var singleSelectionView: some View {
68-
VStack {
60+
var singleDateSelectionView: some View {
61+
VStack(spacing: 10) {
62+
Text("\(LocalizedString.singleDateSelectionExample)")
63+
.font(.callout)
64+
Text("\(LocalizedString.selectedDate) \(pickerViewModel.selectedDate?.monthDateYear ?? "-")")
65+
.font(.footnote)
6966
btnSelectSingleDate
70-
Text("\(LocalizedString.selectedDate) \(pickerViewModel.selectedDate?.monthDateYear ?? "")")
7167
}
68+
.themeCard()
7269
}
7370

74-
var multipleSelectionView: some View {
75-
VStack {
71+
var multipleDateSelectionView: some View {
72+
VStack(spacing: 10) {
73+
Text("\(LocalizedString.multipleDateSelectionExample)")
74+
.font(.callout)
75+
Text("\(LocalizedString.selectedDates) \(pickerViewModel.getSelectedDates() ?? "-")")
76+
.font(.footnote)
7677
btnSelectMultipleDates
77-
if let dates = pickerViewModel.selectedDates {
78-
ForEach(0..<dates.count, id: \.self) { index in
79-
Text(dates[index].monthDateYear)
80-
}
81-
}
8278
}
79+
.themeCard()
8380
}
8481

85-
var rangeSelectionView: some View {
86-
VStack {
82+
var dateRangeSelectionView: some View {
83+
VStack(spacing: 10) {
84+
Text("\(LocalizedString.dateRangeSelectionExample)")
85+
.font(.callout)
86+
Text("\(LocalizedString.startDate) \(pickerViewModel.startDate?.monthDateYear ?? "-"), \(LocalizedString.endDate) \(pickerViewModel.endDate?.monthDateYear ?? "-")")
87+
.font(.footnote)
8788
btnSelectDateRange
88-
Text("\(LocalizedString.startDate) \(pickerViewModel.startDate?.monthDateYear ?? "")")
89-
Text("\(LocalizedString.endDate) \(pickerViewModel.endDate?.monthDateYear ?? "")")
9089
}
90+
.themeCard()
9191
}
9292

9393
var btnSelectDateRange: some View {
9494
Button {
9595
pickerViewModel.configureForDateRangeSelection()
9696
showCalender.toggle()
9797
} label: {
98-
Text(LocalizedString.dateRangeSelectionPicker)
98+
Text(LocalizedString.selectDateRange)
9999
.themeButton()
100100
}
101101
}
102102

103103
var timePickerView: some View {
104-
VStack {
104+
VStack(spacing: 10) {
105+
Text("\(LocalizedString.timePickerExample)")
106+
.font(.callout)
107+
Text("\(LocalizedString.selectedTime) \(pickerViewModel.selectedTime?.timeOnlyWithPadding ?? "-")")
108+
.font(.footnote)
105109
btnTimePicker
106-
Text("\(LocalizedString.selectedTime) \(pickerViewModel.selectedTime?.timeOnlyWithPadding ?? "")")
107110
}
111+
.themeCard()
108112
}
109113

110114
var btnTimePicker: some View {
111115
Button {
112116
showTimePicker.toggle()
113117
} label: {
114-
Text(LocalizedString.timePicker)
118+
Text(LocalizedString.selectTime)
115119
.themeButton()
116120
}
117121

@@ -122,7 +126,7 @@ struct PickerExampleView: View {
122126
pickerViewModel.configureForSingleDateSelection()
123127
showCalender.toggle()
124128
} label: {
125-
Text(LocalizedString.singleDateSelectionPicker)
129+
Text(LocalizedString.selectSingleDate)
126130
.themeButton()
127131
}
128132
}
@@ -142,13 +146,12 @@ struct PickerExampleView: View {
142146
pickerViewModel.configureForMultipleDateSelection()
143147
showCalender.toggle()
144148
} label: {
145-
Text(LocalizedString.multipleDateSelectionPicker)
149+
Text(LocalizedString.selectMultipleDate)
146150
.themeButton()
147151

148152
}
149153
}
150154

151-
152155
}
153156

154157
struct ContentView_Previews: PreviewProvider {

Example/Example/ViewModel/PickerViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final class PickerViewModel: ObservableObject {
4141
datePickerManager = SSDatePickerManager(currentMonth: self.selectedDates?.first ?? Date())
4242
datePickerManager.delegate = self
4343
datePickerManager.datasource = self
44+
datePickerManager.selectedDates = self.selectedDates
4445
var configuration = SSDatePickerConfiguration()
4546
configuration.allowMultipleSelection = true
4647
datePickerManager.configuration = configuration
@@ -83,6 +84,13 @@ final class PickerViewModel: ObservableObject {
8384
datePickerManager.configuration = configuration
8485
}
8586

87+
func getSelectedDates() -> String? {
88+
let dates = self.selectedDates?.compactMap({ date in
89+
date.monthDateYear
90+
}).joined(separator: ",")
91+
return dates
92+
}
93+
8694
}
8795

8896
// MARK: - SSTimePickerDelegate

README.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
11
# SSDateTimePicker
2-
3-
SSDateTimePicker for easy date and time selection with multiple features and a customizable UI for both date and time pickers.
4-
5-
Date Picker Features
6-
* Single Date Selection
7-
* Supports Multiple Date Selection
8-
* Supports Date Range Selection
9-
* Disable Past dates or future dates
10-
* Disable Specific Dates
11-
* Allow selecting from a specific date range only (set minimumDate and maximumDate)
12-
* Customize picker fonts and color according to your preference
13-
14-
Time Picker Features
15-
* Clock Style User Interface
16-
* Supports 12H formatting (AM/PM)
17-
* Easy time editing on double-click instead of picking from picker
18-
* Customize picker fonts and color according to your preference
19-
<img src="https://github.com/SimformSolutionsPvtLtd/SSDateTimePicker/assets/151725480/9d5ba4d7-3d28-4e99-9ec2-de1cacc304ba" width="100" height="200">
20-
<img src="https://github.com/SimformSolutionsPvtLtd/SSDateTimePicker/assets/151725480/0cfdb102-2052-4a64-9cac-2d7865e5f0cd" width="100" height="200">
21-
<img src="https://github.com/SimformSolutionsPvtLtd/SSDateTimePicker/assets/151725480/371edc0b-0afe-4b3a-ab6e-2c4c11f60813" width="100" height="200">
22-
<img src="https://github.com/SimformSolutionsPvtLtd/SSDateTimePicker/assets/151725480/452cdf74-3faf-480a-9772-b4538ef73ad7" width="100" height="200">

SSDateTimePicker/SSDateTimePicker/Extensions/Color+Extension.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ extension Color {
2020
public static let lightPink: Color = Color("lightPink")
2121
public static let lightBlue: Color = Color("lightBlue")
2222
public static let peach: Color = Color("peach")
23+
2324
}
2425

SSDateTimePicker/SSDateTimePicker/Views/Time Picker/SSTimePicker.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public struct SSTimePicker: View, TimePickerConfigurationDirectAccess {
5959
SSClockPicker(timePickerManager: timePickerManager)
6060
bottomButtons
6161
}
62+
.padding(SSPickerConstants.pickerViewInnerPadding)
6263
}
6364

6465
var timePickerHeader: some View {
@@ -103,7 +104,6 @@ public struct SSTimePicker: View, TimePickerConfigurationDirectAccess {
103104
actionDone()
104105
}
105106
}
106-
107107
}
108108
}
109109
}
@@ -145,7 +145,9 @@ public struct SSTimePicker: View, TimePickerConfigurationDirectAccess {
145145

146146
var btnCancel: some View {
147147
Button {
148-
self.actionCancel()
148+
withAnimation {
149+
self.actionCancel()
150+
}
149151
} label: {
150152
Text(LocalizedString.cancel)
151153
.themeButton(buttonsForegroundColor, buttonFont)
@@ -154,7 +156,9 @@ public struct SSTimePicker: View, TimePickerConfigurationDirectAccess {
154156

155157
var btnOk: some View {
156158
Button {
157-
self.actionOk()
159+
withAnimation {
160+
self.actionOk()
161+
}
158162
} label: {
159163
Text(LocalizedString.ok)
160164
.themeButton(buttonsForegroundColor, buttonFont)

0 commit comments

Comments
 (0)