Skip to content

Commit

Permalink
Swift 4.1
Browse files Browse the repository at this point in the history
Support for Swift 4.1
  • Loading branch information
Gouthamansriniv committed Dec 26, 2018
1 parent 62ccf0a commit 34dc808
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 40 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion airbnb-datepicker/airbnb-datepicker/AirbnbDatePicker.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class AirbnbDatePicker: UIView, AirbnbDatePickerDelegate {
dateInputButton.heightAnchor.constraint(equalTo: heightAnchor).isActive = true
}

func showDatePicker() {
@objc func showDatePicker() {
let datePickerViewController = AirbnbDatePickerViewController(dateFrom: selectedStartDate, dateTo: selectedEndDate)
datePickerViewController.delegate = self
let navigationController = UINavigationController(rootViewController: datePickerViewController)
Expand Down
Empty file modified airbnb-datepicker/airbnb-datepicker/AirbnbDatePickerCell.swift
100644 → 100755
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion airbnb-datepicker/airbnb-datepicker/AirbnbDatePickerFooter.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AirbnbDatePickerFooter: UIView {
fatalError("init(coder:) has not been implemented")
}

func handleSave() {
@objc func handleSave() {
if let del = delegate {
del.didSave()
}
Expand Down
Empty file.
Empty file.
60 changes: 24 additions & 36 deletions airbnb-datepicker/airbnb-datepicker/AirbnbDatePickerViewController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import Foundation

public protocol AirbnbDatePickerDelegate {
func datePickerController(_ datePickerController: AirbnbDatePickerViewController, didSaveStartDate startDate: Date?, endDate: Date?)
Expand All @@ -17,7 +18,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
let monthHeaderID = "monthHeaderID"
let cellID = "cellID"
let dateFormatter = DateFormatter()

var delegate: AirbnbDatePickerDelegate?

var selectedStartDate: Date? {
Expand Down Expand Up @@ -51,7 +52,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
return floor(view.frame.size.width / 7)
}
var collectionViewWidthConstraint: NSLayoutConstraint?


// MARK: - Initialization

Expand Down Expand Up @@ -80,7 +81,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
}

NotificationCenter.default.addObserver(self, selector: #selector(AirbnbDatePickerViewController.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)

}

deinit {
Expand All @@ -90,7 +91,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
func initDates() {
let month = calendar.component(.month, from: today)
let year = calendar.component(.year, from: today)
var dateComp = DateComponents(year: year, month: month, day: 1)
let dateComp = DateComponents(year: year, month: month, day: 1)
var curMonth = calendar.date(from: dateComp)

months = [Date]()
Expand Down Expand Up @@ -172,17 +173,17 @@ public class AirbnbDatePickerViewController: UICollectionViewController {

override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

self.automaticallyAdjustsScrollViewInsets = false
if #available(iOS 11, *) {
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
self.view.backgroundColor = Theme.PRIMARY_COLOR

setupNavigationBar()
setupViews()
setupLayout()

}

func rotated() {
@objc func rotated() {
collectionView?.collectionViewLayout.invalidateLayout()
}

Expand Down Expand Up @@ -221,19 +222,17 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
}

func setupCollectionView() {

collectionView?.translatesAutoresizingMaskIntoConstraints = false
collectionView?.alwaysBounceVertical = true
collectionView?.backgroundColor = Theme.PRIMARY_COLOR
collectionView?.showsVerticalScrollIndicator = false
collectionView?.allowsMultipleSelection = true

collectionView?.register(AirbnbDatePickerCell.self, forCellWithReuseIdentifier: cellID)
collectionView?.register(AirbnbDatePickerMonthHeader.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: monthHeaderID)

collectionView?.topAnchor.constraint(equalTo: headerSeparator.bottomAnchor).isActive = true
collectionView?.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
collectionView?.bottomAnchor.constraint(equalTo: footerSeparator.topAnchor).isActive = true

let gap = view.frame.size.width - (itemWidth * 7)
collectionViewWidthConstraint = collectionView?.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -gap)
collectionViewWidthConstraint?.isActive = true
Expand Down Expand Up @@ -309,7 +308,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {

return cell
}

override public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: monthHeaderID, for: indexPath) as! AirbnbDatePickerMonthHeader
Expand All @@ -326,7 +325,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
}

return header

}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
Expand All @@ -342,7 +341,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
let year = calendar.component(.year, from: selectedMonth)
let month = calendar.component(.month, from: selectedMonth)

var dateComp = DateComponents(year: year, month: month, day: Int(cell.dateLabel.text!))
let dateComp = DateComponents(year: year, month: month, day: Int(cell.dateLabel.text!))
let selectedDate = calendar.date(from: dateComp)!

if selectedStartDate == nil || (selectedEndDate == nil && selectedDate < selectedStartDate!) {
Expand Down Expand Up @@ -403,7 +402,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {

override public func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! AirbnbDatePickerCell

if isInBetween(indexPath: indexPath) {
deselectSelectedCells()

Expand All @@ -412,7 +411,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
let year = calendar.component(.year, from: selectedMonth)
let month = calendar.component(.month, from: selectedMonth)

var dateComp = DateComponents(year: year, month: month, day: Int(cell.dateLabel.text!))
let dateComp = DateComponents(year: year, month: month, day: Int(cell.dateLabel.text!))
let selectedDate = calendar.date(from: dateComp)!

selectedStartDate = selectedDate
Expand Down Expand Up @@ -445,13 +444,12 @@ public class AirbnbDatePickerViewController: UICollectionViewController {

override public func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
let cell = collectionView.cellForItem(at: indexPath) as! AirbnbDatePickerCell

return cell.type.contains(.Date)
}

override public func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! AirbnbDatePickerCell

cell.type.remove(.Highlighted)
cell.configureCell()
}
Expand All @@ -460,28 +458,23 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
let dateData = days[indexPath.section]
let month = calendar.component(.month, from: months[indexPath.section])
let year = calendar.component(.year, from: months[indexPath.section])

if indexPath.item < dateData.prepend || indexPath.item >= (dateData.prepend + dateData.days) {
cell.dateLabel.text = ""
cell.type = [.Empty]
} else {
let todayYear = calendar.component(.year, from: today)
let todayMonth = calendar.component(.month, from: today)
let todayDay = calendar.component(.day, from: today)

let curDay = indexPath.item - dateData.prepend + 1
let isPastDate = year == todayYear && month == todayMonth && curDay < todayDay

cell.dateLabel.text = String(curDay)
cell.dateLabel.textColor = isPastDate ? Theme.SECONDARY_COLOR : UIColor.white
cell.type = isPastDate ? [.PastDate] : [.Date]

if todayDay == curDay, todayMonth == month, todayYear == year {
cell.type.insert(.Today)
}
}

if startDateIndexPath != nil && indexPath == startDateIndexPath {
if startDateIndexPath != nil && indexPath == startDateIndexPath {
if endDateIndexPath == nil {
cell.type.insert(.Selected)
} else {
Expand Down Expand Up @@ -537,8 +530,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
}

collectionView?.performBatchUpdates({
(s) in
self.collectionView?.reloadItems(at: indexPathArr)
self.collectionView?.reloadItems(at: indexPathArr)
}, completion: nil)
}

Expand All @@ -554,7 +546,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
}

if let end = endDateIndexPath {
var indexPathArr = [IndexPath]()
let indexPathArr = [IndexPath]()
while section < months.count, section <= end.section {
let curIndexPath = IndexPath(item: item, section: section)
if let cell = collectionView?.cellForItem(at: curIndexPath) as? AirbnbDatePickerCell {
Expand All @@ -576,24 +568,22 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
}

collectionView?.performBatchUpdates({
(s) in
self.collectionView?.reloadItems(at: indexPathArr)
self.collectionView?.reloadItems(at: indexPathArr)
}, completion: nil)
}
}
}

// MARK: - Event Handlers

func handleDismiss() {
@objc func handleDismiss() {
self.navigationController?.dismiss(animated: true, completion: nil)
}

func handleClearInput() {
@objc func handleClearInput() {
deselectSelectedCells()
selectedStartDate = nil
selectedEndDate = nil

startDateIndexPath = nil
endDateIndexPath = nil
}
Expand All @@ -602,7 +592,7 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
let lastDate = months.last!
let month = calendar.component(.month, from: lastDate)
let year = calendar.component(.year, from: lastDate)
var dateComp = DateComponents(year: year, month: month + 1, day: 1)
let dateComp = DateComponents(year: year, month: month + 1, day: 1)
var curMonth = calendar.date(from: dateComp)

for _ in 0..<subsequentMonthsLoadCount {
Expand All @@ -611,10 +601,8 @@ public class AirbnbDatePickerViewController: UICollectionViewController {
let numOfDays = calendar.range(of: .day, in: .month, for: curMonth!)!.count
let firstWeekDay = calendar.component(.weekday, from: curMonth!.startOfMonth())
let lastWeekDay = calendar.component(.weekday, from: curMonth!.endOfMonth())

days.append((days: numOfDays, prepend: firstWeekDay - 1, append: 7 - lastWeekDay))
curMonth = calendar.date(byAdding: .month, value: 1, to: curMonth!)

}

if let handler = completion {
Expand Down
Empty file modified airbnb-datepicker/airbnb-datepicker/AppDelegate.swift
100644 → 100755
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file modified airbnb-datepicker/airbnb-datepicker/Base.lproj/Main.storyboard
100644 → 100755
Empty file.
Empty file modified airbnb-datepicker/airbnb-datepicker/BaseCell.swift
100644 → 100755
Empty file.
Empty file modified airbnb-datepicker/airbnb-datepicker/Date.swift
100644 → 100755
Empty file.
Empty file modified airbnb-datepicker/airbnb-datepicker/Info.plist
100644 → 100755
Empty file.
Empty file modified airbnb-datepicker/airbnb-datepicker/Theme.swift
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions airbnb-datepicker/airbnb-datepicker/UIColor.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ extension UIColor {
convenience init(hex: String) {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString = cString.substring(from: cString.index(cString.startIndex, offsetBy: 1))
cString = String(cString.suffix(from: cString.startIndex))
}

if ((cString.characters.count) != 6) {
if ((cString.count) != 6) {
self.init()
} else {
var rgbValue:UInt32 = 0
Expand Down
Empty file modified airbnb-datepicker/airbnb-datepicker/Utility.swift
100644 → 100755
Empty file.
Empty file modified airbnb-datepicker/airbnb-datepicker/ViewController.swift
100644 → 100755
Empty file.

0 comments on commit 34dc808

Please sign in to comment.