@@ -27,12 +27,11 @@ import SwiftUI
2727
2828/// A view that represents a grid view.
2929struct ACGridStack < B, F> : View where B: View , F: View {
30-
3130 @EnvironmentObject private var store : ACDataStore
3231
3332 let constant : ACConstant
34- var background : ( ( ACIndexSet ? , ACData ? ) -> B ) ? = nil
35- var foreground : ( ( ACIndexSet ? , ACData ? ) -> F ) ? = nil
33+ var background : ( ( ACIndexSet ? , ACData ? ) -> B ) ?
34+ var foreground : ( ( ACIndexSet ? , ACData ? ) -> F ) ?
3635
3736 @State private var rowSize : CGSize = . zero
3837 @State private var titleWidth : CGFloat = . zero
@@ -43,7 +42,8 @@ struct ACGridStack<B, F>: View where B: View, F: View {
4342 . font ( store. constant. font)
4443 }
4544
46- //MARK: - Properties
45+ // MARK: - Properties
46+
4747 /// Property that displays the grid view.
4848 private var content : some View {
4949 let spacing = store. constant. spacing
@@ -66,14 +66,14 @@ struct ACGridStack<B, F>: View where B: View, F: View {
6666 Rectangle ( )
6767 . fill ( Color . clear)
6868 . frame ( width: rowSize. height, height: rowSize. height)
69- . overlay ( getMonthTitle ( column) , alignment: . leading)
69+ . overlay ( getMonthTitle ( column) , alignment: . leading)
7070 ForEach ( Array ( datas. enumerated ( ) ) , id: \. offset) { row, data in
7171 getRowView ( column: column, row: row, data: data)
7272 }
7373 }
7474 }
7575 }
76- } else {
76+ } else {
7777 VStack ( alignment: . leading, spacing: spacing) {
7878 ZStack ( alignment: . bottom) {
7979 let size = titleWidth
@@ -100,7 +100,7 @@ struct ACGridStack<B, F>: View where B: View, F: View {
100100 }
101101 }
102102
103- //MARK: - Methods
103+ // MARK: - Methods
104104
105105 /// A method that returns a row view.
106106 /// - Parameters:
@@ -110,15 +110,10 @@ struct ACGridStack<B, F>: View where B: View, F: View {
110110 /// - Returns: -
111111 private func getRowView( column: Int , row: Int , data: ACData ) -> some View {
112112 ZStack {
113- if data. date. startOfDay > Date ( ) . startOfDay {
114- background ? ( ACIndexSet ( column: column, row: row) , data)
115- . hidden ( )
116- } else {
117- background ? ( ACIndexSet ( column: column, row: row) , data)
118- foreground ? ( ACIndexSet ( column: column, row: row) , data)
119- . opacity ( getOpacity ( count: data. count) )
120- . takeSize ( $rowSize)
121- }
113+ background ? ( ACIndexSet ( column: column, row: row) , data)
114+ foreground ? ( ACIndexSet ( column: column, row: row) , data)
115+ . opacity ( getOpacity ( count: data. count) )
116+ . takeSize ( $rowSize)
122117 }
123118 }
124119
@@ -135,15 +130,18 @@ struct ACGridStack<B, F>: View where B: View, F: View {
135130 . fixedSize ( horizontal: true , vertical: false )
136131 . takeSize ( $_titleSize)
137132 }
138- } else {
139- Text ( store. datas [ column] [ 0 ] . date. monthTitle)
140- . lineLimit ( 1 )
141- . fixedSize ( horizontal: true , vertical: false )
142- . takeSize ( $_titleSize)
133+ } else {
134+ let date = store. datas [ column] [ 0 ] . date
135+ if date > constant. fromDate && date < constant. toDate {
136+ Text ( date. monthTitle)
137+ . lineLimit ( 1 )
138+ . fixedSize ( horizontal: true , vertical: false )
139+ . takeSize ( $_titleSize)
140+ }
143141 }
144142 }
145143 }
146- . onChange ( of: _titleSize) { newValue in
144+ . onChange ( of: _titleSize) { _ in
147145 titleWidth = max ( titleWidth, _titleSize. width)
148146 }
149147 }
@@ -154,29 +152,29 @@ struct ACGridStack<B, F>: View where B: View, F: View {
154152 private func getOpacity( count: Int ) -> CGFloat {
155153 if count == 0 {
156154 return ACLevel . zero. opacity
157- } else if ACLevel . first. rawValue * store. constant. levelSpacing >= count {
155+ } else if ACLevel . first. rawValue * store. constant. levelSpacing >= count {
158156 return ACLevel . first. opacity
159- } else if ACLevel . second. rawValue * store. constant. levelSpacing >= count {
157+ } else if ACLevel . second. rawValue * store. constant. levelSpacing >= count {
160158 return ACLevel . second. opacity
161- } else if ACLevel . third. rawValue * store. constant. levelSpacing >= count {
159+ } else if ACLevel . third. rawValue * store. constant. levelSpacing >= count {
162160 return ACLevel . third. opacity
163- } else if ACLevel . fourth. rawValue * store. constant. levelSpacing >= count {
161+ } else if ACLevel . fourth. rawValue * store. constant. levelSpacing >= count {
164162 return ACLevel . fourth. opacity
165163 }
166164 return 1.0
167165 }
168166}
169167
170- extension ACGridStack where B : View , F : View {
171-
168+ extension ACGridStack where B: View , F: View {
172169 /// Initializes `ACGridStack`
173170 /// - Parameters:
174171 /// - constant: Settings that define the contribution view.
175172 /// - background: The view that is the background of the row view.
176173 /// - foreground: The view that is the foreground of the row view.
177174 init ( constant: ACConstant ,
178175 @ViewBuilder background: @escaping ( ACIndexSet ? , ACData ? ) -> B ,
179- @ViewBuilder foreground: @escaping ( ACIndexSet ? , ACData ? ) -> F ) {
176+ @ViewBuilder foreground: @escaping ( ACIndexSet ? , ACData ? ) -> F )
177+ {
180178 self . constant = constant
181179 self . background = background
182180 self . foreground = foreground
@@ -185,6 +183,9 @@ extension ACGridStack where B : View, F : View {
185183
186184struct ACGridStack_Previews : PreviewProvider {
187185 static var previews : some View {
188- AxisContribution ( constant: . init( ) , source: [ ] )
186+ AxisContribution (
187+ constant: . init( ) ,
188+ source: [ : ]
189+ )
189190 }
190191}
0 commit comments