from user @ Croge32
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.
@patchthecode Have you discovered anything new about this?
@Croge32 Yes. I am working on it.
But just to confirm, can you paste me your configureCalendar function code for the single row calendar that is messing up?
Also, can you show me the code you use to expand and retract the calendar?
I believe I have fixed the issue where it scrolls back the entire year. But I need to see you code in order to know if my fixed works.
Sure.
Here is my configureCalendar function:
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy MM dd"
let rows = calendarOut ? 6 : 1
let inDates: InDateCellGeneration = calendarOut ? .forAllMonths : .forFirstMonthOnly
let outDates: OutDateCellGeneration = calendarOut ? .tillEndOfGrid : .off
let startDate = currentCalendar.date(byAdding: .year, value: -1, to: Date())!
let endDate = Date()
let parameters = ConfigurationParameters(
startDate: startDate,
endDate: endDate,
numberOfRows: rows,
calendar: currentCalendar,
generateInDates: inDates,
generateOutDates: outDates,
firstDayOfWeek: .sunday)
return parameters
}
And here is my code to expand the calendar:
func expandCalendar() {
calendarViewHeight.constant = calendarOut ? 60 : 200
calendarOut = !calendarOut
gesture?.direction = calendarOut ? .up : .down
calendarView.reloadData()
UIView.animate(withDuration: 0.2) {
self.view.layoutIfNeeded()
}
}
@Croge32 thanks. looking into it
@Croge32
Ok I had a chance to look at the issue.
Concerning the calendar scrolling back to the original date, this is expected.
If you have a calendar with a certain configuration, and you change orientation, then your calendar should be visible on the same month/date. But, since you are changing the calendar layout, then the cells positions will change. Now, should the library auto scroll to the date you were previously looking at? or should it not? This is not for the library to decide. This is for you (the coder) to decide. Therefore, can do something like this?
something like this:
let dateToScrollTo: Date?
let allVisibleDates = calendarView.visibleDates()
// lets pick a date
date = allVisibleDates.inDates.first!
calendarView.frame = newSize
calendarView.reload {
self.calendarView.scrollToDate(date)
}
As for the scrollToNextSegment issue, this is a bug for singlerow. I'm currently fixing it.
@Croge32 Hey, I believe I have fixed the issue now.
Do you know how to test with master branch?
put this in your pod file ->
pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git'
then do a pod Install
Testing now. @patchthecode
Perhaps I didn't explain my first issue clearly enough, but let me try to clarify the sequence of events:
1) I open my app in 1 row mode. The calendar date selects November 23rd.
2) I shift to 6 row mode. The date stays selected and it is on the current month, November.
3) I shift back to 1 row mode. The date lands on the week of January 24-30th.
4) I shift back to 6 row mode. The date is still in November.
I see what you're saying about manually shifting it, but I am wondering why this doesn't occur when shifting back to 6 month mode? Also considering the range of my calendar is November 2015-November 2016, so January is a seemingly random place for it to shift to.
BTW it seems 1 or 6 row calendar scrolling is fixed!
It happens because of this (i speculate).
xOffset: CGFloat = 2000
So since your calendar is at the end of your date boundary, your calendar is thus at the end of the content offset of the UICollectionView.
1000. Therefore on the 6 row calendar, your offset of 1000 will still be on the end of the calendar i.e. November this month.2000 again, but your actual xOffset is on 1000 where it left from the 6-row calendar. The offset of 1000 on your single row calendar happens to land on January.1000. Your xOffset is also on 10000 i.e the End of the calendar i.e This month November.Like the library (or think my explanation was helpful)? Then feel free to leave a Star rating ★ rating on Github.
I will greatly appreciate it :)
I'll close this issue.
If you have any new issues, then do not hesitate to let me know.
This library should be in a state of no bug.
Thanks for the rating.
Have a good one. 👍
Got it working for me! Awesome stuff, thanks!