TrioRemoteControlView.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // LoopFollow
  2. // TrioRemoteControlView.swift
  3. import SwiftUI
  4. struct TrioRemoteControlView: View {
  5. @ObservedObject var viewModel: TrioRemoteControlViewModel
  6. @ObservedObject private var activeOverrideNote = Observable.shared.override
  7. @ObservedObject private var activeTempTarget = Observable.shared.tempTarget
  8. @Environment(\.presentationMode) var presentationMode
  9. var body: some View {
  10. NavigationView {
  11. VStack {
  12. let columns = [
  13. GridItem(.flexible(), spacing: 16),
  14. GridItem(.flexible(), spacing: 16),
  15. ]
  16. LazyVGrid(columns: columns, spacing: 16) {
  17. CommandButtonView(command: "Meal", iconName: "fork.knife", destination: MealView())
  18. CommandButtonView(command: "Bolus", iconName: "syringe", destination: BolusView())
  19. CommandButtonView(command: "Temp Target", iconName: "scope", destination: TempTargetView(), isActive: activeTempTarget.value != nil)
  20. CommandButtonView(command: "Overrides", iconName: "slider.horizontal.3", destination: OverrideView(), isActive: activeOverrideNote.value != nil)
  21. }
  22. .padding(.horizontal)
  23. Spacer()
  24. }
  25. .navigationBarTitle("Trio Remote Control", displayMode: .inline)
  26. }
  27. }
  28. }
  29. struct CommandButtonView<Destination: View>: View {
  30. let command: String
  31. let iconName: String
  32. let destination: Destination
  33. /// Lights the button up with a glow while the corresponding override /
  34. /// temp target is active.
  35. var isActive: Bool = false
  36. var body: some View {
  37. NavigationLink(destination: destination) {
  38. VStack {
  39. Image(systemName: iconName)
  40. .resizable()
  41. .aspectRatio(contentMode: .fit)
  42. .frame(width: 50, height: 50)
  43. Text(command)
  44. }
  45. .frame(maxWidth: .infinity, minHeight: 100)
  46. .padding()
  47. .background(Color.blue)
  48. .foregroundColor(.white)
  49. .cornerRadius(8)
  50. .overlay {
  51. if isActive {
  52. RoundedRectangle(cornerRadius: 8)
  53. .stroke(Color.green, lineWidth: 2.5)
  54. }
  55. }
  56. .shadow(color: isActive ? Color.green.opacity(0.7) : .clear, radius: isActive ? 9 : 0)
  57. }
  58. .buttonStyle(PlainButtonStyle())
  59. }
  60. }