ManualTempBasalRootView.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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("Background_1"),
  12. Color("Background_1"),
  13. Color("Background_2")
  14. // Color("Background_1")
  15. ]),
  16. startPoint: .top,
  17. endPoint: .bottom
  18. )
  19. :
  20. LinearGradient(
  21. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. }
  26. private var formatter: NumberFormatter {
  27. let formatter = NumberFormatter()
  28. formatter.numberStyle = .decimal
  29. formatter.maximumFractionDigits = 2
  30. return formatter
  31. }
  32. var body: some View {
  33. Form {
  34. Section {
  35. HStack {
  36. Text("Amount")
  37. Spacer()
  38. DecimalTextField("0", value: $state.rate, formatter: formatter, autofocus: true, cleanInput: true)
  39. Text("U/hr").foregroundColor(.secondary)
  40. }
  41. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  42. ForEach(0 ..< state.durationValues.count) { index in
  43. Text(
  44. String(
  45. format: "%.0f h %02.0f min",
  46. state.durationValues[index] / 60 - 0.1,
  47. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  48. )
  49. ).tag(index)
  50. }
  51. }
  52. }
  53. Section {
  54. Button { state.enact() }
  55. label: { Text("Enact") }
  56. Button { state.cancel() }
  57. label: { Text("Cancel Temp Basal") }
  58. }
  59. }
  60. .scrollContentBackground(.hidden).background(color)
  61. .onAppear(perform: configureView)
  62. .navigationTitle("Manual Temp Basal")
  63. .navigationBarTitleDisplayMode(.automatic)
  64. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  65. }
  66. }
  67. }