diff --git a/Source/DayView.swift b/Source/DayView.swift index 9d71f8e9..f5d4e9ee 100644 --- a/Source/DayView.swift +++ b/Source/DayView.swift @@ -50,8 +50,8 @@ public final class DayView: UIView, TimelinePagerViewDelegate { } } - public let dayHeaderView: DayHeaderView - public let timelinePagerView: TimelinePagerView + public private(set) var dayHeaderView: DayHeaderView + public private(set) var timelinePagerView: TimelinePagerView public var state: DayViewState? { didSet { @@ -60,7 +60,22 @@ public final class DayView: UIView, TimelinePagerViewDelegate { } } - public var calendar: Calendar = Calendar.autoupdatingCurrent + public var calendar: Calendar = Calendar.autoupdatingCurrent { + didSet { + // TODO: Should we observe calendar in state rather then change it manualy? + dayHeaderView.calendar = self.calendar + timelinePagerView.calendar = self.calendar + + let date = self.state?.selectedDate ?? Date() + let newState = DayViewState(date: date, calendar: calendar) + newState.move(to: date) + state = newState + + // TODO: Shound we redraw dayView and its subvies? Or we should do this when calendar in state was changed? +// setNeedsDisplay() +// self.subviews.forEach { $0.setNeedsDisplay() } + } + } private var style = CalendarStyle() diff --git a/Source/Header/DayHeaderView.swift b/Source/Header/DayHeaderView.swift index bb130d98..ece91cd9 100644 --- a/Source/Header/DayHeaderView.swift +++ b/Source/Header/DayHeaderView.swift @@ -4,7 +4,7 @@ import DateToolsSwift public final class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, UIPageViewControllerDataSource, UIPageViewControllerDelegate { public private(set) var daysInWeek = 7 - public let calendar: Calendar + public var calendar: Calendar private var style = DayHeaderStyle() private var currentSizeClass = UIUserInterfaceSizeClass.compact diff --git a/Source/Timeline/TimelinePagerView.swift b/Source/Timeline/TimelinePagerView.swift index f0a68d92..0cf9efb8 100644 --- a/Source/Timeline/TimelinePagerView.swift +++ b/Source/Timeline/TimelinePagerView.swift @@ -20,7 +20,14 @@ public final class TimelinePagerView: UIView, UIGestureRecognizerDelegate, UIScr public weak var dataSource: EventDataSource? public weak var delegate: TimelinePagerViewDelegate? - public private(set) var calendar: Calendar = Calendar.autoupdatingCurrent + public var calendar: Calendar = Calendar.autoupdatingCurrent { + didSet { + pagingViewController.viewControllers?.forEach { + let vc = $0 as! TimelineContainerController + vc.timeline.calendar = calendar + } + } + } public var timelineScrollOffset: CGPoint { // Any view is fine as they are all synchronized