Skip to content

Commit

Permalink
A sketch of replacing the calendar after DayView initializing
Browse files Browse the repository at this point in the history
  • Loading branch information
RareScrap committed Dec 18, 2020
1 parent e6c8c8a commit b4fa5b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
21 changes: 18 additions & 3 deletions Source/DayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion Source/Header/DayHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion Source/Timeline/TimelinePagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4fa5b9

Please sign in to comment.