Added settings page, doesn't save the values yet
This commit is contained in:
		
							
								
								
									
										70
									
								
								SleepDebt/SettingsView.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								SleepDebt/SettingsView.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | |||||||
|  | // | ||||||
|  | //  SettingsView.swift | ||||||
|  | //  SleepDebt | ||||||
|  | // | ||||||
|  | //  Created by Oliver Hnát on 06.01.2024. | ||||||
|  | // | ||||||
|  |  | ||||||
|  | import SwiftUI | ||||||
|  |  | ||||||
|  | struct SettingsView: View { | ||||||
|  |     @State var sleepDebtPeriod = 30 | ||||||
|  |     @State var repaymentPeriod = 7 | ||||||
|  |     @FocusState private var focusItem: Bool | ||||||
|  |     private var repaymentString = "Repayment period (days)" | ||||||
|  |     private var sleepDebtString = "Sleep debt period (days)" | ||||||
|  |     let formatter: NumberFormatter = { | ||||||
|  |         let formatter = NumberFormatter() | ||||||
|  |         formatter.numberStyle = .decimal | ||||||
|  |         return formatter | ||||||
|  |     }() | ||||||
|  |      | ||||||
|  |     var body: some View { | ||||||
|  |         NavigationStack { | ||||||
|  |              | ||||||
|  |             List { | ||||||
|  |                 Section { | ||||||
|  |                     LabeledContent { | ||||||
|  |                         TextField("", value: $sleepDebtPeriod, formatter: formatter) | ||||||
|  |                             .keyboardType(.numberPad) | ||||||
|  |                             .onSubmit { | ||||||
|  |                                 focusItem = false | ||||||
|  |                             } | ||||||
|  |                             .focused($focusItem) | ||||||
|  |                             .multilineTextAlignment(.trailing) | ||||||
|  |                             .foregroundStyle(.blue) | ||||||
|  |                     } label: { | ||||||
|  |                         Text(sleepDebtString) | ||||||
|  |                             .fixedSize() | ||||||
|  |                     } | ||||||
|  |                      | ||||||
|  |                     .lineLimit(1) | ||||||
|  |                     LabeledContent { | ||||||
|  |                         TextField("", value: $repaymentPeriod, formatter: formatter) | ||||||
|  |                             .keyboardType(.numberPad) | ||||||
|  |                             .onSubmit { | ||||||
|  |                                 focusItem = false | ||||||
|  |                             } | ||||||
|  |                             .focused($focusItem) | ||||||
|  |                             .multilineTextAlignment(.trailing) | ||||||
|  |                             .foregroundStyle(.blue) | ||||||
|  |                          | ||||||
|  |                     } label: { | ||||||
|  |                         Text(repaymentString) | ||||||
|  |                             .fixedSize() | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             .onTapGesture{ | ||||||
|  |                 focusItem = false | ||||||
|  |             } | ||||||
|  |             .navigationTitle("Settings") | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |          | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #Preview { | ||||||
|  |     SettingsView() | ||||||
|  | } | ||||||
| @@ -12,7 +12,7 @@ struct SleepDebtApp: App { | |||||||
|     @StateObject var healthKitManager = HealthKitManager() |     @StateObject var healthKitManager = HealthKitManager() | ||||||
|     var body: some Scene { |     var body: some Scene { | ||||||
|         WindowGroup { |         WindowGroup { | ||||||
|             ContentView() |             SleepDebtTabView() | ||||||
|                 .environmentObject(healthKitManager) |                 .environmentObject(healthKitManager) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										35
									
								
								SleepDebt/SleepDebtTabView.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								SleepDebt/SleepDebtTabView.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | // | ||||||
|  | //  SleepDebtTabView.swift | ||||||
|  | //  SleepDebt | ||||||
|  | // | ||||||
|  | //  Created by Oliver Hnát on 06.01.2024. | ||||||
|  | // | ||||||
|  |  | ||||||
|  | import SwiftUI | ||||||
|  |  | ||||||
|  | struct SleepDebtTabView: View { | ||||||
|  |     @State var selectedTab = "Home" | ||||||
|  |     @StateObject var healthKitManager = HealthKitManager() | ||||||
|  |     var body: some View { | ||||||
|  |         TabView(selection: $selectedTab) { | ||||||
|  |             ContentView() | ||||||
|  |                 .tag("Home") | ||||||
|  |                 .tabItem { | ||||||
|  |                     Image(systemName: "house") | ||||||
|  |                     Text("Home") | ||||||
|  |                 } | ||||||
|  |                 .environmentObject(healthKitManager) | ||||||
|  |             SettingsView() | ||||||
|  |                 .tag("Settings") | ||||||
|  |                 .tabItem { | ||||||
|  |                     Image(systemName: "gear") | ||||||
|  |                     Text("Settings") | ||||||
|  |                 } | ||||||
|  |                 .environmentObject(healthKitManager) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #Preview { | ||||||
|  |     SleepDebtTabView() | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user