Skip to content

Commit

Permalink
Basic SwiftPM support (#10)
Browse files Browse the repository at this point in the history
* Add .gitignore and prepare for SPM

* Make certain classes and properties public

* Make ColorSettings public
  • Loading branch information
jdtzmn authored Feb 5, 2020
1 parent 14b9d5f commit e228c06
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 93 deletions.
118 changes: 118 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"]),
]
)
33 changes: 0 additions & 33 deletions RKCalendar/Manager/RKColorSettings.swift

This file was deleted.

56 changes: 0 additions & 56 deletions RKCalendar/Manager/RKManager.swift

This file was deleted.

File renamed without changes.
33 changes: 33 additions & 0 deletions Sources/RKCalendar/RKColorSettings.swift
Original file line number Diff line number Diff line change
@@ -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

}
File renamed without changes.
56 changes: 56 additions & 0 deletions Sources/RKCalendar/RKManager.swift
Original file line number Diff line number Diff line change
@@ -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) })
}

}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

import SwiftUI

struct RKViewController: View {
public struct RKViewController: View {

@Binding var isPresented: Bool
var isPresented: Binding<Bool>

@ObservedObject var rkManager: RKManager

var body: some View {
public init (isPresented: Binding<Bool>, rkManager: RKManager) {
self.isPresented = isPresented
self.rkManager = rkManager
}

public var body: some View {
Group {
RKWeekdayHeader(rkManager: self.rkManager)
Divider()
List {
ForEach(0..<numberOfMonths()) { index in
RKMonth(isPresented: self.$isPresented, rkManager: self.rkManager, monthOffset: index)
RKMonth(isPresented: self.isPresented, rkManager: self.rkManager, monthOffset: index)
}
Divider()
}
Expand Down
File renamed without changes.

0 comments on commit e228c06

Please sign in to comment.