|
|
@@ -10,62 +10,65 @@ struct BolusView: View {
|
|
|
formatter.numberStyle = .decimal
|
|
|
formatter.minimum = 0
|
|
|
formatter.maximum = Double((state.maxBolus ?? 5) / (state.bolusIncrement ?? 0.1)) as NSNumber
|
|
|
- formatter.maximumFractionDigits = 2
|
|
|
- formatter.minimumFractionDigits = 2
|
|
|
+ formatter.maximumFractionDigits = (state.bolusIncrement ?? 0.1) > 0.05 ? 1 : 2
|
|
|
+ formatter.minimumFractionDigits = (state.bolusIncrement ?? 0.1) > 0.05 ? 1 : 2
|
|
|
formatter.allowsFloats = true
|
|
|
+ formatter.roundingIncrement = Double(state.bolusIncrement ?? 0.1) as NSNumber
|
|
|
return formatter
|
|
|
}
|
|
|
|
|
|
var body: some View {
|
|
|
- VStack(spacing: 16) {
|
|
|
- HStack {
|
|
|
- Button {
|
|
|
- let newValue = steps - 1
|
|
|
- steps = max(newValue, 0)
|
|
|
- } label: { Image(systemName: "minus") }
|
|
|
- .frame(width: 50)
|
|
|
- Spacer()
|
|
|
- Text(numberFormatter.string(from: (steps * Double(state.bolusIncrement ?? 0.1)) as NSNumber)! + " U")
|
|
|
- .font(.headline)
|
|
|
- .focusable(true)
|
|
|
- .digitalCrownRotation(
|
|
|
- $steps,
|
|
|
- from: 0,
|
|
|
- through: Double((state.maxBolus ?? 5) / (state.bolusIncrement ?? 0.1)),
|
|
|
- by: 1,
|
|
|
- sensitivity: .medium,
|
|
|
- isContinuous: false,
|
|
|
- isHapticFeedbackEnabled: true
|
|
|
- )
|
|
|
- Spacer()
|
|
|
- Button {
|
|
|
- let newValue = steps + 1
|
|
|
- steps = min(newValue, Double((state.maxBolus ?? 5) / (state.bolusIncrement ?? 0.1)))
|
|
|
- } label: { Image(systemName: "plus") }
|
|
|
- .frame(width: 50)
|
|
|
- }
|
|
|
-
|
|
|
- HStack {
|
|
|
- Button {
|
|
|
- state.isBolusViewActive = false
|
|
|
- }
|
|
|
- label: {
|
|
|
- Image(systemName: "xmark.circle.fill")
|
|
|
- .resizable()
|
|
|
- .foregroundColor(.loopRed)
|
|
|
- .frame(width: 30, height: 30)
|
|
|
+ GeometryReader { geo in
|
|
|
+ VStack(spacing: 16) {
|
|
|
+ HStack {
|
|
|
+ Button {
|
|
|
+ let newValue = steps - 1
|
|
|
+ steps = max(newValue, 0)
|
|
|
+ } label: { Image(systemName: "minus") }
|
|
|
+ .frame(width: geo.size.width / 4)
|
|
|
+ Spacer()
|
|
|
+ Text(numberFormatter.string(from: (steps * Double(state.bolusIncrement ?? 0.1)) as NSNumber)! + " U")
|
|
|
+ .font(.headline)
|
|
|
+ .focusable(true)
|
|
|
+ .digitalCrownRotation(
|
|
|
+ $steps,
|
|
|
+ from: 0,
|
|
|
+ through: Double((state.maxBolus ?? 5) / (state.bolusIncrement ?? 0.1)),
|
|
|
+ by: 1,
|
|
|
+ sensitivity: .medium,
|
|
|
+ isContinuous: false,
|
|
|
+ isHapticFeedbackEnabled: true
|
|
|
+ )
|
|
|
+ Spacer()
|
|
|
+ Button {
|
|
|
+ let newValue = steps + 1
|
|
|
+ steps = min(newValue, Double((state.maxBolus ?? 5) / (state.bolusIncrement ?? 0.1)))
|
|
|
+ } label: { Image(systemName: "plus") }
|
|
|
+ .frame(width: geo.size.width / 4)
|
|
|
}
|
|
|
- Button {
|
|
|
- enactBolus()
|
|
|
- }
|
|
|
- label: {
|
|
|
- Image(systemName: "checkmark.circle.fill")
|
|
|
- .resizable()
|
|
|
- .foregroundColor(.loopGreen)
|
|
|
- .frame(width: 30, height: 30)
|
|
|
+
|
|
|
+ HStack {
|
|
|
+ Button {
|
|
|
+ state.isBolusViewActive = false
|
|
|
+ }
|
|
|
+ label: {
|
|
|
+ Image(systemName: "xmark.circle.fill")
|
|
|
+ .resizable()
|
|
|
+ .foregroundColor(.loopRed)
|
|
|
+ .frame(width: 30, height: 30)
|
|
|
+ }
|
|
|
+ Button {
|
|
|
+ enactBolus()
|
|
|
+ }
|
|
|
+ label: {
|
|
|
+ Image(systemName: "checkmark.circle.fill")
|
|
|
+ .resizable()
|
|
|
+ .foregroundColor(.loopGreen)
|
|
|
+ .frame(width: 30, height: 30)
|
|
|
+ }
|
|
|
+ .disabled(steps <= 0)
|
|
|
}
|
|
|
- .disabled(steps <= 0)
|
|
|
- }
|
|
|
+ }.frame(maxHeight: .infinity)
|
|
|
}
|
|
|
.navigationTitle("Enact Bolus")
|
|
|
.onAppear {
|
|
|
@@ -81,6 +84,13 @@ struct BolusView: View {
|
|
|
|
|
|
struct BolusView_Previews: PreviewProvider {
|
|
|
static var previews: some View {
|
|
|
- BolusView().environmentObject(WatchStateModel())
|
|
|
+ let state = WatchStateModel()
|
|
|
+ state.bolusRecommended = 10.3
|
|
|
+ state.bolusIncrement = 0.05
|
|
|
+ return Group {
|
|
|
+ BolusView()
|
|
|
+ BolusView().previewDevice("Apple Watch Series 5 - 40mm")
|
|
|
+ BolusView().previewDevice("Apple Watch Series 3 - 38mm")
|
|
|
+ }.environmentObject(state)
|
|
|
}
|
|
|
}
|