ManualTempBasalRootView.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. <<<<<<< HEAD
  37. TextFieldWithToolBar(text: $state.rate, placeholder: "0", numberFormatter: formatter)
  38. =======
  39. TextFieldWithToolBar(
  40. text: $state.rate,
  41. placeholder: "0",
  42. shouldBecomeFirstResponder: true,
  43. numberFormatter: formatter
  44. )
  45. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  46. Text("U/hr").foregroundColor(.secondary)
  47. }
  48. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  49. ForEach(0 ..< state.durationValues.count) { index in
  50. Text(
  51. String(
  52. format: "%.0f h %02.0f min",
  53. state.durationValues[index] / 60 - 0.1,
  54. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  55. )
  56. ).tag(index)
  57. }
  58. }
  59. }
  60. Section {
  61. Button { state.enact() }
  62. label: { Text("Enact") }
  63. Button { state.cancel() }
  64. label: { Text("Cancel Temp Basal") }
  65. }
  66. }
  67. .scrollContentBackground(.hidden).background(color)
  68. .onAppear(perform: configureView)
  69. .navigationTitle("Manual Temp Basal")
  70. .navigationBarTitleDisplayMode(.automatic)
  71. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  72. }
  73. }
  74. }