Skip to content

Commit 64b0fc8

Browse files
author
Alberto Aznar
committed
Bug fixed: First month date selection & separation enabled
1 parent 8743ca8 commit 64b0fc8

File tree

9 files changed

+46
-34
lines changed

9 files changed

+46
-34
lines changed

DateScrollPicker.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ s.ios.deployment_target = '10.0'
1313
s.name = 'DateScrollPicker'
1414
s.summary = 'Fully customizable date scroll view with picker feature for iOS written in Swift 5'
1515
s.description = 'DateScrollPicker create a view with a UICollectionView. This collection has infinite cells with dates. You can customize all this cells with your own fonts and colors.'
16-
s.version = '1.0.1'
16+
s.version = '1.0.2'
1717

1818
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
1919

DateScrollPicker/Classes/DateScrollPicker.swift

+16-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ open class DateScrollPicker: UIView {
3636
/// //////////////////////////////////////////////////////////////////////////
3737
/// Object that configure `DateScrollPicker` view. You can setup `DateScrollPicker` with
3838
/// your own parameters. See also `DateScrollPickerFormat` implementation.
39-
open var format = DateScrollPickerFormat()
39+
open var format = DateScrollPickerFormat() {
40+
didSet {
41+
if !format.separatorEnabled {
42+
dateItems = dateItems.filter({ $0.separator == false })
43+
collectionView.reloadData()
44+
}
45+
}
46+
}
4047

4148

4249
override init(frame: CGRect) {
@@ -50,7 +57,7 @@ open class DateScrollPicker: UIView {
5057
}
5158

5259
open override func draw(_ rect: CGRect) {
53-
selectToday(animated: false)
60+
// selectToday(animated: false)
5461
}
5562

5663
private func commonInit() {
@@ -70,16 +77,12 @@ open class DateScrollPicker: UIView {
7077
let monthEndDate = monthStartDate.addMonth(1)!
7178
var currentDate = monthStartDate
7279

73-
if format.separatorEnabled {
74-
dateItems.append(DateScrollItem(date: currentDate, selected: false, separator: true))
75-
}
80+
dateItems.append(DateScrollItem(date: currentDate, selected: false, separator: true))
7681
while currentDate < monthEndDate {
77-
dateItems.append(DateScrollItem(date: currentDate, selected: currentDate == Date.today(), separator: false))
82+
dateItems.append(DateScrollItem(date: currentDate, selected: false, separator: false))
7883
currentDate = currentDate.addDays(1)!
7984
}
80-
if format.separatorEnabled {
81-
dateItems.append(DateScrollItem(date: monthEndDate, selected: false, separator: true))
82-
}
85+
dateItems.append(DateScrollItem(date: monthEndDate, selected: false, separator: true))
8386
}
8487

8588
private func setupCollection() {
@@ -96,7 +99,7 @@ open class DateScrollPicker: UIView {
9699
extension DateScrollPicker: DateScrollPickerInterface {
97100

98101
open func selectToday(animated: Bool? = nil) {
99-
selectDate(Date.today())
102+
selectDate(Date.today(), animated: animated)
100103
}
101104

102105
open func scrollToDate(date: Date, animated: Bool? = nil) {
@@ -110,14 +113,14 @@ extension DateScrollPicker: DateScrollPickerInterface {
110113
extension DateScrollPicker {
111114

112115
private func indexPath(date: Date) -> IndexPath? {
113-
guard let index = dateItems.firstIndex(where: {$0.date == date}) else { return nil }
116+
guard let index = dateItems.firstIndex(where: {$0.date == date && $0.separator == false }) else { return nil }
114117
return IndexPath(item: index, section: 0)
115118
}
116119

117-
private func selectDate(_ date: Date) {
120+
private func selectDate(_ date: Date, animated: Bool? = nil) {
118121
guard let indexPath = indexPath(date: date) else { return }
119122
selectItemAt(indexPath)
120-
scrollToDate(date: dateItems[indexPath.item].date)
123+
scrollToDate(date: dateItems[indexPath.item].date, animated: animated)
121124
}
122125

123126
private func selectItemAt(_ indexPath: IndexPath) {

Example/DateScrollPicker/Info.plist

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<key>UISupportedInterfaceOrientations</key>
4242
<array>
4343
<string>UIInterfaceOrientationPortrait</string>
44-
<string>UIInterfaceOrientationLandscapeLeft</string>
4544
</array>
4645
<key>UIViewControllerBasedStatusBarAppearance</key>
4746
<true/>

Example/DateScrollPicker/ViewController.swift

+14-4
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ class ViewController: UIViewController {
3131
override var preferredStatusBarStyle: UIStatusBarStyle {
3232
return .lightContent
3333
}
34+
35+
override func viewDidAppear(_ animated: Bool) {
36+
super.viewDidAppear(animated)
37+
// goToday()
38+
}
3439
}
3540

3641
// HANDLERS
3742

3843
extension ViewController {
3944

4045
@objc func didPressTodayButton(_ sender: UIButton) {
41-
dateScrollPicker.selectToday()
42-
dateScrollPicker2.selectToday()
43-
dateScrollPicker3.selectToday()
44-
dateScrollPicker4.selectToday()
46+
goToday()
4547
}
4648
}
4749

@@ -157,10 +159,18 @@ extension ViewController {
157159
format.separatorBackgroundColor = UIColor.white.withAlphaComponent(0.3)
158160
format.separatorTopFont = UIFont(name: "Volte-Regular3", size: 22)!
159161
format.separatorTopFont = UIFont(name: "Volte-Regular2", size: 20)!
162+
format.separatorEnabled = false
160163
dateScrollPicker4.format = format
161164
dateScrollPicker4.delegate = self
162165
dateScrollPicker4.dataSource = self
163166
}
167+
168+
private func goToday() {
169+
dateScrollPicker.selectToday()
170+
dateScrollPicker2.selectToday()
171+
dateScrollPicker3.selectToday()
172+
dateScrollPicker4.selectToday()
173+
}
164174
}
165175

166176
// DELEGATES

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- DateScrollPicker (1.0.0)
2+
- DateScrollPicker (1.0.2)
33

44
DEPENDENCIES:
55
- DateScrollPicker (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
DateScrollPicker: 27f11ce6213d69c6c64ba83a823f348642b2aa6f
12+
DateScrollPicker: b77f11f147aa12ed0a90b53ff40e77d0935ff302
1313

1414
PODFILE CHECKSUM: c24bf58c0465fe9acaa42046819f831bed4a7f85
1515

Example/Pods/Local Podspecs/DateScrollPicker.podspec.json

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/DateScrollPicker/DateScrollPicker-Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)