Skip to content

Commit aab566c

Browse files
authored
Updates to suspend threshold from design review (#76)
* Implement suspend threshold guardrails * Update project.pbxproj * Tweak suspend threshold description * Updates from design review
1 parent 760a182 commit aab566c

File tree

2 files changed

+11
-56
lines changed

2 files changed

+11
-56
lines changed

Loop/Views/SuspendThresholdEditor.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import LoopKitUI
1313

1414

1515
struct SuspendThresholdEditor: View {
16-
@State private var value = HKQuantity(unit: .milligramsPerDeciliter, doubleValue: 80)
16+
@State private var value: HKQuantity
1717
@State private var isEditing = false
1818
@State private var showingConfirmationAlert = false
1919

@@ -50,8 +50,8 @@ struct SuspendThresholdEditor: View {
5050
// https://bugs.swift.org/browse/SR-11628
5151
if true {
5252
Card {
53-
SuspendThresholdPicker(value: $value, unit: unit, isEditing: $isEditing)
5453
SuspendThresholdDescription()
54+
SuspendThresholdPicker(value: $value, unit: unit, isEditing: $isEditing)
5555
}
5656
}
5757
},
@@ -89,7 +89,7 @@ struct SuspendThresholdEditor: View {
8989
private func confirmationAlert() -> Alert {
9090
Alert(
9191
title: Text("Save Suspend Threshold?", comment: "Alert title for confirming a suspend threshold outside the recommended range"),
92-
message: Text("The suspend threshold you have entered is outside of what we recommend.", comment: "Alert message for confirming a suspend threshold outside the recommended range"),
92+
message: Text("The suspend threshold you have entered is outside of what Tidepool generally recommends.", comment: "Alert message for confirming a suspend threshold outside the recommended range"),
9393
primaryButton: .cancel(Text("Go Back")),
9494
secondaryButton: .default(
9595
Text("Continue"),
@@ -105,7 +105,7 @@ struct SuspendThresholdEditor: View {
105105
}
106106

107107
struct SuspendThresholdDescription: View {
108-
let text = Text("When your glucose is below or predicted to go below this value, the app will recommend a basal rate of 0 U/h and will not recommend a bolus.", comment: "Suspend threshold description")
108+
let text = Text("When your glucose is predicted to go below this value, the app will recommend a basal rate of 0 U/h and will not recommend a bolus.", comment: "Suspend threshold description")
109109

110110
var body: some View {
111111
SettingDescription(text: text)
@@ -121,14 +121,10 @@ struct SuspendThresholdGuardrailWarning: View {
121121

122122
private var title: Text {
123123
switch safetyClassificationThreshold {
124-
case .minimum:
125-
return Text("Lowest Suspend Threshold", comment: "Title text for the lowest suspend threshold warning")
126-
case .belowRecommended:
124+
case .minimum, .belowRecommended:
127125
return Text("Low Suspend Threshold", comment: "Title text for the low suspend threshold warning")
128-
case .aboveRecommended:
126+
case .aboveRecommended, .maximum:
129127
return Text("High Suspend Threshold", comment: "Title text for the high suspend threshold warning")
130-
case .maximum:
131-
return Text("Highest Suspend Threshold", comment: "Title text for the highest suspend threshold warning")
132128
}
133129
}
134130
}

Loop/Views/SuspendThresholdPicker.swift

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,13 @@ struct SuspendThresholdPicker: View {
1717
var unit: HKUnit
1818
@Binding var isEditing: Bool
1919

20-
private var formatter: NumberFormatter
21-
22-
init(value: Binding<HKQuantity>, unit: HKUnit, isEditing: Binding<Bool>) {
23-
self._value = value
24-
self.unit = unit
25-
self._isEditing = isEditing
26-
self.formatter = {
27-
let quantityFormatter = QuantityFormatter()
28-
quantityFormatter.setPreferredNumberFormatter(for: unit)
29-
return quantityFormatter.numberFormatter
30-
}()
31-
}
32-
3320
var body: some View {
3421
VStack {
3522
HStack {
3623
Spacer()
37-
38-
if Guardrail.suspendThreshold.classification(for: value) != .withinRecommendedRange {
39-
Image(systemName: "exclamationmark.triangle.fill")
40-
.foregroundColor(accentColor)
41-
.transition(.springInScaleOut)
42-
}
43-
44-
Text(formatter.string(from: value.doubleValue(for: unit)) ?? "\(value.doubleValue(for: unit))")
45-
.foregroundColor(accentColor)
46-
.animation(nil)
47-
48-
Text(unit.shortLocalizedUnitString())
49-
.foregroundColor(.gray)
24+
GuardrailConstrainedQuantityView(value: value, unit: unit, guardrail: .suspendThreshold, isEditing: isEditing)
5025
}
26+
.contentShape(Rectangle())
5127
.onTapGesture {
5228
withAnimation {
5329
self.isEditing.toggle()
@@ -61,27 +37,10 @@ struct SuspendThresholdPicker: View {
6137
}
6238
}
6339
}
64-
65-
private var accentColor: Color {
66-
switch Guardrail.suspendThreshold.classification(for: value) {
67-
case .withinRecommendedRange:
68-
return isEditing ? .accentColor : .primary
69-
case .outsideRecommendedRange(let threshold):
70-
switch threshold {
71-
case .minimum, .maximum:
72-
return .severeWarning
73-
case .belowRecommended, .aboveRecommended:
74-
return .warning
75-
}
76-
}
77-
}
7840
}
7941

8042
fileprivate extension AnyTransition {
81-
static let expandFromTop = move(edge: .top).combined(with: .opacity).combined(with: .scale(scale: 0, anchor: .top))
82-
83-
static let springInScaleOut = asymmetric(
84-
insertion: AnyTransition.scale.animation(.spring(dampingFraction: 0.5)),
85-
removal: AnyTransition.scale.combined(with: .opacity)
86-
)
43+
static let expandFromTop = move(edge: .top)
44+
.combined(with: .opacity)
45+
.combined(with: .scale(scale: 0, anchor: .top))
8746
}

0 commit comments

Comments
 (0)