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,12 +142,7 @@ struct ContentView: View {
private var listView: some View {
ScrollView {
ZStack {
Color(.systemBackground).edgesIgnoringSafeArea(.bottom)
.cornerRadius(10)
LazyVStack {
// for reach year
LazyVStack(spacing: 5, pinnedViews: [.sectionHeaders]) {
ForEach(viewModel.grouped.sorted(by: {
$0.key > $1.key
}), id: \.key) { year, months in
@@ -156,32 +151,40 @@ struct ContentView: View {
ForEach(months.sorted(by: {
$0.key > $1.key
}), id: \.key) { month, entries in
Section(header: SectionHeaderView(month: month, year: year)) {
monthListView(month: month, year: year, entries: entries)
}
}
}
}.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!