Created
April 2, 2019 06:29
-
-
Save Abhishek9634/aca9d3eb6a22d0312724955a3bde9e8a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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