ManualTempBasalRootView.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import SwiftUI
  2. import Swinject
  3. extension ManualTempBasal {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color.bgDarkBlue,
  12. Color.bgDarkerDarkBlue
  13. ]),
  14. startPoint: .top,
  15. endPoint: .bottom
  16. )
  17. :
  18. LinearGradient(
  19. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. }
  24. private var formatter: NumberFormatter {
  25. let formatter = NumberFormatter()
  26. formatter.numberStyle = .decimal
  27. formatter.maximumFractionDigits = 2
  28. return formatter
  29. }
  30. var body: some View {
  31. Form {
  32. Section {
  33. HStack {
  34. Text("Amount")
  35. Spacer()
  36. TextFieldWithToolBar(
  37. text: $state.rate,
  38. placeholder: "0",
  39. shouldBecomeFirstResponder: true,
  40. numberFormatter: formatter
  41. )
  42. Text("U/hr").foregroundColor(.secondary)
  43. }
  44. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  45. ForEach(0 ..< state.durationValues.count) { index in
  46. Text(
  47. String(
  48. format: "%.0f h %02.0f min",
  49. state.durationValues[index] / 60 - 0.1,
  50. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  51. )
  52. ).tag(index)
  53. }
  54. }
  55. }
  56. Section {
  57. Button { state.enact() }
  58. label: { Text("Enact") }
  59. Button { state.cancel() }
  60. label: { Text("Cancel Temp Basal") }
  61. }
  62. }
  63. .scrollContentBackground(.hidden).background(color)
  64. .onAppear(perform: configureView)
  65. .navigationTitle("Manual Temp Basal")
  66. .navigationBarTitleDisplayMode(.automatic)
  67. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  68. }
  69. }
  70. }