ManualTempBasalRootView.swift 2.5 KB

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