Skip to content

Commit 005b4a9

Browse files
authored
Merge pull request #3 from wojteklembryk/master
Controller configuration extended to disable date range changes
2 parents 0a5815c + bf70011 commit 005b4a9

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Fastis.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = 'Fastis'
3-
s.version = '1.0.9'
3+
s.version = '1.0.10'
44
s.summary = "Simple date picker created using JTAppleCalendar library"
55
s.description = <<-DESC
66
Fastis is a fully customizable UI component for picking dates and ranges created using JTAppleCalendar library.
77
DESC
8-
8+
99
s.homepage = 'https://github.com/retailcrm/Fastis'
1010
s.social_media_url = 'https://retailcrm.pro'
1111
s.screenshot = 'https://github.com/retailcrm/Fastis/raw/master/Documentation/top_screen.jpg'

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Run `carthage update` to build the framework, drag the following framework into
8484

8585
- `Fastis.framework`
8686
- `SnapKit.framewok`
87-
- `PrettyCards.framework`
87+
- `PrettyCards.framework`
8888
- `JTAppleCalendar.framework`
8989

9090
### Swift Package Manager
@@ -164,6 +164,7 @@ var initialValue: Value? = nil
164164
var minimumDate: Date? = nil
165165
var maximumDate: Date? = nil
166166
var selectMonthOnHeaderTap: Bool = true
167+
var allowDateRangeChanges: Bool = true
167168
```
168169

169170
- `shortcuts`- Shortcuts array. Default value is `[]`. See [Shortcuts](#shortcuts) section
@@ -174,6 +175,7 @@ var selectMonthOnHeaderTap: Bool = true
174175
- `minimumDate`- Minimal selection date. Dates less then current will be markes as unavailable. Default value is `nil`.
175176
- `maximumDate`- Maximum selection date. Dates greather then current will be markes as unavailable. Default value is `nil`.
176177
- `selectMonthOnHeaderTap` (Only for `.range` mode) - Set this variable to `true` if you want to allow select date ranges by tapping on months. Default value is `true`.
178+
- `allowDateRangeChanges` (Only for `.range` mode) - Set this variable to `false` if you want to if you want to disable date range changes. Next tap after selecting range will start new range selection. Default value is `true`.
177179

178180
### Shortcuts
179181

@@ -227,4 +229,4 @@ let fastisController = FastisController(mode: .range, config: customConfig)
227229

228230
## License
229231

230-
Fastis is released under the MIT license. See LICENSE for details.
232+
Fastis is released under the MIT license. See LICENSE for details.

Source/Views/Controller.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ public class FastisController<Value: FastisValue>: UIViewController, JTACMonthVi
150150
}
151151
}
152152

153+
/**
154+
Allow date range changes
155+
156+
Set this variable to `false` if you want to disable date range changes.
157+
Next tap after selecting range will start new range selection.
158+
*/
159+
public var allowDateRangeChanges: Bool = true
160+
153161
/**
154162
Maximum selection date. Dates greather then current will be markes as unavailable
155163
*/
@@ -332,7 +340,11 @@ public class FastisController<Value: FastisValue>: UIViewController, JTACMonthVi
332340
var newValue: FastisRange!
333341
if let currentValue = self.value as? FastisRange {
334342

335-
if date.isInSameDay(in: self.currentCalendar, date: currentValue.fromDate) {
343+
let dateRangeChangesDisabled = !allowDateRangeChanges
344+
let rangeSelected = !currentValue.fromDate.isInSameDay(date: currentValue.toDate)
345+
if dateRangeChangesDisabled && rangeSelected {
346+
newValue = .from(date.startOfDay(in: self.currentCalendar), to: date.endOfDay(in: self.currentCalendar))
347+
} else if date.isInSameDay(in: self.currentCalendar, date: currentValue.fromDate) {
336348
let newToDate = date.endOfDay(in: self.currentCalendar)
337349
newValue = .from(currentValue.fromDate, to: newToDate)
338350
} else if date.isInSameDay(in: self.currentCalendar, date: currentValue.toDate) {
@@ -493,7 +505,6 @@ extension FastisController where Value == FastisRange {
493505
return self.privateSelectMonthOnHeaderTap
494506
}
495507
}
496-
497508
}
498509

499510
extension FastisController where Value == Date {

0 commit comments

Comments
 (0)