Просмотр исходного кода

Descriptive alerts for preferences. First commit.

(cherry picked from commit ace94be5e1b1e6cd7f04b81dc536141e1752fbe9)
Jon Mårtensson 5 лет назад
Родитель
Сommit
fcf4c6e8d5

+ 9 - 1
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift

@@ -6,6 +6,7 @@ enum PreferencesEditor {
     class Field<T>: Identifiable {
         var displayName: String
         var keypath: WritableKeyPath<Preferences, T>
+        var infoText: String
         var value: T {
             didSet {
                 settable?.onSet(keypath, value: value)
@@ -14,10 +15,17 @@ enum PreferencesEditor {
 
         weak var settable: PreferencesSettable?
 
-        init(displayName: String, keypath: WritableKeyPath<Preferences, T>, value: T, settable: PreferencesSettable? = nil) {
+        init(
+            displayName: String,
+            keypath: WritableKeyPath<Preferences, T>,
+            value: T,
+            infoText: String,
+            settable: PreferencesSettable? = nil
+        ) {
             self.displayName = displayName
             self.keypath = keypath
             self.value = value
+            self.infoText = infoText
             self.settable = settable
         }
 

Разница между файлами не показана из-за своего большого размера
+ 40 - 1
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorViewModel.swift


+ 30 - 1
FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift

@@ -1,5 +1,10 @@
 import SwiftUI
 
+struct DescriptionString: Identifiable {
+    var id: String { name }
+    let name: String
+}
+
 extension PreferencesEditor {
     struct RootView: BaseView {
         @EnvironmentObject var viewModel: ViewModel<Provider>
@@ -10,6 +15,8 @@ extension PreferencesEditor {
             return formatter
         }
 
+        @State private var infoButtonPressed: DescriptionString?
+
         var body: some View {
             Form {
                 Section(header: Text("FreeAPS X")) {
@@ -36,15 +43,37 @@ extension PreferencesEditor {
                     }
 
                     ForEach(viewModel.boolFields.indexed(), id: \.1.id) { index, field in
-                        Toggle(field.displayName, isOn: self.$viewModel.boolFields[index].value)
+                        HStack {
+                            Button("ⓘ", action: {
+                                infoButtonPressed = DescriptionString(name: field.infoText)
+                            })
+                            Toggle(field.displayName, isOn: self.$viewModel.boolFields[index].value)
+                        }
+                    }
+                    .alert(item: $infoButtonPressed) { iButton in
+                        Alert(
+                            title: Text("Description"),
+                            message: Text(iButton.name),
+                            dismissButton: .default(Text("Got it!"))
+                        )
                     }
 
                     ForEach(viewModel.decimalFields.indexed(), id: \.1.id) { index, field in
                         HStack {
+                            Button("ⓘ", action: {
+                                infoButtonPressed = DescriptionString(name: field.infoText)
+                            })
                             Text(field.displayName)
                             DecimalTextField("0", value: self.$viewModel.decimalFields[index].value, formatter: formatter)
                         }
                     }
+                    .alert(item: $infoButtonPressed) { iButton in
+                        Alert(
+                            title: Text("Description"),
+                            message: Text(iButton.name),
+                            dismissButton: .default(Text("Got it!"))
+                        )
+                    }
                 }
 
                 Section {