From 01fcf70d45edb5a6f18e32382a7c3777f87fd762 Mon Sep 17 00:00:00 2001 From: Trey t Date: Sat, 29 Jan 2022 12:06:01 -0600 Subject: [PATCH] UI on content view listView --- Shared/views/ContentView.swift | 67 ++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/Shared/views/ContentView.swift b/Shared/views/ContentView.swift index b0e9878..fc0e3e6 100644 --- a/Shared/views/ContentView.swift +++ b/Shared/views/ContentView.swift @@ -142,46 +142,49 @@ struct ContentView: View { private var listView: some View { ScrollView { - ZStack { - Color(.systemBackground).edgesIgnoringSafeArea(.bottom) - .cornerRadius(10) - - LazyVStack { - // for reach year - ForEach(viewModel.grouped.sorted(by: { + LazyVStack(spacing: 5, pinnedViews: [.sectionHeaders]) { + ForEach(viewModel.grouped.sorted(by: { + $0.key > $1.key + }), id: \.key) { year, months in + + // for reach month + ForEach(months.sorted(by: { $0.key > $1.key - }), id: \.key) { year, months in - - // for reach month - ForEach(months.sorted(by: { - $0.key > $1.key - }), id: \.key) { month, entries in + }), id: \.key) { month, entries in + Section(header: SectionHeaderView(month: month, year: year)) { monthListView(month: month, year: year, entries: entries) } } } - GeometryReader { proxy in + }.background( + GeometryReader { proxy in let offset = proxy.frame(in: .named("scroll")).minY Color.clear.preference(key: ViewOffsetKey.self, value: offset) } - } + ) } + .background( + Color(UIColor.systemBackground) + ) .coordinateSpace(name: "scroll") .onPreferenceChange(ViewOffsetKey.self) { value in 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 { - Section(header: - HStack{ - Text(monthName(fromMonthInt: month)) - .font(.title2) - .foregroundColor(Color(UIColor.label)) - Text(String(year)) - .font(.title2) - .foregroundColor(Color(UIColor.label)) - }) { + VStack { // for reach all entries ForEach(entries.sorted(by: { return $0.forDate! > $1.forDate! @@ -192,16 +195,16 @@ struct ContentView: View { showUpdateEntryAlert = true }) } -// if deleteEnabled { -// .onDelete(perform: { offsets in -// withAnimation { -// viewModel.delete(offsets: offsets, inMonth: month, inYear: year) -// } -// }) -// } + // if deleteEnabled { + // .onDelete(perform: { offsets in + // withAnimation { + // viewModel.delete(offsets: offsets, inMonth: month, inYear: year) + // } + // }) + // } } } - + private func entryListView(entry: MoodEntry) -> some View { HStack { entry.mood.icon