ManualTempBasalRootView.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import SwiftUI
  2. import Swinject
  3. extension ManualTempBasal {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @State var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. @Environment(AppState.self) var appState
  9. private var formatter: NumberFormatter {
  10. let formatter = NumberFormatter()
  11. formatter.numberStyle = .decimal
  12. formatter.maximumIntegerDigits = 2
  13. formatter.maximumFractionDigits = 2
  14. return formatter
  15. }
  16. var body: some View {
  17. Form {
  18. Section {
  19. HStack {
  20. Text("Amount")
  21. Spacer()
  22. TextFieldWithToolBar(
  23. text: $state.rate,
  24. placeholder: "0",
  25. numberFormatter: formatter,
  26. initialFocus: true,
  27. unitsText: String(localized: "U/hr", comment: "Units text for temporary basal rate")
  28. )
  29. }
  30. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  31. ForEach(0 ..< state.durationValues.count) { index in
  32. Text(
  33. String(
  34. format: "%.0f h %02.0f min",
  35. state.durationValues[index] / 60 - 0.1,
  36. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  37. )
  38. ).tag(index)
  39. }
  40. }
  41. }
  42. Section {
  43. Button { state.enact() }
  44. label: { Text("Enact") }
  45. Button { state.cancel() }
  46. label: { Text("Cancel Temp Basal") }
  47. }
  48. }
  49. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  50. .onAppear(perform: configureView)
  51. .navigationTitle("Manual Temp Basal")
  52. .navigationBarTitleDisplayMode(.automatic)
  53. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  54. }
  55. }
  56. }