|
|
@@ -5,13 +5,37 @@ extension DynamicSettings {
|
|
|
struct RootView: BaseView {
|
|
|
let resolver: Resolver
|
|
|
@StateObject var state = StateModel()
|
|
|
- @State private var shouldDisplayHint: Bool = false
|
|
|
@State var hintDetent = PresentationDetent.large
|
|
|
- @State var selectedVerboseHint: AnyView?
|
|
|
- @State var hintLabel: String?
|
|
|
+ @State private var hintPayload: HintPayload?
|
|
|
@State private var decimalPlaceholder: Decimal = 0.0
|
|
|
@State private var booleanPlaceholder: Bool = false
|
|
|
|
|
|
+ private struct HintPayload: Identifiable {
|
|
|
+ let id = UUID()
|
|
|
+ let label: String
|
|
|
+ let content: AnyView
|
|
|
+ }
|
|
|
+
|
|
|
+ private var shouldDisplayHintBinding: Binding<Bool> {
|
|
|
+ Binding(
|
|
|
+ get: { hintPayload != nil },
|
|
|
+ set: { newValue in if !newValue { hintPayload = nil } }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ private func verboseHintBinding(label: String) -> Binding<(any View)?> {
|
|
|
+ Binding(
|
|
|
+ get: { hintPayload?.content },
|
|
|
+ set: { newView in
|
|
|
+ if let view = newView {
|
|
|
+ hintPayload = HintPayload(label: label, content: AnyView(view))
|
|
|
+ } else {
|
|
|
+ hintPayload = nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
private var conversionFormatter: NumberFormatter {
|
|
|
let formatter = NumberFormatter()
|
|
|
formatter.numberStyle = .decimal
|
|
|
@@ -76,9 +100,9 @@ extension DynamicSettings {
|
|
|
Spacer()
|
|
|
Button(
|
|
|
action: {
|
|
|
- hintLabel = String(localized: "Dynamic Insulin Sensitivity")
|
|
|
- selectedVerboseHint =
|
|
|
- AnyView(
|
|
|
+ hintPayload = HintPayload(
|
|
|
+ label: String(localized: "Dynamic Insulin Sensitivity"),
|
|
|
+ content: AnyView(
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
Text("Default: Disabled").bold()
|
|
|
Text(
|
|
|
@@ -124,7 +148,7 @@ extension DynamicSettings {
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
- shouldDisplayHint.toggle()
|
|
|
+ )
|
|
|
},
|
|
|
label: {
|
|
|
HStack {
|
|
|
@@ -142,14 +166,8 @@ extension DynamicSettings {
|
|
|
SettingInputSection(
|
|
|
decimalValue: $state.adjustmentFactor,
|
|
|
booleanValue: $booleanPlaceholder,
|
|
|
- shouldDisplayHint: $shouldDisplayHint,
|
|
|
- selectedVerboseHint: Binding(
|
|
|
- get: { selectedVerboseHint },
|
|
|
- set: {
|
|
|
- selectedVerboseHint = $0.map { AnyView($0) }
|
|
|
- hintLabel = String(localized: "Adjustment Factor (AF)")
|
|
|
- }
|
|
|
- ),
|
|
|
+ shouldDisplayHint: shouldDisplayHintBinding,
|
|
|
+ selectedVerboseHint: verboseHintBinding(label: String(localized: "Adjustment Factor (AF)")),
|
|
|
// TODO?: include conditional links to Desmos logarithmic graphs based on which .glucose setting is used
|
|
|
units: state.units,
|
|
|
type: .decimal("adjustmentFactor"),
|
|
|
@@ -173,14 +191,8 @@ extension DynamicSettings {
|
|
|
SettingInputSection(
|
|
|
decimalValue: $state.adjustmentFactorSigmoid,
|
|
|
booleanValue: $booleanPlaceholder,
|
|
|
- shouldDisplayHint: $shouldDisplayHint,
|
|
|
- selectedVerboseHint: Binding(
|
|
|
- get: { selectedVerboseHint },
|
|
|
- set: {
|
|
|
- selectedVerboseHint = $0.map { AnyView($0) }
|
|
|
- hintLabel = String(localized: "Sigmoid Adjustment Factor")
|
|
|
- }
|
|
|
- ),
|
|
|
+ shouldDisplayHint: shouldDisplayHintBinding,
|
|
|
+ selectedVerboseHint: verboseHintBinding(label: String(localized: "Sigmoid Adjustment Factor")),
|
|
|
units: state.units,
|
|
|
type: .decimal("adjustmentFactorSigmoid"),
|
|
|
label: String(localized: "Sigmoid Adjustment Factor"),
|
|
|
@@ -207,14 +219,8 @@ extension DynamicSettings {
|
|
|
SettingInputSection(
|
|
|
decimalValue: $state.weightPercentage,
|
|
|
booleanValue: $booleanPlaceholder,
|
|
|
- shouldDisplayHint: $shouldDisplayHint,
|
|
|
- selectedVerboseHint: Binding(
|
|
|
- get: { selectedVerboseHint },
|
|
|
- set: {
|
|
|
- selectedVerboseHint = $0.map { AnyView($0) }
|
|
|
- hintLabel = String(localized: "Weighted Average of TDD")
|
|
|
- }
|
|
|
- ),
|
|
|
+ shouldDisplayHint: shouldDisplayHintBinding,
|
|
|
+ selectedVerboseHint: verboseHintBinding(label: String(localized: "Weighted Average of TDD")),
|
|
|
units: state.units,
|
|
|
type: .decimal("weightPercentage"),
|
|
|
label: String(localized: "Weighted Average of TDD"),
|
|
|
@@ -236,14 +242,8 @@ extension DynamicSettings {
|
|
|
SettingInputSection(
|
|
|
decimalValue: $decimalPlaceholder,
|
|
|
booleanValue: $state.tddAdjBasal,
|
|
|
- shouldDisplayHint: $shouldDisplayHint,
|
|
|
- selectedVerboseHint: Binding(
|
|
|
- get: { selectedVerboseHint },
|
|
|
- set: {
|
|
|
- selectedVerboseHint = $0.map { AnyView($0) }
|
|
|
- hintLabel = String(localized: "Adjust Basal")
|
|
|
- }
|
|
|
- ),
|
|
|
+ shouldDisplayHint: shouldDisplayHintBinding,
|
|
|
+ selectedVerboseHint: verboseHintBinding(label: String(localized: "Adjust Basal")),
|
|
|
units: state.units,
|
|
|
type: .boolean,
|
|
|
label: String(localized: "Adjust Basal"),
|
|
|
@@ -264,12 +264,12 @@ extension DynamicSettings {
|
|
|
}
|
|
|
}
|
|
|
.listSectionSpacing(sectionSpacing)
|
|
|
- .sheet(isPresented: $shouldDisplayHint) {
|
|
|
+ .sheet(item: $hintPayload) { payload in
|
|
|
SettingInputHintView(
|
|
|
hintDetent: $hintDetent,
|
|
|
- shouldDisplayHint: $shouldDisplayHint,
|
|
|
- hintLabel: hintLabel ?? "",
|
|
|
- hintText: selectedVerboseHint ?? AnyView(EmptyView()),
|
|
|
+ shouldDisplayHint: shouldDisplayHintBinding,
|
|
|
+ hintLabel: payload.label,
|
|
|
+ hintText: payload.content,
|
|
|
sheetTitle: String(localized: "Help", comment: "Help sheet title")
|
|
|
)
|
|
|
}
|