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 {
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