Onboarding screens
OnboardingData object that will hold onboarding answers
This commit is contained in:
@@ -11,12 +11,15 @@ import Charts
|
||||
|
||||
struct ContentView: View {
|
||||
@Environment(\.managedObjectContext) private var viewContext
|
||||
|
||||
@State private var needsOnboarding: Bool = true
|
||||
|
||||
@State private var showingSheet = false
|
||||
@State private var showTodayInput = true
|
||||
|
||||
@ObservedObject var viewModel = ContentModeViewModel()
|
||||
|
||||
@AppStorage("savedOnboardingData") private var savedOnboardingData = OnboardingData()
|
||||
|
||||
init(){
|
||||
UITabBar.appearance().backgroundColor = UIColor.systemBackground
|
||||
}
|
||||
@@ -37,7 +40,15 @@ struct ContentView: View {
|
||||
.tabItem {
|
||||
Label("Stats", systemImage: "chart.line.uptrend.xyaxis")
|
||||
}
|
||||
}
|
||||
}.sheet(isPresented: $needsOnboarding, onDismiss: {
|
||||
|
||||
}, content: {
|
||||
OnboardingMain(onboardingData: savedOnboardingData,
|
||||
completionClosure: { onboardingData in
|
||||
needsOnboarding = false
|
||||
savedOnboardingData = onboardingData
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
private var settingsButtonView: some View {
|
||||
|
||||
@@ -11,15 +11,9 @@ struct SettingsView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
let editedDataClosure: (() -> Void)
|
||||
@State private var showOnboarding = false
|
||||
|
||||
@AppStorage("notificationDate") private var notificationDate = Date() {
|
||||
didSet {
|
||||
if self.showReminder {
|
||||
LocalNotification.scheduleReminder(atTime: self.notificationDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AppStorage("savedOnboardingData") private var savedOnboardingData = OnboardingData()
|
||||
@AppStorage("showReminder") private var showReminder: Bool = false
|
||||
|
||||
var body: some View {
|
||||
@@ -29,15 +23,21 @@ struct SettingsView: View {
|
||||
VStack {
|
||||
closeButtonView
|
||||
.padding()
|
||||
notificationCell
|
||||
randomShitCell
|
||||
addTestDataCell
|
||||
clearDB
|
||||
whyBackgroundMode
|
||||
changeIcon
|
||||
showOnboardingButton
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}.sheet(isPresented: $showOnboarding) {
|
||||
OnboardingMain(onboardingData: savedOnboardingData,
|
||||
completionClosure: { onboardingData in
|
||||
showOnboarding = false
|
||||
savedOnboardingData = onboardingData
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,27 +54,6 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var notificationCell: some View {
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
VStack {
|
||||
Toggle("Would you like to be reminded?", isOn: $showReminder)
|
||||
.onChange(of: showReminder, perform: { value in
|
||||
self.maybeNotificaiotns(areEnabled: value)
|
||||
})
|
||||
.padding()
|
||||
DatePicker("", selection: $notificationDate, displayedComponents: .hourAndMinute)
|
||||
.onChange(of: notificationDate, perform: { value in
|
||||
self.updateNotificationTimes(toDate: value)
|
||||
})
|
||||
.disabled(showReminder == false)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
}
|
||||
|
||||
private var randomShitCell: some View {
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
@@ -179,21 +158,18 @@ struct SettingsView: View {
|
||||
LocalNotification.scheduleReminder(atTime: date)
|
||||
}
|
||||
|
||||
private func maybeNotificaiotns(areEnabled: Bool) {
|
||||
if areEnabled {
|
||||
LocalNotification.testIfEnabled(completion: { result in
|
||||
switch result{
|
||||
case .success(_):
|
||||
LocalNotification.scheduleReminder(atTime: self.notificationDate)
|
||||
case .failure(let error):
|
||||
print(error)
|
||||
// show error
|
||||
break
|
||||
}
|
||||
private var showOnboardingButton: some View {
|
||||
ZStack {
|
||||
Color(UIColor.systemBackground)
|
||||
Button(action: {
|
||||
showOnboarding.toggle()
|
||||
}, label: {
|
||||
Text("Show Onboarding")
|
||||
})
|
||||
} else {
|
||||
LocalNotification.removeNotificaiton()
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user