JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

SelectedPosition problem when config generateInDates or generateOutDates

Open SajjadKharrazi opened this issue 4 years ago • 19 comments

with these configuration of calendar:

ConfigurationParameters(startDate: startDate, endDate: endDate, generateInDates: .off, generateOutDates: .off)

then cellState.selectedPosition() returns wrong response in start and end of month. you have an 2tapRangedSelection example, you can edit it and see wrong result.

SajjadKharrazi avatar May 15 '20 19:05 SajjadKharrazi

in my app i set this generateOutDates: .tillEndOfRow and as you can see if month day ends at middle of the week, everything works great:

image

but if a month day ends at end of the week, so it will break. like Jun 2021 and Jul 2021

image

or in April 2022 and May 2022:

image

SajjadKharrazi avatar May 15 '20 22:05 SajjadKharrazi

when i set generateOutDates: .off, it will be like this: ( end of the month day is in middle )

image

SajjadKharrazi avatar May 15 '20 22:05 SajjadKharrazi

this ?

calendarView.rangeSelectionMode = .continuous
calendarView.rangeSelectionMode = .segmented

patchthecode avatar May 16 '20 02:05 patchthecode

with .continuous it works correctly

thank you

SajjadKharrazi avatar May 16 '20 10:05 SajjadKharrazi

oops! with generateOutDates: .tillEndOfRow and calendarView.rangeSelectionMode = .continuous look likes great!

but with generateOutDates: .off and calendarView.rangeSelectionMode = .continuous, last day of month does not have correct SelectedPosition state ( i selected from 22 Jul to 31 Jul )

image

SajjadKharrazi avatar May 16 '20 10:05 SajjadKharrazi

The behaviour you are seeing is not a bug. It is behaving as intended. It appears that way on your screen because you have hidden the outdates.

The real issue here seems to be this --> I do not have a have to code the library that will satisfy every developer for ranged selection.

There are many conditions that have to be considered. I will list them later today.

patchthecode avatar May 16 '20 13:05 patchthecode

ok. I see an edge case fix that i can apply. Let me test it.

patchthecode avatar May 16 '20 13:05 patchthecode

Keep in mind, i know how to fix your issue. However, if i code it the way you want, then other developers might not like the new behavior. Therefore, let me test an edgecase fix for this case when the final day lands on end of index. Be right back.

patchthecode avatar May 16 '20 13:05 patchthecode

Ok yea, the fix will work. But other developers wont be happy.

Therefore i have determined the ultimate solution for this. This library needs to create a new set of functions.

calendarView.showIndates()
calendarView.hideIndates()
calendarView.showoutDates()
calendarView.hideOutDates()

Because the problem is that i let the developers determine when to show or hide the indates/outDates on their own. Because of this, the library does not know when a developer has done this. And because I do not know, I cannot suggest the best visual way the range selection should look.

However, if this library now begins to manage the visibility/invisibility of the inDates/OutDates, Then i will know how to adjust what the ranged left, right, middle should look like.

patchthecode avatar May 16 '20 13:05 patchthecode

greaaaat!!! when we can use this?

SajjadKharrazi avatar May 16 '20 13:05 SajjadKharrazi

I didnt want this library to "hold the developers hand" so much however..... But it seems that i locked my self into this problem the moment i introduced the selectedPosition feature

patchthecode avatar May 16 '20 13:05 patchthecode

it's not possible to handle it with generateOutDates parameters?

SajjadKharrazi avatar May 16 '20 14:05 SajjadKharrazi

if generateOutDates is .off then handle it like calendarView.hideOutDates()

SajjadKharrazi avatar May 16 '20 14:05 SajjadKharrazi

How do you suggest?
This is the problem with selecting dates 26 - 31 with outdates/indates hidden.

Screen Shot 2020-05-16 at 10 02 32 AM

If i unhide it, you can see that the library correctly does it as continuous. The 2nd row of selected dates is** the indates you hid. You can see it is correctly continous.

Screen Shot 2020-05-16 at 10 03 57 AM

patchthecode avatar May 16 '20 14:05 patchthecode

But because it is hidden by the developer (and not the library). The library does not know about it. And therefore cannot make the 31 to be red color.

I can do a fix to fix the issue. But then it will no longer be continuous. However, If the library manages the visibility of indates/outdates for the developer, then i can fix the range selection under the hood.

patchthecode avatar May 16 '20 14:05 patchthecode

but i think developer hide outDate and inDate dates. we always have one 31 which is shown and it's not hidden. so you can decide selectedPosition on visible date.

as you said above if you want to add these functions in library:

calendarView.showIndates()
calendarView.hideIndates()
calendarView.showoutDates()
calendarView.hideOutDates()

i think you can handle it with generateInDates and generateOutDates. like this: ( i think these are equal )

{ calendarView.showIndates() } == { generateInDates: .forFirstMonthOnly, .forAllMonths }
{ calendarView.hideIndates() } == { generateInDates: .off }
{ calendarView.showoutDates() } == { generateOutDates: .tillEndOfRow, .tillEndOfGrid }
{ calendarView.hideoutDates() } == { generateOutDates: .off }

Although maybe I'm wrong and just .off param is equal to related hide or show function

SajjadKharrazi avatar May 16 '20 14:05 SajjadKharrazi

Ah. Let me clear it up. Here indates/outdates are generated and visible.

Screen Shot 2020-05-16 at 10 22 25 AM

Here indates/outdates are generated and hidden/invisible.

Screen Shot 2020-05-16 at 10 23 41 AM

Here indates/outdates are not generated at all. And therefore are not visible.

Screen Shot 2020-05-16 at 10 24 42 AM

So there is difference between generating them and hiding them.

With the solution i plan to implement, I will be handeling the visibility (not the generation). Based on the visibility, i can fix how the range looks. The decision to generate/not generate will not be handled by the library. It will be handled by the developers.

patchthecode avatar May 16 '20 14:05 patchthecode

how to config like this

imphila avatar Jun 16 '20 09:06 imphila

Hi @patchthecode @SajjadKharrazi , I face the same problem, any workaround for this situation? 🙏

marcuswu0814 avatar Dec 22 '21 02:12 marcuswu0814