This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy var collectionViewDataSource: CalendarCollectionViewDataSource = { | |
let range = CalendarManager.getCalendarRange(withStartDate: startDate, withEndDate: endDate) | |
let collectionView = CalendarCollectionViewDataSource(calendarRange: range) | |
return collectionView | |
}() | |
collectionView.dataSource = self.collectionViewDataSource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func numberOfSections(in collectionView: UICollectionView) -> Int { | |
return calendarRange.count | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return calendarRange[section].daysInMonth | |
} | |
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { | |
switch kind { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CalendarRange { | |
let month: Int | |
let year: Int | |
let daysInMonth: Int | |
} | |
static func getCalendarRange(withStartDate startDate: Date, withEndDate endDate: Date) -> [CalendarRange] { | |
let months = Calendar.current.dateComponents([.month], from: startDate, to: endDate).month ?? 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CalendarCell.register(with: collectionView) | |
CalendarHeader.register(with: collectionView) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalendarHeader: UICollectionReusableView { | |
@IBOutlet weak var monthLabel: UILabel! | |
static let identifier = "calendarHeader" | |
static func register(with collectionView: UICollectionView) { | |
collectionView.register(UINib.init(nibName: "CalendarHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader , withReuseIdentifier: identifier) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalendarCell: UICollectionViewCell { | |
@IBOutlet weak var dateLabel: UILabel! | |
static let identifier = "calendarCell" | |
static func register(with collectionView: UICollectionView) { | |
collectionView.register(UINib.init(nibName: "CalendarCell", bundle: nil), forCellWithReuseIdentifier: identifier) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy var collectionViewFlowLayout : CalendarCollectionViewFlowLayout = { | |
let layout = CalendarCollectionViewFlowLayout() | |
return layout | |
}() | |
collectionView.delegate = self.collectionViewFlowLayout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var itemsPerRow: CGFloat = 3 | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
guard let flow = collectionViewLayout as? UICollectionViewFlowLayout else { | |
fatalError("only flow layout is supported") | |
} | |
let paddingSpace = flow.sectionInset.left + flow.sectionInset.right + (minimumInteritemSpacing * itemsPerRow) | |
let availableWidth = collectionView.frame.width - paddingSpace | |
let widthPerItem = availableWidth / itemsPerRow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
contentView.addSubview(collectionView) | |
collectionView.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0).isActive = true | |
collectionView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 0).isActive = true | |
collectionView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant: 0).isActive = true | |
collectionView.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor, constant: 0).isActive = true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react" | |
const formEncode = data => { | |
return Object.keys(data) | |
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key])) | |
.join("&") | |
} | |
const RegistrationForm = () => { | |
const [email, setEmail] = useState("") |
NewerOlder