-
Notifications
You must be signed in to change notification settings - Fork 52
/
MonthYearSideBar.swift
88 lines (67 loc) · 2.58 KB
/
MonthYearSideBar.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Kevin Li - 1:39 PM - 6/1/20
import SwiftUI
fileprivate let angle: Angle = .degrees(-90)
fileprivate let offsetLowerBound: CGFloat = Constants.List.listTopPadding
struct MonthYearSideBar: View {
@Environment(\.appTheme) private var appTheme: AppTheme
@State private var size1: CGSize = .zero
@State private var size2: CGSize = .zero
@ObservedObject var state: MonthYearSideBarState
private var offset1: CGFloat {
state.monthYear1Offset - (size1.height / 2) + Constants.List.listTopPadding
}
private var offset2: CGFloat {
state.monthYear2Offset - (size2.height / 2) + Constants.List.listTopPadding
}
var body: some View {
ZStack(alignment: .top) {
monthYear1Text
.rotated(angle)
.captureSize(in: $size1)
.offset(y: offset1)
monthYear2Text
.rotated(angle)
.captureSize(in: $size2)
.offset(y: offset2)
}
.frame(width: Constants.List.monthYearWidth)
}
}
private extension MonthYearSideBar {
var monthYear1Text: some View {
Text(monthYear1FullMonthWithYear.uppercased())
.tracking(10)
.foregroundColor(isMonthYear1SameMonthAndYearAsToday ? appTheme.primary : nil)
.font(.caption)
.fontWeight(.semibold)
.lineLimit(1)
.padding(.vertical, 8)
.transition(.opacity)
}
var isMonthYear1SameMonthAndYearAsToday: Bool {
appCalendar.isDate(state.monthYear1Component.date, equalTo: Date(), toGranularity: .month) &&
appCalendar.isDate(state.monthYear1Component.date, equalTo: Date(), toGranularity: .year)
}
var monthYear1FullMonthWithYear: String {
state.monthYear1Component.date.fullMonthWithYear
}
}
private extension MonthYearSideBar {
var monthYear2Text: some View {
Text(monthYear2FullMonthWithYear.uppercased())
.tracking(10)
.foregroundColor(isMonthYear2SameMonthAndYearAsToday ? appTheme.primary : nil)
.font(.caption)
.fontWeight(.semibold)
.lineLimit(1)
.padding(.vertical, 8)
.transition(.opacity)
}
var isMonthYear2SameMonthAndYearAsToday: Bool {
appCalendar.isDate(state.monthYear2Component.date, equalTo: Date(), toGranularity: .month) &&
appCalendar.isDate(state.monthYear2Component.date, equalTo: Date(), toGranularity: .year)
}
var monthYear2FullMonthWithYear: String {
state.monthYear2Component.date.fullMonthWithYear
}
}