Selecting a large date range all at once shows a delay before loading app [Expected]. Suggestions wanted on how to improve this code.
Version Number: 8.0.2
Description
Function "selectDates(from startDate: Date, to endDate: Date, triggerSelectionDelegate: Bool = true, keepSelectionIfMultiSelectionAllowed: Bool = false)" freeze main thread in my app when I pass too long period between startDate and endDate (about six and more months).
Steps To Reproduce
func calendar(_ calendar: JTACMonthView, didSelectDate date: Date, cell: JTACDayCell?, cellState: CellState, indexPath: IndexPath) {
var selectedDates = calendar.selectedDates
if let start = selectedDates.min(), let end = selectedDates.max() {
calendar.selectDates(from: start, to: end, triggerSelectionDelegate: false, keepSelectionIfMultiSelectionAllowed: true)
}
}
Expected Behavior
Not freeze main thread in app for a few seconds
you are calling selectDates inside of didSelect.
infinite loop?
No infinite loop here cause triggerSelectionDelegate = false. We are based on your sample code "2 Tap Ranged Selection" from Wiki. And that code also frizzed. Screen record in attachment.
Ok, so to clarify, You issue is --> When you select a Large range of dates, you application freezes until the selection is complete?
Yes that's it
can you try the menthod mentioned here? https://github.com/patchthecode/JTAppleCalendar/issues/1150
calendar.selectDates(dateRange, triggerSelectionDelegate: false, keepSelectionIfMultiSelectionAllowed: true)
Not worked for me. And I can see that method also invoke in selectDates(from:to:).
According to my tests, the following code in the method selectDates(_ dates: triggerSelectionDelegate:keepSelectionIfMultiSelectionAllowed:) slows down:

@patchthecode please help!
i think you may have to help me with a solution here.
Imagine i am selection 1,000,000 dates. Do you guys think that this should take some time to select? To me, the answer would be yes.
Now, can you suggest a solution that i can implement that will make this not happen? If you can provide me a suggestion, then I can provide a fix. Right now, i cannot think of a way to select so many dates, with zero impact to performance.
Ran into the same problem, but I understand that selecting a large range of dates would cause performance issues. Might I suggest implementing a completion handler so that if the selection is taking some time, developers can present a progress indication to the user. Would work great for me 😌
@blastback360 sounds like a good idea.
I flagged this with the help wanted.
If anyone is willing to take this up i'd be happy. Peronally though, i'd want to know a reason for why we'd select so many dates up front all at once. I am wondering if there is something else the dev can do given the limitations of this lib.
Hey guys, for huge amount of dates seems that the best way is to avoid any delegates related to selection etc and use own logic based on two dates - for example in "handleCellSelected" check if date is laying between that range and if yes - highlight view on the fly. I don't think that we need to do hard calculation for every IndexPath if we can do it only for visible cells. In this case even selection of 1 million will be efficient
give this man a medal. I think i can close this issue. The dev should be the one to implement something to help this, not the library.