HomeRootView.swift 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import SwiftUI
  2. extension Home {
  3. struct RootView: BaseView {
  4. @EnvironmentObject var viewModel: ViewModel<Provider>
  5. @State var showHours = 1
  6. var body: some View {
  7. viewModel.setFilteredGlucoseHours(hours: 24)
  8. return GeometryReader { geo in
  9. VStack {
  10. Group {
  11. Text("Header")
  12. }
  13. ScrollView(.vertical, showsIndicators: false) {
  14. HoursPickerView(selectedHour: $showHours)
  15. ScrollView(.horizontal, showsIndicators: false) {
  16. PointChartView(
  17. minValue: 20,
  18. maxValue: 300,
  19. maxWidth: geo.size.width,
  20. showHours: showHours,
  21. glucoseData: SampleData.sampleData
  22. ) { value in
  23. GlucosePointView(value: value)
  24. }
  25. }.frame(height: 300)
  26. // GlucoseChartView(glucose: $viewModel.glucose, suggestion: $viewModel.suggestion).frame(height: 150)
  27. if let reason = viewModel.suggestion?.reason {
  28. Text(reason).font(.caption).padding()
  29. }
  30. Button(action: viewModel.runLoop) {
  31. Text("Run loop now").buttonBackground().padding()
  32. }.foregroundColor(.white)
  33. }
  34. ZStack {
  35. Rectangle().fill(Color.gray.opacity(0.2)).frame(height: 50 + geo.safeAreaInsets.bottom)
  36. HStack {
  37. Button { viewModel.showModal(for: .addCarbs) }
  38. label: {
  39. Image(systemName: "circlebadge.2.fill")
  40. }.foregroundColor(.green)
  41. Spacer()
  42. Button { viewModel.showModal(for: .addTempTarget) }
  43. label: {
  44. Image(systemName: "target")
  45. }.foregroundColor(.green)
  46. Spacer()
  47. Button { viewModel.showModal(for: .bolus) }
  48. label: {
  49. Image(systemName: "drop.fill")
  50. }.foregroundColor(.orange)
  51. Spacer()
  52. if viewModel.allowManualTemp {
  53. Button { viewModel.showModal(for: .manualTempBasal) }
  54. label: {
  55. Image(systemName: "circle.bottomhalf.fill")
  56. }.foregroundColor(.blue)
  57. Spacer()
  58. }
  59. Button { viewModel.showModal(for: .settings) }
  60. label: {
  61. Image(systemName: "gearshape")
  62. }.foregroundColor(.gray)
  63. }
  64. .padding(.horizontal, 24)
  65. .padding(.bottom, geo.safeAreaInsets.bottom)
  66. }
  67. }
  68. .edgesIgnoringSafeArea(.bottom)
  69. }
  70. .navigationTitle("Home")
  71. .navigationBarHidden(true)
  72. }
  73. }
  74. }