BolusProgressOverlay.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import SwiftUI
  2. struct BolusProgressOverlay: View {
  3. let state: WatchState
  4. let onCancelBolus: () -> Void
  5. private let progressGradient = LinearGradient(
  6. colors: [
  7. Color(red: 0.7215686275, green: 0.3411764706, blue: 1), // #B857FF
  8. Color(red: 0.6235294118, green: 0.4235294118, blue: 0.9803921569), // #9F6CFA
  9. Color(red: 0.4862745098, green: 0.5450980392, blue: 0.9529411765), // #7C8BF3
  10. Color(red: 0.3411764706, green: 0.6666666667, blue: 0.9254901961), // #57AAEC
  11. Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902) // #43BBE9
  12. ],
  13. startPoint: .leading,
  14. endPoint: .trailing
  15. )
  16. var body: some View {
  17. VStack(spacing: 10) {
  18. VStack {
  19. Text("Bolusing")
  20. .font(.footnote)
  21. .foregroundStyle(.secondary)
  22. .padding(.top)
  23. ProgressView(value: state.bolusProgress, total: 1.0)
  24. .tint(progressGradient)
  25. Text(String(
  26. format: "%.1f U of %.1f U",
  27. state.bolusProgress * state.activeBolusAmount,
  28. state.activeBolusAmount
  29. ))
  30. .font(.footnote)
  31. .foregroundStyle(.secondary)
  32. Spacer()
  33. Button(action: {
  34. state.sendCancelBolusRequest()
  35. onCancelBolus()
  36. }) {
  37. Text("Cancel Bolus")
  38. }
  39. .buttonStyle(.bordered)
  40. .padding()
  41. }
  42. .padding()
  43. .background(Color.black.opacity(0.8))
  44. .cornerRadius(10)
  45. }
  46. .scenePadding()
  47. .onChange(of: state.bolusProgress) { _, newProgress in
  48. if newProgress >= 1.0 {
  49. state.activeBolusAmount = 0 // Reset only when bolus is complete
  50. }
  51. }
  52. .onDisappear {
  53. state.activeBolusAmount = 0 // Triple-check to reset when view disappears
  54. }
  55. }
  56. }