Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced mode with SelectionMode enum #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,35 @@ Customise the **RKManager** for the desired effects as follows:

Setting the calendar, minimum and maximum dates that can be selected.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0)
RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate)

## Single date selection

Use mode 0 to select a single date.
Use mode `SelectionMode.singleDate` to select a single date.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: 0)
RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .singleDate)

## Range of dates selection

Use mode 1 to select a contiguous range of dates, from a start date to an end date.
Use mode `SelectionMode.dateRange` to select a contiguous range of dates, from a start date to an end date.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: 1)
RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .dateRange)

Note, mode 2 is automatically toggled internally and the end date must be greater than the start date.
Note, `SelectionMode.dateRange2` is automatically toggled internally and the end date must be greater than the start date.

## Multi-dates selection

Use mode 3 for selecting a number of dates.
Use mode `SelectionMode.multidate` for selecting a number of dates.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: 3)
RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .multiDate)

## Disabled-dates setting

Use any mode and set zero or more dates to be disabled (un-selectable).

For example:

var rkManager = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: 0)
var rkManager = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .singleDate)

rkManager.disabledDates.append(contentsOf: [
Date().addingTimeInterval(60*60*24*4),
Expand Down
4 changes: 4 additions & 0 deletions RKCalendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
019D282A22DBCD2E0001C990 /* demo-app-light-mode-2.png in Resources */ = {isa = PBXBuildFile; fileRef = 019D282822DBCD2E0001C990 /* demo-app-light-mode-2.png */; };
C72D24C62317A99D00A37CC1 /* RKColorSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = C72D24C52317A99D00A37CC1 /* RKColorSettings.swift */; };
C7A3D61B23126E230065D6FF /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = C7A3D61A23126E230065D6FF /* README.md */; };
C91B7A6024FE992C009C7660 /* SelectionMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91B7A5F24FE992C009C7660 /* SelectionMode.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -50,6 +51,7 @@
019D282822DBCD2E0001C990 /* demo-app-light-mode-2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "demo-app-light-mode-2.png"; sourceTree = "<group>"; };
C72D24C52317A99D00A37CC1 /* RKColorSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RKColorSettings.swift; sourceTree = "<group>"; };
C7A3D61A23126E230065D6FF /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
C91B7A5F24FE992C009C7660 /* SelectionMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectionMode.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -115,6 +117,7 @@
0112FD7522DB954900BB8F94 /* RKViewController.swift */,
0112FD6F22DB91DB00BB8F94 /* RKManager.swift */,
C72D24C52317A99D00A37CC1 /* RKColorSettings.swift */,
C91B7A5F24FE992C009C7660 /* SelectionMode.swift */,
);
path = Manager;
sourceTree = "<group>";
Expand Down Expand Up @@ -213,6 +216,7 @@
0112FD7422DB926A00BB8F94 /* RKMonth.swift in Sources */,
C72D24C62317A99D00A37CC1 /* RKColorSettings.swift in Sources */,
0112FD5722DB8D6800BB8F94 /* SceneDelegate.swift in Sources */,
C91B7A6024FE992C009C7660 /* SelectionMode.swift in Sources */,
0112FD6A22DB8EA800BB8F94 /* RKDate.swift in Sources */,
0112FD5922DB8D6800BB8F94 /* ContentView.swift in Sources */,
0112FD7622DB954900BB8F94 /* RKViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>RKCalendar.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
8 changes: 4 additions & 4 deletions RKCalendar/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ struct ContentView : View {
@State var multipleIsPresented = false
@State var deselectedIsPresented = false

var rkManager1 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0)
var rkManager1 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate)

var rkManager2 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 1) // automatically goes to mode=2 after start selection, and vice versa.
var rkManager2 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .dateRange) // automatically goes to mode=2 after start selection, and vice versa.

var rkManager3 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 3)
var rkManager3 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .multiDate)

var rkManager4 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0)
var rkManager4 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate)


var body: some View {
Expand Down
10 changes: 5 additions & 5 deletions RKCalendar/Manager/RKCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ struct RKCell: View {
struct RKCell_Previews : PreviewProvider {
static var previews: some View {
Group {
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0), isDisabled: false, isToday: false, isSelected: false, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate), isDisabled: false, isToday: false, isSelected: false, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
.previewDisplayName("Control")
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0), isDisabled: true, isToday: false, isSelected: false, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate), isDisabled: true, isToday: false, isSelected: false, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
.previewDisplayName("Disabled Date")
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0), isDisabled: false, isToday: true, isSelected: false, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate), isDisabled: false, isToday: true, isSelected: false, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
.previewDisplayName("Today")
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0), isDisabled: false, isToday: false, isSelected: true, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate), isDisabled: false, isToday: false, isSelected: true, isBetweenStartAndEnd: false), cellWidth: CGFloat(32))
.previewDisplayName("Selected Date")
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0), isDisabled: false, isToday: false, isSelected: false, isBetweenStartAndEnd: true), cellWidth: CGFloat(32))
RKCell(rkDate: RKDate(date: Date(), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate), isDisabled: false, isToday: false, isSelected: false, isBetweenStartAndEnd: true), cellWidth: CGFloat(32))
.previewDisplayName("Between Two Dates")
}
.previewLayout(.fixed(width: 300, height: 70))
Expand Down
4 changes: 2 additions & 2 deletions RKCalendar/Manager/RKManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class RKManager : ObservableObject {

var colors = RKColorSettings()

init(calendar: Calendar, minimumDate: Date, maximumDate: Date, selectedDates: [Date] = [Date](), mode: Int) {
init(calendar: Calendar, minimumDate: Date, maximumDate: Date, selectedDates: [Date] = [Date](), mode: SelectionMode) {
self.calendar = calendar
self.minimumDate = minimumDate
self.maximumDate = maximumDate
self.selectedDates = selectedDates
self.mode = mode
self.mode = mode.rawValue
}

func selectedDatesContains(date: Date) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion RKCalendar/Manager/RKMonth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ struct RKMonth: View {
#if DEBUG
struct RKMonth_Previews : PreviewProvider {
static var previews: some View {
RKMonth(isPresented: .constant(false),rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0), monthOffset: 0)
RKMonth(isPresented: .constant(false),rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .dateRange), monthOffset: 0)
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions RKCalendar/Manager/RKViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct RKViewController: View {
struct RKViewController_Previews : PreviewProvider {
static var previews: some View {
Group {
RKViewController(isPresented: .constant(false), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0))
RKViewController(isPresented: .constant(false), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*32), mode: 0))
RKViewController(isPresented: .constant(false), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate))
RKViewController(isPresented: .constant(false), rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*32), mode: .singleDate))
.environment(\.colorScheme, .dark)
.environment(\.layoutDirection, .rightToLeft)
}
Expand Down
2 changes: 1 addition & 1 deletion RKCalendar/Manager/RKWeekdayHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct RKWeekdayHeader : View {
#if DEBUG
struct RKWeekdayHeader_Previews : PreviewProvider {
static var previews: some View {
RKWeekdayHeader(rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 0))
RKWeekdayHeader(rkManager: RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate))
}
}
#endif
Expand Down
16 changes: 16 additions & 0 deletions RKCalendar/Manager/SelectionMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SelectionMode.swift
// RKCalendar
//
// Created by Maxwell James Omdal on 9/1/20.
// Copyright © 2020 Maxwell James Omdal. All rights reserved.
//

import Foundation

enum SelectionMode: Int {
case singleDate = 0
case dateRange
case dateRange2
case multiDate
}