build out enable delete option but cant use b/c list view is not a list

re-arrange the content view
This commit is contained in:
Trey t
2022-01-29 11:22:59 -06:00
parent 423be2a30c
commit 2aa59a084a
4 changed files with 89 additions and 70 deletions

View File

@@ -12,6 +12,7 @@ class UserDefaultsStore {
case savedOnboardingData
case needsOnboarding
case useCloudKit
case deleteEnable
}
static func getOnboarding() -> OnboardingData {

View File

@@ -12,6 +12,7 @@ import Charts
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
@State private var showingSheet = false
@State private var showTodayInput = true
@@ -155,6 +156,23 @@ struct ContentView: View {
ForEach(months.sorted(by: {
$0.key > $1.key
}), id: \.key) { month, entries in
monthListView(month: month, year: year, entries: entries)
}
}
}
GeometryReader { proxy in
let offset = proxy.frame(in: .named("scroll")).minY
Color.clear.preference(key: ViewOffsetKey.self, value: offset)
}
}
}
.coordinateSpace(name: "scroll")
.onPreferenceChange(ViewOffsetKey.self) { value in
calculateHeight(minHeight: 88, maxHeight: 180, yOffset: value)
}
}
private func monthListView(month: Int, year: Int, entries: [MoodEntry]) -> some View {
Section(header:
HStack{
Text(monthName(fromMonthInt: month))
@@ -173,24 +191,14 @@ struct ContentView: View {
selectedEntry = entry
showUpdateEntryAlert = true
})
}.onDelete(perform: { offsets in
withAnimation {
viewModel.delete(offsets: offsets, inMonth: month, inYear: year)
}
})
}
}
}
}
GeometryReader { proxy in
let offset = proxy.frame(in: .named("scroll")).minY
Color.clear.preference(key: ViewOffsetKey.self, value: offset)
}
}
}
.coordinateSpace(name: "scroll")
.onPreferenceChange(ViewOffsetKey.self) { value in
calculateHeight(minHeight: 88, maxHeight: 180, yOffset: value)
// if deleteEnabled {
// .onDelete(perform: { offsets in
// withAnimation {
// viewModel.delete(offsets: offsets, inMonth: month, inYear: year)
// }
// })
// }
}
}
@@ -274,13 +282,8 @@ struct ContentView: View {
}
private var mainView: some View {
ZStack {
BGView().equatable()
VStack {
settingsButtonView
.padding(.top, 50)
if viewModel.hasNoData {
Spacer()
emptyView
@@ -299,15 +302,14 @@ struct ContentView: View {
Spacer()
}
.opacity(1 - headerOpacity)
}
.frame(height: headerHeight + 20)
listView
.padding([.leading, .trailing])
.padding(.top, headerHeight+10)
.padding(.bottom, 60)
}
}
}
}
}.background(
BGView().equatable()
)
}
}

View File

@@ -21,12 +21,14 @@ struct SettingsView: View {
@ObservedObject var syncMonitor = SyncMonitor.shared
@AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue, store: GroupUserDefaults.groupDefaults) private var useCloudKit = false
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
var body: some View {
ZStack {
Color(UIColor.secondarySystemBackground)
VStack {
Group {
closeButtonView
.padding()
cloudKitEnable
@@ -40,7 +42,7 @@ struct SettingsView: View {
if useCloudKit {
cloudKitStatus
}
}
Spacer()
}
.padding()
@@ -230,6 +232,19 @@ struct SettingsView: View {
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
}
private var canDelete: some View {
ZStack {
Color(UIColor.systemBackground)
VStack {
Toggle(String(localized: "settings_use_delete_enable"),
isOn: $deleteEnabled)
.padding()
}
}
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
}
}
struct SettingsView_Previews: PreviewProvider {

View File

@@ -54,6 +54,7 @@
"settings_view_show_onboarding" = "Show onboarding";
"settings_use_cloudkit_title" = "Use CloudKit";
"settings_use_cloudkit_body" = "CloudKit fucking sucks";
"settings_use_delete_enable" = "Allow deletion of entry";
"mood_value_great" = "Great";
"mood_value_good" = "Good";