UI on content view listView

This commit is contained in:
Trey t
2022-01-29 12:06:01 -06:00
parent 254c3b12d8
commit 01fcf70d45

View File

@@ -142,46 +142,49 @@ struct ContentView: View {
private var listView: some View { private var listView: some View {
ScrollView { ScrollView {
ZStack { LazyVStack(spacing: 5, pinnedViews: [.sectionHeaders]) {
Color(.systemBackground).edgesIgnoringSafeArea(.bottom) ForEach(viewModel.grouped.sorted(by: {
.cornerRadius(10) $0.key > $1.key
}), id: \.key) { year, months in
LazyVStack { // for reach month
// for reach year ForEach(months.sorted(by: {
ForEach(viewModel.grouped.sorted(by: {
$0.key > $1.key $0.key > $1.key
}), id: \.key) { year, months in }), id: \.key) { month, entries in
Section(header: SectionHeaderView(month: month, year: year)) {
// for reach month
ForEach(months.sorted(by: {
$0.key > $1.key
}), id: \.key) { month, entries in
monthListView(month: month, year: year, entries: entries) monthListView(month: month, year: year, entries: entries)
} }
} }
} }
GeometryReader { proxy in }.background(
GeometryReader { proxy in
let offset = proxy.frame(in: .named("scroll")).minY let offset = proxy.frame(in: .named("scroll")).minY
Color.clear.preference(key: ViewOffsetKey.self, value: offset) Color.clear.preference(key: ViewOffsetKey.self, value: offset)
} }
} )
} }
.background(
Color(UIColor.systemBackground)
)
.coordinateSpace(name: "scroll") .coordinateSpace(name: "scroll")
.onPreferenceChange(ViewOffsetKey.self) { value in .onPreferenceChange(ViewOffsetKey.self) { value in
calculateHeight(minHeight: 88, maxHeight: 180, yOffset: value) calculateHeight(minHeight: 88, maxHeight: 180, yOffset: value)
} }
} }
private func SectionHeaderView(month: Int, year: Int) -> some View {
Text("\(monthName(fromMonthInt: month)) \(String(year))")
.font(.title)
.foregroundColor(Color(UIColor.label))
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(
Color(UIColor.systemBackground)
)
}
private func monthListView(month: Int, year: Int, entries: [MoodEntry]) -> some View { private func monthListView(month: Int, year: Int, entries: [MoodEntry]) -> some View {
Section(header: VStack {
HStack{
Text(monthName(fromMonthInt: month))
.font(.title2)
.foregroundColor(Color(UIColor.label))
Text(String(year))
.font(.title2)
.foregroundColor(Color(UIColor.label))
}) {
// for reach all entries // for reach all entries
ForEach(entries.sorted(by: { ForEach(entries.sorted(by: {
return $0.forDate! > $1.forDate! return $0.forDate! > $1.forDate!
@@ -192,13 +195,13 @@ struct ContentView: View {
showUpdateEntryAlert = true showUpdateEntryAlert = true
}) })
} }
// if deleteEnabled { // if deleteEnabled {
// .onDelete(perform: { offsets in // .onDelete(perform: { offsets in
// withAnimation { // withAnimation {
// viewModel.delete(offsets: offsets, inMonth: month, inYear: year) // viewModel.delete(offsets: offsets, inMonth: month, inYear: year)
// } // }
// }) // })
// } // }
} }
} }