Swiftpack.co -  retailcrm/Fastis as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
retailcrm/Fastis
Simple date picker created using JTAppleCalendar library
.package(url: "https://github.com/retailcrm/Fastis.git", from: "1.0.13")

Fastis

Carthage compatible SwiftMP compatible Cocoapods compatible Swift Xcode License

Fastis is a fully customizable UI component for picking dates and ranges created using JTAppleCalendar library.

Requirements

  • iOS 11.0+
  • Xcode 11.0+
  • Swift 5.0+

Features

  • ☑ Flexible customization
  • ☑ Shortcuts for dates and ranges
  • ☑ Single date and date range modes

Instalation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Fastis into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Fastis', '~> 1.0.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Fastis into your Xcode project using Carthage, specify it in your Cartfile:

github "retailcrm/Fastis" ~> 1.0.0

Run carthage update to build the framework, drag the following framework into your Xcode project:

  • Fastis.framework
  • SnapKit.framewok
  • PrettyCards.framework
  • JTAppleCalendar.framework

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Fastis as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/retailcrm/Fastis.git", .upToNextMajor(from: "1.0.0"))
]

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Fastis into your project manually.

Usage

Quick Start

import Fastis

class MyViewController: UIViewController {

   func chooseDate() {
        let fastisController = FastisController(mode: .range)
        fastisController.title = "Choose range"
        fastisController.maximumDate = Date()
        fastisController.allowsToChooseNilDate = true
        fastisController.shortcuts = [.today, .lastWeek]
        fastisController.doneHandler = { resultRange in
            ...
        }
        fastisController.present(above: self)
    }

}

Single and range modes

If you want to get a single date you have to use Date type:

let fastisController = FastisController(mode: .single)
fastisController.initialValue = Date()
fastisController.doneHandler = { resultDate in
	print(resultDate) // resultDate is Date
}

If you want to get a date range you have to use FastisRange type:

let fastisController = FastisController(mode: .range)
fastisController.initialValue = FastisRange(from: Date(), to: Date()) // or .from(Date(), to: Date())
fastisController.doneHandler = { resultRange in
	print(resultRange) // resultDate is FastisRange
}

Configuration

FastisController have the following default configuration parameters:

var shortcuts: [FastisShortcut<Value>] = []
var allowsToChooseNilDate: Bool = false
var dismissHandler: (() -> Void)? = nil
var doneHandler: ((Value?) -> Void)? = nil
var initialValue: Value? = nil
var minimumDate: Date? = nil
var maximumDate: Date? = nil
var selectMonthOnHeaderTap: Bool = true
var allowDateRangeChanges: Bool = true
  • shortcuts- Shortcuts array. Default value is []. See Shortcuts section
  • allowsToChooseNilDate- Allow to choose nil date. If you set true done button will be wlways enabled. Default value is false.
  • dismissHandler- The block to execute after the dismissal finishes. Default value is nil.
  • doneHandler- The block to execute after "Done" button will be tapped. Default value is nil.
  • initialValue- And initial value which will be selected bu default. Default value is nil.
  • minimumDate- Minimal selection date. Dates less then current will be markes as unavailable. Default value is nil.
  • maximumDate- Maximum selection date. Dates greather then current will be markes as unavailable. Default value is nil.
  • 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.
  • 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.

Shortcuts

Using shortcuts allows you to quick select prepared dates or date ranges. By default .shortcuts is empty. If you don't provide any shortcuts the bottom container will be hidden.

In Fasis available some prepared shortcuts for each mode:

  • For .single: .today, .tomorrow, .yesterday
  • For .range: .today, .lastWeek, .lastMonth

Also you can create your own shortcut:

var customShortcut = FastisShortcut(name: "Today") {
	let now = Date()
	return FastisRange(from: now.startOfDay(), to: now.endOfDay())
}
fastisController.shortcuts = [customShortcut, .lastWeek]

Customization

Fastis can be customized global or local. FastisConfig have some sections:

  • controller - base view controller (cancelButtonTitle, doneButtonTitle, etc.)
  • monthHeader - month titles
  • dayCell - day cells (selection parameters, font, etc.)
  • weekView - top header view with week day names
  • currentValueView - current value view appereance (clear button, date format, etc.)
  • shortcutContainerView - bottom view with shortcuts
  • shortcutItemView - shortcut item in the bottom view

To cutomize all Fastis controllers in your app use FastisConfig.default:

FastisConfig.default.monthHeader.labelColor = .red

To customize special FastisController instance:

var customConfig = FastisConfig.default
customConfig.controller.dayCell.dateLabelColor = .blue
let fastisController = FastisController(mode: .range, config: customConfig)

Credits

License

Fastis is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 10
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

36 weeks ago

Day cell custom selection view corner radius and ranged background view inset (thanks @wojteklembryk); Fix bug with month selection

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API