Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrollToDate() scrolls to the OutDates of the previous month (Edge case) #1239

Closed
idavidgeo opened this issue Mar 27, 2020 · 11 comments
Closed

Comments

@idavidgeo
Copy link

idavidgeo commented Mar 27, 2020

(Required) Version Number: 8.0.2

Description

scrollToDate() scrolls to the OutDates of the previous month if they exist.
E.G. April 4th 2020 also lies as the last (OutDates) item on the calendar of March. So it scrolls to march instead.
Conversely, scrollToDate(date_object) - where date_object is April 5th 2020, would result in the correct month placement. Because April 5th does not lie on the OutDates of march.

Steps To Reproduce

  1. Have vertical scrolling
  2. Scrolling mode = .stopAtEachCalendarFrame.
  3. Have Outdates, InDates enables
  4. call scrollToDate(date_object) // Where date_object is April 4th 2020

Expected Behavior

Expecting to land on the April month, but it landed on March

Additional Context

A very nasty workaround is by making a generic Date() object using DateComponents() and setting the date to 15 and copying the rest. I don't really care about the specific date, I just need the correct/current month.

It looks like this:

    var scrollToMonth = DateComponents()
    scrollToMonth.day = 15
    scrollToMonth.month = calendar.component(.month, from: selectedDay)
    scrollToMonth.year = calendar.component(.year, from: selectedDay)

    calendarView.scrollToDate(Calendar.current.date(from: scrollToMonth)!)

Also, why not have something like scrollToMonth()?

I also checkout the scrollToMonth definition, but wasn't able to understand many of it :/
This is my first app.

Nonetheless, wonderful framework 👍

Thank you for time spent developing and maintaining.

@patchthecode
Copy link
Owner

If you have a sample app reproducing this, it can help.

@idavidgeo
Copy link
Author

idavidgeo commented Mar 28, 2020

The project is pretty large, I don't want to share the whole thing.

I also have a little issue where the function "didSelectDate" doesn't get called on cell touches.
I have the whole class in the file attached. As for the storyboard, I don't have any touch or gestures recognizers.

"didSelectDate" is on line 128
[CalendarViewController.swift.zip]

@patchthecode
Copy link
Owner

I understand you cant share the whole thing.
What i meant was, create an empty sample project with the bare minimum code that reproduces this problem.

Crashes (or bugs like crashes) or other obvious errors can be solved by me easier than the error you currently have. Anything can cause it, from xibs, to code. Therefore a sample app can help me see exactly what the problem is.

If i just have the file, then i will have to create a project around it which might behave differently than your current one;

@idavidgeo
Copy link
Author

I understand, I'll try to do that ASAP.

@patchthecode
Copy link
Owner

Ok i just awoke.
taking a look.

BTW, scroll to date should never scroll to outDates. It should always scroll to the correct date stated by you.

Checking this out now.

@idavidgeo
Copy link
Author

idavidgeo commented Mar 28, 2020

Update: didSelectDate function issue was fixed by going to the Size Inspector on DateCell and changing the Collection View Cell Size from Automatic to Custom, and un-checking Content View

This also fixed all the console errors regarding constraints after the calendar renders.

Should I open a separate issue for this and then close it?

@patchthecode
Copy link
Owner

no, its ok.
I dont know what you did to fix the non-clicking issue (i am not too familiar with xibs).
Therefore, what i did was create a new Xib with all the default settings and the constraint errors went away. Once the errors went away. Clicking started working again.
This let me think the tapping issue was related to the constraint errors.

As for the scroll to date, it works as expected on my end.
Therefore, let me ask you this, do you live in the West? or the East part of the world.
I suspected it might be a time zone issue -> #252

@idavidgeo
Copy link
Author

idavidgeo commented Mar 30, 2020

Im on the US West Coast.

So even without modifying anything in the project it scrolled to the correct month?

Also, even after setting generateOutDates: .none is still scrolls to the month prior, even if the date cells are not showing at all.

EDIT: I don't think this is a timezone issue, because its' error margin lies across 4 days in this case (April-March). That is: scrolling to any of the dates that also lie as outDates of the previous month, will scroll to the previous month.

@idavidgeo
Copy link
Author

Ok you were probably right about that one, I don't know exactly what I did, but I messed around come Calendar() settings, and was trying to make things more consistent and it work now. Cheers.

@patchthecode
Copy link
Owner

awesome

@DrD00der
Copy link

DrD00der commented Feb 3, 2021

I have the same bug in my code. Calendar is scrolling to prior month due to outDates appearing.

I made a workaround by changing the scrollToDate to be the middle of the current month instead of using today's date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants