InsertCannulaView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // InsertCannulaView.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 2/5/20.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKitUI
  10. struct InsertCannulaView: View {
  11. @ObservedObject var viewModel: InsertCannulaViewModel
  12. @Environment(\.verticalSizeClass) var verticalSizeClass
  13. @State private var cancelModalIsPresented: Bool = false
  14. var body: some View {
  15. GuidePage(content: {
  16. VStack {
  17. LeadingImage("Pod")
  18. HStack {
  19. InstructionList(instructions: [
  20. LocalizedString("Tap below to start cannula insertion.", comment: "Label text for step one of insert cannula instructions"),
  21. LocalizedString("Wait until insertion is completed.", comment: "Label text for step two of insert cannula instructions"),
  22. ])
  23. .disabled(viewModel.state.instructionsDisabled)
  24. }
  25. .padding(.bottom, 8)
  26. }
  27. .accessibility(sortPriority: 1)
  28. }) {
  29. VStack {
  30. if self.viewModel.state.showProgressDetail {
  31. self.viewModel.error.map {
  32. ErrorView($0, errorClass: $0.recoverable ? .normal : .critical)
  33. .accessibility(sortPriority: 0)
  34. }
  35. if self.viewModel.error == nil {
  36. VStack {
  37. ProgressIndicatorView(state: self.viewModel.state.progressState)
  38. if self.viewModel.state.isFinished {
  39. FrameworkLocalText("Inserted", comment: "Label text indicating insertion finished.")
  40. .bold()
  41. .padding(.top)
  42. }
  43. }
  44. .padding(.bottom, 8)
  45. }
  46. }
  47. if self.viewModel.error != nil {
  48. Button(action: {
  49. self.viewModel.didRequestDeactivation?()
  50. }) {
  51. Text(LocalizedString("Deactivate Pod", comment: "Button text for deactivate pod button"))
  52. .accessibility(identifier: "button_deactivate_pod")
  53. .actionButtonStyle(.destructive)
  54. }
  55. .disabled(self.viewModel.state.isProcessing)
  56. }
  57. if (self.viewModel.error == nil || self.viewModel.error?.recoverable == true) {
  58. Button(action: {
  59. self.viewModel.continueButtonTapped()
  60. }) {
  61. Text(self.viewModel.state.nextActionButtonDescription)
  62. .accessibility(identifier: "button_next_action")
  63. .accessibility(label: Text(self.viewModel.state.actionButtonAccessibilityLabel))
  64. .actionButtonStyle(.primary)
  65. }
  66. .disabled(self.viewModel.state.isProcessing)
  67. .animation(nil)
  68. .zIndex(1)
  69. }
  70. }
  71. .transition(AnyTransition.opacity.combined(with: .move(edge: .bottom)))
  72. .padding()
  73. }
  74. .animation(.default)
  75. .alert(isPresented: $cancelModalIsPresented) { cancelPairingModal }
  76. .navigationBarTitle("Insert Cannula", displayMode: .automatic)
  77. .navigationBarBackButtonHidden(true)
  78. .navigationBarItems(trailing: cancelButton)
  79. }
  80. var cancelButton: some View {
  81. Button(LocalizedString("Cancel", comment: "Cancel button text in navigation bar on insert cannula screen")) {
  82. cancelModalIsPresented = true
  83. }
  84. .accessibility(identifier: "button_cancel")
  85. }
  86. var cancelPairingModal: Alert {
  87. return Alert(
  88. title: FrameworkLocalText("Are you sure you want to cancel Pod setup?", comment: "Alert title for cancel pairing modal"),
  89. message: FrameworkLocalText("If you cancel Pod setup, the current Pod will be deactivated and will be unusable.", comment: "Alert message body for confirm pod attachment"),
  90. primaryButton: .destructive(FrameworkLocalText("Yes, Deactivate Pod", comment: "Button title for confirm deactivation option"), action: { viewModel.didRequestDeactivation?() } ),
  91. secondaryButton: .default(FrameworkLocalText("No, Continue With Pod", comment: "Continue pairing button title of in pairing cancel modal"))
  92. )
  93. }
  94. }