Jtapplecalendar: Incorrect cellState.selectedPosition for specific sell

Created on 1 Feb 2017  ยท  17Comments  ยท  Source: patchthecode/JTAppleCalendar

Hello there one more time :D Sorry for a lot of issues.

Okey, i found bug (as i think) with selected position of cellState for the cell if cell is the first sunday of the month. This cell should be as .full selectedPosition as i understand. It is produced only if the month starts with Sunday (or another first day of week?).

I can catch this case as:

if (cellState.day == DaysOfWeek.sunday && cellState.text == "1") {

}

And for best understanding of such problem i post the image
ym3h9v2iqee2r9tx5bqx0pev8-0ywsq4imqrhdyjrpc

Already Fixed on Master Branch bug

Most helpful comment

@KyleConway ok. I think i did the fix for the first issue, and i kept my fingers crossed hoping it will fix your issue ๐Ÿ˜† .
Let me look into you use-case now.

All 17 comments

Ok. this is a real issue.
I know the solution.
I'll code a fix this weekend for the latest (or earlier if im free).

@patchthecode I am able to reproduce this issue as well. In addition to the use case described above, I am also seeing similar behavior when selecting outdate and indate cells.

For instance, I have a vertically enabled calendar with rangeSelectionWillBeUsed and allowsMultipleSelection both enabled. Within thedidSelectDate delegate callback, I am using

selectDates(from startDate: Date, to endDate: Date, triggerSelectionDelegate: Bool = true, keepSelectionIfMultiSelectionAllowed: Bool = false) {
...
...
}

to select the new range of dates (done similar to your multiple selection tutorial).
If I enter the calendarView screen (no pre-selected dates) and select an outdate, everything is drawn fine. But if I then select another outdate 2 cells later in the calendar, the two newly selected cells are displayed fine but the first selected cell is not redisplayed.

I want a bubble effect on the selected range of dates and need the first selected date to redraw. Attached is a screen shot of the result for reference. This is not the case with the monthly dates - I am only seeing this behavior for indates and outdates. Also if the neighboring indate or outdate is selected it works fine - it is when the indate/outdate is more than 1 cell away from the last selected that the redraw fails. Let me know if you need any more details.
screen shot 2017-02-03 at 4 32 38 pm

@patchthecode I've made pod update to version 6.1.2 but still see the incorrect selectedPosition for the dates such as 1st May 2017th. Did I miss anything? Thanks!

@tungfam the fix was done on master branch.
You need this in your pod file ->

pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git'

when do a pod install.

If all is well, this will be released in next version

So for example:

    *   *   *   *
A | B | C | D | E | F

If B, C, D and E are selected. The selected position of:

  1. B = left
  2. C = middle
  3. D = middle
  4. E = right
  5. A and F = none

The job of selectedPosition() is to return the selectedPosition. The Job of selected position is not to create a range.
We use selectedPosition to help us to create a range.

So when you say that you are getting the incorrect selectedPosition, then answer me this -->
Is the position that you are getting different from what is described above?

@patchthecode I have updated my PodFile to point to master as you described above. I wiped my pods and reinstalled. The fix is not correct for the issue that I described.

Referencing the use case and image that I posted before: I have a

handleCellDisplay(dayCellView: JTAppleDayCellView?, cellState: CellState, date: Date) {...} 

func that is called from willDisplayCell, didDeselectDate, and didSelectDate delegate callbacks similar to the tutorials.

When I enter the calendarView with no dates preselected - then I select the date 3/1/2017. After I then select 3/3/2017. These are both outdates in my calendar and I see the same result shown in my attached image above. I added a print statement to handleCellDisplay - this is what I am seeing:

handleCellDisplay -- date: 2017-03-01 08:00:00 +0000, selectedPosition: full
โ€”โ€”โ€” End of first selection (3/1/2017) display
handleCellDisplay -- date: 2017-03-03 08:00:00 +0000, selectedPosition: right
handleCellDisplay -- date: 2017-03-02 08:00:00 +0000, selectedPosition: middle
โ€”โ€”โ€” End of second selection (3/3/2017) display

From the print statements you can see the first date 3/1/2017 is not being redisplayed on the second selection of date 3/3/2017. In contrast, if I do the same steps with visible current month dates and not indates or outdates I am seeing this output. Referencing the above attached image, the dates I am using are 2/26/2017 and 2/28/2018:

handleCellDisplay -- date: 2017-02-26 08:00:00 +0000, selectedPosition: full
โ€”โ€”โ€” End of first selection (2/26/2017) display
handleCellDisplay -- date: 2017-02-28 08:00:00 +0000, selectedPosition: right
handleCellDisplay -- date: 2017-02-26 08:00:00 +0000, selectedPosition: left
handleCellDisplay -- date: 2017-02-27 08:00:00 +0000, selectedPosition: middle
handleCellDisplay -- date: 2017-02-28 08:00:00 +0000, selectedPosition: right
โ€”โ€”โ€” End of second selection (2/28/2017) display

You can see in the second date selection redisplay that the first date selected (2/26/2017) is being redisplayed correctly - its selectedPosition is updated from "full" to "left". This is not happening with the selection of indates or outdates and only correctly redisplaying with visible month dates.
Let me know if you need any more details - thank you for all the help.

@KyleConway ok. I think i did the fix for the first issue, and i kept my fingers crossed hoping it will fix your issue ๐Ÿ˜† .
Let me look into you use-case now.

@KyleConway ok after looking into your issue, i do not think what you are experiencing is a bug (unless i am wrong).

You are using this to select right?

calendarView.selectDates(from: someStartDate, to: someEndDate,  triggerSelectionDelegate: false, keepSelectionIfMultiSelectionAllowed: true)

I think what you need is just this:

calendarView.selectDates(from: someStartDate, to: someEndDate)

I think in your code, you are not triggering the delegate.
Did this resolve your issue?

@KyleConway that said, i did find another issue with range selection I am currently fixing. If the code suggested above does not resolve your problem, then this next fix will.

That update to my implementation of selectDates looks to have done it. Thank you for the feedback! I'm still interested in the fix you described - will there be a new release once your change is applied? I only ask because I am using pods and 6.1.2 does not include a lot of the latest enhancements. I am pointing to master in the mean time

@KyleConway you can stay on master branch. I will make an official release once i finish that last logic change with range selection. So official version might be released in about 1 week? more or less.

@patchthecode
I tried and got this result (if select day from the first week of month):

But if I select some day of second week I get expected result:

Configuration:

        let parameters = ConfigurationParameters(startDate: startDate,
                                                 endDate: endDate,
                                                 numberOfRows: 6,
                                                 calendar: Calendar.current,
                                                 generateInDates: .forAllMonths,
                                                 generateOutDates: .tillEndOfGrid,
                                                 firstDayOfWeek: .sunday)
func calendar(_ calendar: JTAppleCalendarView, willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) {
        let calendarCell = cell as! CalendarCellView
        ...
        if cellState.dateBelongsTo == .thisMonth {
            calendarCell.isHidden = false
        } else {
            calendarCell.isHidden = true
        }
        ...
    }

@handioq that would be the other issue I am currently fixing.
I am thinking of a way to handle it. The values you are getting are correct. But I have to change the way the code behaves. I shall implement something in another day or 2.

closing this as the original issue has been resolved.

@patchthecode sounds good! thanks a lot! where is the path to the latest branch that i can pull from to have this update?

The original issue has been solved.

But your issue with the correct way to display selectedPosition() will be racked here -> https://github.com/patchthecode/JTAppleCalendar/issues/318

@tungfam leave a comment on that page you will be notified of the changes. I have only now gotten to this issue as there were others to resolve

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fatalution picture Fatalution  ยท  3Comments

PedroAnibarro1 picture PedroAnibarro1  ยท  5Comments

VladFrolov picture VladFrolov  ยท  4Comments

blinkmeoff picture blinkmeoff  ยท  3Comments

MoridinBG picture MoridinBG  ยท  5Comments