From e228c06797b1763ac62ddf1ad94712f27a99899f Mon Sep 17 00:00:00 2001 From: jdtzmn Date: Wed, 5 Feb 2020 15:05:16 -0500 Subject: [PATCH] Basic SwiftPM support (#10) * Add .gitignore and prepare for SPM * Make certain classes and properties public * Make ColorSettings public --- .gitignore | 118 ++++++++++++++++++ Package.swift | 31 +++++ RKCalendar/Manager/RKColorSettings.swift | 33 ----- RKCalendar/Manager/RKManager.swift | 56 --------- .../RKCalendar}/RKCell.swift | 0 Sources/RKCalendar/RKColorSettings.swift | 33 +++++ .../RKCalendar}/RKDate.swift | 0 Sources/RKCalendar/RKManager.swift | 56 +++++++++ .../RKCalendar}/RKMonth.swift | 0 .../RKCalendar}/RKViewController.swift | 13 +- .../RKCalendar}/RKWeekdayHeader.swift | 0 11 files changed, 247 insertions(+), 93 deletions(-) create mode 100644 .gitignore create mode 100644 Package.swift delete mode 100644 RKCalendar/Manager/RKColorSettings.swift delete mode 100644 RKCalendar/Manager/RKManager.swift rename {RKCalendar/Manager => Sources/RKCalendar}/RKCell.swift (100%) create mode 100644 Sources/RKCalendar/RKColorSettings.swift rename {RKCalendar/Manager => Sources/RKCalendar}/RKDate.swift (100%) create mode 100644 Sources/RKCalendar/RKManager.swift rename {RKCalendar/Manager => Sources/RKCalendar}/RKMonth.swift (100%) rename {RKCalendar/Manager => Sources/RKCalendar}/RKViewController.swift (81%) rename {RKCalendar/Manager => Sources/RKCalendar}/RKWeekdayHeader.swift (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da54006 --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ + +# Created by https://www.gitignore.io/api/macos,swift,swiftpackagemanager +# Edit at https://www.gitignore.io/?templates=macos,swift,swiftpackagemanager + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +.build/ +# Add this line if you want to avoid checking in Xcode SPM integration. +# .swiftpm/xcode + +# CocoaPods +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# Pods/ +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +### SwiftPackageManager ### +Packages +xcuserdata +*.xcodeproj + + +# End of https://www.gitignore.io/api/macos,swift,swiftpackagemanager \ No newline at end of file diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..512cb05 --- /dev/null +++ b/Package.swift @@ -0,0 +1,31 @@ +// swift-tools-version:5.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "RKCalendar", + platforms: [ + .iOS(.v13), + ], + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "RKCalendar", + targets: ["RKCalendar"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "RKCalendar", + dependencies: []), + // .testTarget( + // name: "RKCalendarTests", + // dependencies: ["RKCalendar"]), + ] +) diff --git a/RKCalendar/Manager/RKColorSettings.swift b/RKCalendar/Manager/RKColorSettings.swift deleted file mode 100644 index 7631ff8..0000000 --- a/RKCalendar/Manager/RKColorSettings.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// RKColorSettings.swift -// RKCalendar -// -// Copyright © 2019 Raffi Kian. All rights reserved. -// - -import Foundation -import Combine -import SwiftUI - -class RKColorSettings : ObservableObject { - - // foreground colors - @Published var textColor: Color = Color.primary - @Published var todayColor: Color = Color.white - @Published var selectedColor: Color = Color.white - @Published var disabledColor: Color = Color.gray - @Published var betweenStartAndEndColor: Color = Color.white - // background colors - @Published var textBackColor: Color = Color.clear - @Published var todayBackColor: Color = Color.gray - @Published var selectedBackColor: Color = Color.red - @Published var disabledBackColor: Color = Color.clear - @Published var betweenStartAndEndBackColor: Color = Color.blue - // headers foreground colors - @Published var weekdayHeaderColor: Color = Color.primary - @Published var monthHeaderColor: Color = Color.primary - // headers background colors - @Published var weekdayHeaderBackColor: Color = Color.clear - @Published var monthBackColor: Color = Color.clear - -} diff --git a/RKCalendar/Manager/RKManager.swift b/RKCalendar/Manager/RKManager.swift deleted file mode 100644 index ea97da7..0000000 --- a/RKCalendar/Manager/RKManager.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// RKManager.swift -// RKCalendar -// -// Created by Raffi Kian on 7/14/19. -// Copyright © 2019 Raffi Kian. All rights reserved. -// - -import SwiftUI - -class RKManager : ObservableObject { - - @Published var calendar = Calendar.current - @Published var minimumDate: Date = Date() - @Published var maximumDate: Date = Date() - @Published var disabledDates: [Date] = [Date]() - @Published var selectedDates: [Date] = [Date]() - @Published var selectedDate: Date! = nil - @Published var startDate: Date! = nil - @Published var endDate: Date! = nil - - @Published var mode: Int = 0 - - var colors = RKColorSettings() - - init(calendar: Calendar, minimumDate: Date, maximumDate: Date, selectedDates: [Date] = [Date](), mode: Int) { - self.calendar = calendar - self.minimumDate = minimumDate - self.maximumDate = maximumDate - self.selectedDates = selectedDates - self.mode = mode - } - - func selectedDatesContains(date: Date) -> Bool { - if let _ = self.selectedDates.first(where: { calendar.isDate($0, inSameDayAs: date) }) { - return true - } - return false - } - - func selectedDatesFindIndex(date: Date) -> Int? { - return self.selectedDates.firstIndex(where: { calendar.isDate($0, inSameDayAs: date) }) - } - - func disabledDatesContains(date: Date) -> Bool { - if let _ = self.disabledDates.first(where: { calendar.isDate($0, inSameDayAs: date) }) { - return true - } - return false - } - - func disabledDatesFindIndex(date: Date) -> Int? { - return self.disabledDates.firstIndex(where: { calendar.isDate($0, inSameDayAs: date) }) - } - -} diff --git a/RKCalendar/Manager/RKCell.swift b/Sources/RKCalendar/RKCell.swift similarity index 100% rename from RKCalendar/Manager/RKCell.swift rename to Sources/RKCalendar/RKCell.swift diff --git a/Sources/RKCalendar/RKColorSettings.swift b/Sources/RKCalendar/RKColorSettings.swift new file mode 100644 index 0000000..bc14768 --- /dev/null +++ b/Sources/RKCalendar/RKColorSettings.swift @@ -0,0 +1,33 @@ +// +// RKColorSettings.swift +// RKCalendar +// +// Copyright © 2019 Raffi Kian. All rights reserved. +// + +import Foundation +import Combine +import SwiftUI + +public class RKColorSettings : ObservableObject { + + // foreground colors + @Published public var textColor: Color = Color.primary + @Published public var todayColor: Color = Color.white + @Published public var selectedColor: Color = Color.white + @Published public var disabledColor: Color = Color.gray + @Published public var betweenStartAndEndColor: Color = Color.white + // background colors + @Published public var textBackColor: Color = Color.clear + @Published public var todayBackColor: Color = Color.gray + @Published public var selectedBackColor: Color = Color.red + @Published public var disabledBackColor: Color = Color.clear + @Published public var betweenStartAndEndBackColor: Color = Color.blue + // headers foreground colors + @Published public var weekdayHeaderColor: Color = Color.primary + @Published public var monthHeaderColor: Color = Color.primary + // headers background colors + @Published public var weekdayHeaderBackColor: Color = Color.clear + @Published public var monthBackColor: Color = Color.clear + +} diff --git a/RKCalendar/Manager/RKDate.swift b/Sources/RKCalendar/RKDate.swift similarity index 100% rename from RKCalendar/Manager/RKDate.swift rename to Sources/RKCalendar/RKDate.swift diff --git a/Sources/RKCalendar/RKManager.swift b/Sources/RKCalendar/RKManager.swift new file mode 100644 index 0000000..2b4d52a --- /dev/null +++ b/Sources/RKCalendar/RKManager.swift @@ -0,0 +1,56 @@ +// +// RKManager.swift +// RKCalendar +// +// Created by Raffi Kian on 7/14/19. +// Copyright © 2019 Raffi Kian. All rights reserved. +// + +import SwiftUI + +public class RKManager : ObservableObject { + + @Published public var calendar = Calendar.current + @Published public var minimumDate: Date = Date() + @Published public var maximumDate: Date = Date() + @Published public var disabledDates: [Date] = [Date]() + @Published public var selectedDates: [Date] = [Date]() + @Published public var selectedDate: Date! = nil + @Published public var startDate: Date! = nil + @Published public var endDate: Date! = nil + + @Published public var mode: Int = 0 + + public var colors = RKColorSettings() + + public init(calendar: Calendar, minimumDate: Date, maximumDate: Date, selectedDates: [Date] = [Date](), mode: Int) { + self.calendar = calendar + self.minimumDate = minimumDate + self.maximumDate = maximumDate + self.selectedDates = selectedDates + self.mode = mode + } + + public func selectedDatesContains(date: Date) -> Bool { + if let _ = self.selectedDates.first(where: { calendar.isDate($0, inSameDayAs: date) }) { + return true + } + return false + } + + public func selectedDatesFindIndex(date: Date) -> Int? { + return self.selectedDates.firstIndex(where: { calendar.isDate($0, inSameDayAs: date) }) + } + + public func disabledDatesContains(date: Date) -> Bool { + if let _ = self.disabledDates.first(where: { calendar.isDate($0, inSameDayAs: date) }) { + return true + } + return false + } + + public func disabledDatesFindIndex(date: Date) -> Int? { + return self.disabledDates.firstIndex(where: { calendar.isDate($0, inSameDayAs: date) }) + } + +} diff --git a/RKCalendar/Manager/RKMonth.swift b/Sources/RKCalendar/RKMonth.swift similarity index 100% rename from RKCalendar/Manager/RKMonth.swift rename to Sources/RKCalendar/RKMonth.swift diff --git a/RKCalendar/Manager/RKViewController.swift b/Sources/RKCalendar/RKViewController.swift similarity index 81% rename from RKCalendar/Manager/RKViewController.swift rename to Sources/RKCalendar/RKViewController.swift index f421501..d163c47 100644 --- a/RKCalendar/Manager/RKViewController.swift +++ b/Sources/RKCalendar/RKViewController.swift @@ -8,19 +8,24 @@ import SwiftUI -struct RKViewController: View { +public struct RKViewController: View { - @Binding var isPresented: Bool + var isPresented: Binding @ObservedObject var rkManager: RKManager - var body: some View { + public init (isPresented: Binding, rkManager: RKManager) { + self.isPresented = isPresented + self.rkManager = rkManager + } + + public var body: some View { Group { RKWeekdayHeader(rkManager: self.rkManager) Divider() List { ForEach(0..