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

Repeated week between two months with one row calendar #143

Closed
allemattio opened this issue Sep 16, 2016 · 39 comments
Closed

Repeated week between two months with one row calendar #143

allemattio opened this issue Sep 16, 2016 · 39 comments

Comments

@allemattio
Copy link

allemattio commented Sep 16, 2016

Hi @patchthecode
I'm using your calendar in one row mode to have a week view.
I have a strange behaviour and I don't know if it's a bug or a misconfiguration problem.
Here's the thing, suppose that I'm in this situation, with a week between two months:
img_0068

If I scroll left, I would like to see the week from august 22nd to august 28th, but Instead I find another time this:
img_0069

And then, if I scroll again left I find this
img_0070

And scrolling again to the left I finally find the week from august 22nd to august 28th
I use dark gray in the day names for current month names and light gray for other months' day.
It's like there is an extra and useless week between two months.
This happens every time when I'm scrolling from a month to another.

Here is the initialization code:

calendarView.dataSource = self
calendarView.delegate = self
calendarView.registerCellViewXib(fileName: cellXibName)
calendarView.cellInset = CGPoint(x: 0, y: 0)
calendarView.firstDayOfWeek = .Monday
calendarView.reloadData()
calendarView.selectDates([NSDate()])
calendarView.scrollToDate(NSDate(), triggerScrollToDateDelegate: false, animateScroll: false, preferredScrollPosition: .None, completionHandler: nil)

and here is the configureCalendar Method from the delegate

func configureCalendar(calendar: JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate, numberOfRows: Int, calendar: NSCalendar) {
    var numberOfRows = 6
    if let calendarView = calendar as? AddictionJTAppleCalendarView{
        numberOfRows = calendarView.configuredNumberOfRows
    }
    let aCalendar = NSCalendar.currentCalendar()
    return (startDate: CalendarDateManager.sharedInstance.calendarStartDate, endDate: CalendarDateManager.sharedInstance.calendarEndDate, numberOfRows: numberOfRows, calendar: aCalendar)
}

Am I doing something wrong or is a bug?
Thanks in advance, and CONGRATULATIONS, this is by far the best calendar plugin, thank you so much for having developed it!!!!

@patchthecode
Copy link
Owner

Its not a bug. What you are seeing is what every one else is asking for in singlerow mode --> The ability to remove in-dates and out-dates.

If you notice, in 6-row mode, you will see grayed out dates represesting in-dates/out-dates of the previous month and following month.

screen shot 2016-09-07 at 3 17 33 pm

This works well for 6-row mode, but sucks for single row mode. I am working on an upgrade so that you can enable/disable this. I have the explanation here -> #129

currently the code is 90% complete. Unfortunately, I am making the upgrade for this in swift3 first. Afterwards I will support swift2.

@allemattio
Copy link
Author

Ok, I got the point. Thanks so much.
So I can try to use the DynamicGeneration branch or is it the same as master's situation?

@patchthecode
Copy link
Owner

In Dynamic generation, thats where i am working on the code. You can test it out there.
However, some of the functionality is broken as I am still working on it. And I have a bunch of code to commit right now (which i still have locally). Working on the code still :)

@patchthecode
Copy link
Owner

Keep in mind, the code will be in swift3

@allemattio
Copy link
Author

Ok thanks.
Another small question that I can't find in the docs.
Is possible to make the didScrollToDateSegmentStartingWithdate delegate method include the indates and outdates as the border of the segment, via a configuration parameter?
As an example, in the screenshot you posted the delegate would pass Feb 1st as start date and Feb 29th as end date, is possible to make it pass Jan 31St and Mar 12th?
I would also need this for my week view cal. :-)
Thanks a lot in advance

@patchthecode
Copy link
Owner

hmm. That is a good idea. I will include it a an enhancement

@patchthecode
Copy link
Owner

@allemattio by the way, could you let me know the reason for this upgrade?
I just need to know what the function does not already provide, so that I can make the best possible update.

@patchthecode
Copy link
Owner

Also, this is now fixed on master branch. Testing is still in progress.

@allemattio
Copy link
Author

@patchthecode I need that because I have to put under the week calendar a grid with the events for the week, just like the iphone landscape calendar.
So to query for the events I always need to have the borders of the visualized segment.

Thank you so much, what is fixed? the duplicated week or the part about the segment limits?

@patchthecode
Copy link
Owner

What was fixed was the original issue. The in-dates/out-dates feature.

Ok one thing, concerning, the new enhance you want, will it still be necessary since you might be removing the in-dates/out-dates for the single row calendar?

@allemattio
Copy link
Author

allemattio commented Sep 19, 2016

@patchthecode I think that now that won't be necessary.
Since I will have no outdates, the segment should be always of 7 days.
I'm waiting for the push like a happy child! :-)
Thank you so much, really.

@allemattio
Copy link
Author

@patchthecode just a question. This is fixed for Swift 2.2 and will be pushed to master, right?

@patchthecode
Copy link
Owner

Hmm... Its hard for me to both maintain swift3 and swift 2.2..

..... The people here have already requested a swift 2.3 branch, but my work place have already migrated to swift3. As I have mentioned to them in this issue -> #144 , someone will have to create a branch called Swift2.3 and maintain it as it is difficult for me to maintain so many versions.

Will your project be in swfit 2.3/2.2?

@allemattio
Copy link
Author

My project is in swift 2.2, sadly I don't think I'll have time to migrate it. I will try only if I can't workaround this issue

@patchthecode
Copy link
Owner

Hmm. Well just so you know. Migrating is easy with XCode 8. It pretty much almost does every thing for you. But yea, some people will have to create a separate branch as it is a bit much for my plate.

@allemattio
Copy link
Author

On which branch and for which version have you fixed this Issue? 3 or 2.3?it's Also easy to migrate from 2.2 to 3 or only from 2.2 to 2.3?

@patchthecode
Copy link
Owner

patchthecode commented Sep 19, 2016

the branch i am making all the changes on is called DynamicGeneration
And I jumped straight from 2.1 to 3.
Most of the changes I had to make was done by XCode.
What you can do is save the old XCode copy, Download the new one, and try it.

@allemattio
Copy link
Author

I'm trying to bring the changes for the indate/outdate to the 2.2 branch, is it difficult?
I'm trying to find out the part of code that generates the cells, also by following the DynamicGeneration branch code, but I still can't find it.
If it not take too much time to you, can you give me some advice about where I can find that code so I can modify it to exclude/include indates/outdates?

@allemattio
Copy link
Author

allemattio commented Sep 20, 2016

@patchthecode I migrated my code to swift 3 to try the DynamicGeneration branch, I managed to remove indates by setting false in the delegate, and removed the outdates by setting .off when configuring the week calendar

Now,
In the month view of my app, which is a calendar configured with 6 rows, I have a small problem in the didScrollToDateSegmentStartingWithdate method, it returns me always the previous month in the startDate and endDate

In the week view, where I have another calendar configured with 1 row I have this problem, it's like that a day "disappears" now and then, look at these screenshots:

img_0073

Now if I scroll to the right I see:

img_0074

To the right again:
img_0076

Another example, starting from:
img_0077

and scrolling to the left I see:
img_0079

Now and then a day disappears, and the weeks get misaligned.
Also, the start day is not respected. But maybe I can fix this via code.
I'm sorry, it' not easy to explain my problem. It's a bug or a configuration problem?

@patchthecode
Copy link
Owner

patchthecode commented Sep 20, 2016

Its a work in progress.
Thats why, it is not on the main branch yet.
I'm still working on it. Many little bugs here and there.
I should be finished soon though (if my real work doesnt bog me down with work. Since this is my side project)

Thanks for pointing this error out. Will look at it. It's thanks to testers like you I get to see where bugs are and fix them before an official release

@patchthecode
Copy link
Owner

patchthecode commented Sep 20, 2016

1st Day of week is not respected yet, because I have not completed the code there. It originally operated from the fact there is a defined 6x7 grid. But now, setting in-dates/out-dates on/off breaks this rule. So I have to code for that.

In regards to the section being incorrect. It is the same thing. Have to do recalculations there.

The day that is disappearing however, I'll have to fix the other 2 bugs to see if that problem is resolved.

Hey if you find new issues, can you create a new Issue so we can track it there? Since this issue here is for the date-in/out feature. I will flag new issues you create under the DynamicBranch tag

@allemattio
Copy link
Author

@patchthecode thanks, I won't bother you, I'll just peacefully wait for the fixes! :-)
Thanks again for your amazing work

@patchthecode
Copy link
Owner

No worries. In fact, i actually need you guys to tell me where the bugs are.
I just made a push to DynamicGeneration. Can you let me know what else you find?

@allemattio
Copy link
Author

@patchthecode I will try it today and I will let you know. Just for knowledge, the branch Swift3 can be considered stable?

@allemattio
Copy link
Author

allemattio commented Sep 21, 2016

@patchthecode I got this error:
cellCacheSection does not exist.
There was an error in this code section. Please contact the developer on GitHub
assertion failed: file /Pods/JTAppleCalendar/Sources/JTAppleCalendarView.swift, line 334

Also, I noticed that now I have to put the code for the generation of the calendar in the ViewDidAppear method, also I had to fix the frame height of the Cells for the calendar with 1 row

@patchthecode
Copy link
Owner

patchthecode commented Sep 21, 2016

ok.

  1. Firs thing, why do you have to put it int he viewDidAppear method? What is the wrong with viewDidLoad?
  2. Can you show me you configureCalendar function? In order to recreate your issue I have to know what type of calendar you have. All the settings for it. Eg. horizontal? vertical? Number of rows? etc etc etc. Just paste the configureCalendar function code

The frame height problem is known.
That is the next code I have to work on.

@patchthecode
Copy link
Owner

patchthecode commented Sep 21, 2016

Also, let me see your viewDidLoad setup code for the calendar please

@allemattio
Copy link
Author

@patchthecode If I leave it in the viewDidLoad, it is not rendered correctly, it's not visible.

here is the function:

`
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {

    let aCalendar = Foundation.Calendar.current
    if calendar == self.weekCalendarView {
        return ConfigurationParameters(startDate: CalendarDateManager.sharedInstance.calendarStartDate,
                                       endDate: CalendarDateManager.sharedInstance.calendarEndDate,
                                       numberOfRows: 1,
                                       calendar: aCalendar,
                                       generateInDates: false,
                                       generateOutDates: .off,
                                       firstDayOfWeek: .monday)
    }
    else {
        return ConfigurationParameters(startDate: CalendarDateManager.sharedInstance.calendarStartDate,
                                       endDate: CalendarDateManager.sharedInstance.calendarEndDate,
                                       numberOfRows: 6,
                                       calendar: aCalendar,
                                       generateInDates: true,
                                       generateOutDates: .tillEndOfGrid,
                                       firstDayOfWeek: .monday)
    }
}

`

@patchthecode
Copy link
Owner

Ok. Do you have headers registered?

@patchthecode
Copy link
Owner

chat here is slow.. Mind joining me here? -> https://gitter.im/patchthecode/JTAppleCalendar

@allemattio
Copy link
Author

allemattio commented Sep 21, 2016

no, no headers.

here is the code called in the viewDidLoad

        calendarView.addWarrantBorder()

        calendarView.dataSource = self
        calendarView.delegate = self
        calendarView.registerCellViewXib(fileName: cellXibName)
        calendarView.cellInset = CGPoint(x: 0, y: 0)
        calendarView.reloadData()
        calendarView.selectDates([Date()])
        calendarView.scrollToDate(Date(), triggerScrollToDateDelegate: false, animateScroll: false, preferredScrollPosition: .none, completionHandler: nil)

@allemattio
Copy link
Author

sure, joining the chat

@allemattio
Copy link
Author

allemattio commented Sep 21, 2016

@patchthecode find this problem on the DynamicGeneration branch, with a calendar with 6 rows and this config:

ConfigurationParameters(startDate: CalendarDateManager.sharedInstance.calendarStartDate,
                                           endDate: CalendarDateManager.sharedInstance.calendarEndDate,
                                           numberOfRows: 6,
                                           calendar: aCalendar,
                                           generateInDates: true,
                                           generateOutDates: .tillEndOfGrid,
                                           firstDayOfWeek: .monday)

The calendar has only 5 rows
img_0080

@patchthecode
Copy link
Owner

patchthecode commented Sep 21, 2016

Ok one thing, when posting your code here, could you remove lines like these?

CalendarDateManager.sharedInstance.calendarStartDate

Replace it with the actual date string becaue I do not know what is the start date and endDates with those lines.

@patchthecode
Copy link
Owner

Ok. Made some changes.
Try the latest sample app

@allemattio
Copy link
Author

I tried to use the DynamicGeneration branch in my app but freezes on launch.
The example seems instead correct, apart from the scroll that is not paginated.

@patchthecode
Copy link
Owner

The example scroll is set in the viewDidLoad function where I have the code

calendarView.scrollingMode = .nonStopToCell(withResistance: 0.75)

delete that line of code to have you scroll paginated.

You say it freezes your app.
Does it crash or anything?

@patchthecode
Copy link
Owner

Btw, if chat is too slow, you can join me here -> https://gitter.im/patchthecode/JTAppleCalendar

@patchthecode
Copy link
Owner

Also, the names of some functions were changed to make it more standard. I think your app is freezing because since the function names have changed, the library is trying to call functions that does not exist in your app because the delegate function names are now different?

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

No branches or pull requests

2 participants