UI on content view listView
This commit is contained in:
@@ -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 year
|
// for reach month
|
||||||
ForEach(viewModel.grouped.sorted(by: {
|
ForEach(months.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,16 +195,16 @@ 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)
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func entryListView(entry: MoodEntry) -> some View {
|
private func entryListView(entry: MoodEntry) -> some View {
|
||||||
HStack {
|
HStack {
|
||||||
entry.mood.icon
|
entry.mood.icon
|
||||||
|
|||||||
Reference in New Issue
Block a user