Przeglądaj źródła

Fix update handling of therapyItems; update docstrings

Deniz Cengiz 1 rok temu
rodzic
commit
0495f17394

+ 2 - 2
Trio/Sources/Modules/Onboarding/OnboardingStateModel.swift

@@ -105,7 +105,7 @@ extension Onboarding {
 
         // MARK: - Helpers
 
-        /// Finds the index of the closest Decimal value in the given array.
+        /// Finds the index of the closest `Decimal` value in the given array.
         /// - Parameters:
         ///   - value: The value to match.
         ///   - array: The array to search in.
@@ -116,7 +116,7 @@ extension Onboarding {
             })?.offset ?? 0
         }
 
-        /// Finds the index of the closest TimeInterval value in the given array.
+        /// Finds the index of the closest `TimeInterval` value in the given array.
         /// - Parameters:
         ///   - value: The time value to match.
         ///   - array: The array to search in.

+ 7 - 3
Trio/Sources/Modules/Onboarding/View/TherapySettingEditorView.swift

@@ -109,8 +109,12 @@ struct TherapySettingEditorView: View {
         .listStyle(.plain)
         .scrollDisabled(true)
         .scrollContentBackground(.hidden)
-        .frame(height: 55 + CGFloat(items.count) * 45 + (items.contains(where: { $0.id == selectedItemID }) ? 230 : 0))
         // 55 for header row, item counts x 45 for every entry row + 230 for a visible picker row
+        .frame(height: 55 + CGFloat(items.count) * 45 + (items.contains(where: { $0.id == selectedItemID }) ? 230 : 0))
+        .onAppear {
+            // ensure picker is closed when view appears
+            selectedItemID = nil
+        }
     }
 
     @ViewBuilder private func timeValuePickerRow(
@@ -167,7 +171,7 @@ struct TherapySettingEditorView: View {
     private func validateTherapySettingItems() {
         // validates therapy items (i.e. parsed therapy settings into wrapper class)
         let newItems = Array(Set(items)).sorted { $0.time < $1.time }
-        if let first = newItems.first {
+        if var first = newItems.first {
             first.time = 0
         }
 
@@ -200,7 +204,7 @@ struct TherapySettingEditorView: View {
     }
 }
 
-class TherapySettingItem: Identifiable, Equatable, Hashable {
+struct TherapySettingItem: Identifiable, Equatable, Hashable {
     var id = UUID()
     var time: TimeInterval = 0 // seconds since start of day
     var value: Decimal = 0