Calendar works great for the most part! Very informative tutorials.
So I'm making a calendar that has a button that expands it from 1 to 6 rows. With 6 rows I have it working and looking great, but with 1 row I have a couple issues:

When I set outDates to .off, the view starts off incorrect, but corrects itself on selection, which is a bit jarring.

This happens when I select a date near the end of my row (i.e. the right side), scroll towards that direction, and select another date on the opposite (i.e. left) side. Scrolling back towards the first selection will still show a selected date. Then if you make another selection near it, it may show the duplicate on the same row.
Relevant code:
// calendar button:
func calendarPressed(sender: Any) {
calendarViewHeight.constant = calendarOut ? 60 : 200
calendarOut = !calendarOut
calendarView.reloadData()
UIView.animate(withDuration: 0.2) {
self.view.layoutIfNeeded()
}
}
...
override func viewDidLoad() {
super.viewDidLoad()
calendarView.dataSource = self
calendarView.delegate = self
calendarView.registerCellViewXib(file: "MealsMealPlanCalendarCell")
calendarView.scrollToDate(Date(), triggerScrollToDateDelegate: false, animateScroll: false)
...
}
...
extension MealsMealPlanViewController: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy MM dd"
let rows = calendarOut ? 6 : 1
let inDates: InDateCellGeneration = calendarOut ? .forAllMonths : .off
let outDates: OutDateCellGeneration = calendarOut ? .tillEndOfGrid : .tillEndOfRow
let startDate = Calendar.current.date(byAdding: .year, value: -1, to: Date())!
let endDate = Date()
let parameters = ConfigurationParameters(
startDate: startDate,
endDate: endDate,
numberOfRows: rows,
calendar: Calendar.current,
generateInDates: inDates,
generateOutDates: outDates,
firstDayOfWeek: .sunday)
return parameters
}
func calendar(_ calendar: JTAppleCalendarView, willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) {
let myCustomCell = cell as! MealsMealPlanCalendarCell
myCustomCell.dayLabel.text = cellState.text
if cellState.dateBelongsTo == .thisMonth {
myCustomCell.dayLabel.textColor = UIColor.white
cell.isHidden = false
} else {
cell.isHidden = true
}
handleCellSelection(view: cell, cellState: cellState)
}
func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleDayCellView?, cellState: CellState) {
handleCellSelection(view: cell, cellState: cellState)
let formatter = DateFormatter()
formatter.dateFormat = "EEEE, MMMM dd, yyyy"
calendarDate?.text = formatter.string(from: date)
}
func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleDayCellView?, cellState: CellState) {
handleCellSelection(view: cell, cellState: cellState)
}
func handleCellSelection(view: JTAppleDayCellView?, cellState: CellState) {
guard let myCustomCell = view as? MealsMealPlanCalendarCell else {
return
}
if cellState.isSelected {
myCustomCell.selectedView.layer.cornerRadius = myCustomCell.selectedView.frame.size.width / 2.0
myCustomCell.selectedView.isHidden = false
} else {
myCustomCell.selectedView.isHidden = true
}
}
}
Is there anything I'm doing wrong? Thanks!
OK. your for your issues.
[s|m|t|w|t|f|s] that is outside of the calendar. Therefore your in-dates/out-dates will offset the positioning of your dates. It seems that the setting that you want is in-Dates = .forFirstMonthOnly and out-dates = .off.
Since you have an external header (and not an internal one), this setting will ensure that the dates are offset correctly. The in-date setting will start of the offset and the out-date setting being set to off will make the dates start immediately in its correct position.
Let me know if this works for you. I am looking into your 2nd issue now.
Another thing to note for issue#1, you said that it auto-corrected it self on selection. Ok there is a bug here. The bug happens on single-row calendar.
It happens with the scrollToDate() function. On single row view, it scrolls to the incorrect position. Therefore when you select the date, it readjusts it self to what it _should_ be.
I have now created a new issue here to track this -->> https://github.com/patchthecode/JTAppleCalendar/issues/197
Good to go regarding issue#1 馃憤
issue#2 still occurring. Were you able to replicate this?
@Croge32 i'll get it it in a bit. I'm currently working on issue#1.
but i'm pretty sure that the 2nd issue is nothing serious. I'll look at it in a sec.
I'll let you know if I can't replicate it. Just a min.
@Croge32 hey I think I have fixed the first issue.
can you test it?
put this in your pod file (to test the masterBranch). And run pod install
pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git'
I'll get that tested for you tomorrow!
I have now replicated the 2nd issue. Looking into it now.
I have now fixed the second issue.
Let me know if the issues are resolved when you have tested them
Worked for me! 馃憤
@patchthecode I'm noticing another issue that may or may not be related to your latest updates.
When I start my application I'm in one row mode at the current date. If I click my expand button I am in the same month. If I retract the calendar back to 1 row, the dates shown are the 24th - 30th of January, so almost 1 entire year back. Code above is basically the same.
Also calendarView.scrollToNextSegment() and calendarView.scrollToPreviousSegment() seem broken with 1 row. ScrollToPrevious goes back by entire months even when set to 1 row and scrollToNext doesn't scroll at all.
Ok. Looking into it
Lets track this here -> https://github.com/patchthecode/JTAppleCalendar/issues/202