Skip to content

Instantly share code, notes, and snippets.

@Abhishek9634
Created April 2, 2019 06:29
Show Gist options
  • Save Abhishek9634/aca9d3eb6a22d0312724955a3bde9e8a to your computer and use it in GitHub Desktop.
Save Abhishek9634/aca9d3eb6a22d0312724955a3bde9e8a to your computer and use it in GitHub Desktop.
extension MyViewController: DropDownViewDelegate {
private func setupData() {
guard let model = self.dropDownView.cellItems.first else { return }
self.handleDates(model: model)
}
private func hideOnOtherView() {
if self.dropDownView.isVisible {
self.dropDownView.toggleMenu()
}
}
private func setupDropDown() {
let cellItems = [DropDownCellModel(item: .daily, isSelected: true),
DropDownCellModel(item: .weekly),
DropDownCellModel(item: .monthly)]
self.dropDownView.setUpItems(cellItems)
self.dropDownView.delegate = self
}
func didSelect(_ dropDown: DropDownView, model: DropDownCellModel) {
self.handleDates(model: model)
}
private func handleDates(model: DropDownCellModel) {
switch model.item {
case .daily:
self.dates = Date.getDates(days: -90).map {
ScheduleDateCellModel(date: $0)
}
case .weekly:
self.dates = Date().getPreviousWeeks(range: 12).map {
ScheduleDateCellModel(dates: $0, dateGroup: model.item)
}
case .monthly:
self.dates = Date.getMonths(range: -3).map {
ScheduleDateCellModel(date: $0, dateGroup: model.item)
}
default:
return
}
self.collectionView.reloadData()
self.selectDate(IndexPath(row: self.dates.count - 1, section: 0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment