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

Calendar does not start on current date when including dates from past #9

Open
simbo64 opened this issue Dec 25, 2019 · 14 comments
Open

Comments

@simbo64
Copy link

simbo64 commented Dec 25, 2019

I suspect this is something to do with Lists in SwiftUI, but if you give the start date to the RKManager as a date in the past, the calendar starts at that date. I suspect most users desired behaviour would be the calendar always starts on the current date and then the user scrolls up or down to the section they want?

@nikae
Copy link

nikae commented Mar 9, 2020

Does anyone have a solution to this issue?

@workingDog
Copy link
Contributor

I have a possible solution in my experimental branch: exp1
https://github.com/workingDog/RKCalendar
until SwiftUI implements it.
let me know if it works.
(note it does not yet work for weekly view)

@nikae
Copy link

nikae commented Mar 11, 2020

It works great.
Thank you!

@gooftroop1330
Copy link

what files were edited and/or needed in order to achieve this?

@workingDog
Copy link
Contributor

Note somehow this experimental code ended up in the master branch.
In the master branch,

I added ScrollableView in RKScroll,

and modified RKViewController as follows:

added

@State private var contentOffset = CGPoint.zero   line: 19

todayVScrollPos() and todayHScrollPos()    lines: 166 and 176

added at lines 100 for verticalView, and 119 for horizontalView:

.onAppear(perform: { self.contentOffset = self.todayHScrollPos() }) 

Let me know if this works.

@workingDog
Copy link
Contributor

I forgot the important bit, I replaced ScrollView(.vertical) with ScrollableView(self.$contentOffset)
at lines: 87 and 105

@gooftroop1330
Copy link

@workingDog forgive me. I am new to swift. I am using the original RKManager files in the Raffikian repository. If I add those few lines to those files from their repository will it still work? Or do I need to download your files in order to achieve this

@workingDog
Copy link
Contributor

You need to download my repo. I thought you were asking about what I did to implement this feature in my repo. My answer should have mentioned this, sorry.

https://github.com/workingDog/RKCalendar

Just download the master branch.

@gooftroop1330
Copy link

okay last issue and I promise im done lol. I've got it working! however, your's uses a done button. is there a way to revert that back to onClick of a date to close the calendar?

@workingDog
Copy link
Contributor

no problems ask away.

First the done button is really for when you use it on macos. To remove it
comment the lines (25 to 30) with the "Button(action: onDone) ..." in RKViewController.

Then to close when clicking on a date, in RKMonth --> func dateTapped(date: Date)
add "self.isPresented = false" at the end of the cases you want.

Let me know if this works.

@gooftroop1330
Copy link

@workingDog I've been playing with this problem for several days now. So the app I am working on populates a database from Jan 1, 2020 -> 400 days in the future. Through testing, I know those days are populated. When I launch the calendar to select a day, it starts at the current day, but does not let me see into the past and it also has me limited to 11 months into the future. If I select, say July 1, 2020, when I relaunch the calendar I can only see from July 1 to the previous end date. Any ideas?

@gooftroop1330
Copy link

@workingDog after rebuilding, I have the correct date range, but now going into the calendar doesn't focus on the selected date. it only goes to the current date 4/6/2020

@workingDog
Copy link
Contributor

I'm glad you got the range working. As for the focus date, the current behaviour is to start at the current date. I'll investigate on starting on the selected date.

In the mean time you could try this:

replace Date() with rkManager.selectedDate
in RKViewController -> todayVScrollPos() lines 167 and 168
and also in RKViewController -> todayHScrollPos() lines 177 and 178

There maybe some unexpected side effects.

@gooftroop1330
Copy link

@workingDog I solved this. Adding rkmManager.selectedDate where you said to works. You just have to assure that rkManager.selected is instantiated before called to RKViewController for the first time. Thank you so much!

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

4 participants