Reputation: 41
I use the library RKmanager to show a calendar with a dateRangePicker. But i can't get an event if the parameter rkManager.endDate is set from nil to a date.
I want activate and deactivate an addButton for the dateRange if a range is set.
The Object from i want to get the trigger if changes:
class RKManager : ObservableObject {
@Published var startDate: Date! = nil
@Published var endDate: Date! = nil
Now my View:
import SwiftUI
struct DateRangeView: View {
@State var rkManager = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 1)
@State private var addNewDateRangeIsDisabled: Bool = true
var body: some View {
VStack(alignment: .leading) {
RKViewController(isPresented: .constant(false), rkManager: self.rkManager )
Button(action: {
if self.rkManager.endDate != nil
&& self.rkManager.startDate != nil
{
self.addNewDateRange()
}
}) {
HStack {
Image(systemName: "plus.circle.fill")
.resizable()
.frame(width: 20, height: 20)
Text("Add new DateRange")
}
}
.padding()
.disabled(self.rkManager.endDate == nil) // --> here i want to change if the value changed
}.navigationBarTitle("TestRoomName", displayMode: .inline)
}
Upvotes: 0
Views: 1051
Reputation: 257779
A ObservableObject
should be represented in view by ObservedObject
dynamic property wrapper so view would be updated on published property change.
Here is fix
struct DateRangeView: View {
@ObservedObject var rkManager = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: 1)
// ... other code
Upvotes: 1