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

Updates to RKCalendar #4

Open
workingDog opened this issue Aug 26, 2019 · 10 comments
Open

Updates to RKCalendar #4

workingDog opened this issue Aug 26, 2019 · 10 comments

Comments

@workingDog
Copy link
Contributor

RaffiKian, great project.

I've made some modifications to your code to include xCode 11 beta 6, multi-dates selection, disabled dates option, etc... If you are interested in these I'd be happy to do another pull request. If not let me know.

https://github.com/workingDog/RKCalendar

@RaffiKian
Copy link
Owner

Thank you for your contribution, amazing additions. I will contact you by email.

@amuresia
Copy link

amuresia commented Oct 19, 2019

Hi @workingDog,

Thanks for working on this and sharing it with us! The disabled options functionality that you've added is something that I am particularly interested in integrating in my app! However I noticed a small problem when the RKCalendar is not part of the ContentsView which in my Stage Delegate is the root view.

Unfortunately the disabled dates don't work if I try to create a new TestView with the RKCalendar, and then include the TestView in ContentsView

import SwiftUI

struct TestView : View {
    
    @State var deselectedIsPresented = false
        
    var rkManager4 = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 1)
    
    var body: some View {
        VStack (spacing: 25) {
            
            Button(action: { self.deselectedIsPresented.toggle() }) {
                Text("Example 4 - Disabled Dates Setting").foregroundColor(.blue)
            }
            .sheet(isPresented: self.$deselectedIsPresented, content: {
                RKViewController(isPresented: self.$deselectedIsPresented, rkManager: self.rkManager4)})
            datesView(dates: self.rkManager4.disabledDates)
            
        }
        .onAppear(perform: startUp)
        .navigationViewStyle(StackNavigationViewStyle())
    }
    
    func datesView(dates: [Date]) -> some View {
        ScrollView (.horizontal) {
            HStack {
                ForEach(dates, id: \.self) { date in
                    Text(self.getTextFromDate(date: date))
                }
            }
        }.padding(.horizontal, 15)
    }
 
    func startUp() {        
        // example of pre-setting disabled dates
        let testOffDates = [
            Date().addingTimeInterval(60*60*24*4),
            Date().addingTimeInterval(60*60*24*5),
            Date().addingTimeInterval(60*60*24*7)]
        rkManager4.disabledDates.append(contentsOf: testOffDates)
    }
    
    func getTextFromDate(date: Date!) -> String {
        let formatter = DateFormatter()
        formatter.locale = .current
        formatter.dateFormat = "EEEE, MMMM d, yyyy"
        return date == nil ? "" : formatter.string(from: date)
    }

}
import SwiftUI
import Combine

struct ContentView: View {
    var body: some View {
        VStack {
                TestView()
        }
    }
}

Any thought on how to fix or work around this issue? Thank you very much in advance!

@workingDog
Copy link
Contributor Author

workingDog commented Oct 19, 2019 via email

@amuresia
Copy link

Thank you! I should have mentioned that I'm running it on Xcode Beta 7 Version 11.2 beta (11B41). On what version is it working for you? I can downgrade and test that if you'd like.

@workingDog
Copy link
Contributor Author

workingDog commented Oct 19, 2019 via email

@workingDog
Copy link
Contributor Author

workingDog commented Oct 19, 2019 via email

@FireNeuron
Copy link

Hi Raffi,

Thanks for creating such a simple to use calendar.
I am new to SwiftUI. I have encountered a small problem when implementing your calendar: if I set the calendar to show two years of dates, i.e. maximumDate: Date().addingTimeInterval(606024*730). Xcode gives me a warning in the console whenever I tap on a date:
ForEach<Range, Int, RKMonth> count (25) != its initial count (19). ForEach(_:content:) should only be used for constant data. Instead conform data to Identifiable or use ForEach(_:id:content:) and provide an explicit id!

Could you help with this?
Many thanks

@workingDog
Copy link
Contributor Author

@FireNeuron,

I could not replicate your problem. Could you track down where exactly this warning comes from. Maybe the warning has the name of the class or struct. Could you share that.

@FireNeuron
Copy link

Thanks for your quick reply. I figured it out. Turns out List() doesn't load all of its content in once (like LazyVStack). So, the ForEach() in the List of RKViewController.swift only populated 19 rows (months) initially in my case rather than 25 (for two years). The smaller the device screen, the less rows the List() would load.

I changed the List() to:
ScrollView (.vertical) {
VStack{}
}
The problem went away.

Many thanks any way!

@workingDog
Copy link
Contributor Author

I'm glad you worked it out. You maybe be interested in my fork of RKCalendar, with a number of additional features at:

https://github.com/workingDog/RKCalendar

I'd be interested to see if you get the same issue with it.

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