patchthecode / JTAppleCalendar

The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable
https://patchthecode.com
MIT License
7.58k stars 810 forks source link

cellState.selectedPostion() doesn't return correct value for ranged selection #1126

Closed rameswarprasad closed 5 years ago

rameswarprasad commented 5 years ago

(Required) Version Number: 8.0.1

Description

When ranged selection is available I found an issue which I think is a bug. Please look at the attached image:

Simulator Screen Shot - iPhone 8 - 2019-09-05 at 01 37 41

Here the cellState.selectedPosition() for 1st Feb is returned as .left instead of middle.

Steps To Reproduce

Here I just called selectDates method programmatically on the calendar view with 31st Jan as start date and 2nd Feb as endDate.

Expected Behavior

The value should return .middle for 1st Feb when called cellState.selectedPosition()

Additional Context

Also, I'm attaching some demo example so it's easier to play around instead of reimplementing the same thing.

Link to Demo: https://www.dropbox.com/s/5gpwwyhj9nm6p9e/CalendarDemo.zip?dl=0

patchthecode commented 5 years ago

yea... this is expected. This was the way i coded it. Another developer pointed the same thing you mention here --> https://github.com/patchthecode/JTAppleCalendar/issues/1096

We came to a conclusion that i needed an update because if i code it one way, some devs will be happy while the other devs will be upset. So in the update mentioned on that page, i proposed a middle ground.

patchthecode commented 5 years ago

Since the other issue is tracking this, I'll close this one and try to get an update soon. In the mean time, you'll have to use a different logic to find the Mid/start points.

Another developer also made a push on that thread to do a fix. But I have not had the time to look at it yet. closing this issue. Lets track it there

patchthecode commented 5 years ago

I just merged the fix. Can you let me know if it works for you?

The calendar should now have 2 modes.

calendarView.rangeSelectionMode = .continous OR calendarView.rangeSelectionMode = .segmented

In order to test this you'll have to use master branch. If you are using XCodeBeta, then you can just use SwiftPackageManager for this. Let me know if you need further help with it.