AttachPodView.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // AttachPodView.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 2/23/21.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKitUI
  10. struct AttachPodView: View {
  11. enum Modal: Int, Identifiable {
  12. var id: Int { rawValue }
  13. case attachConfirmationModal
  14. case cancelModal
  15. }
  16. @Environment(\.verticalSizeClass) var verticalSizeClass
  17. var didConfirmAttachment: () -> Void
  18. var didRequestDeactivation: () -> Void
  19. @State private var activeModal: Modal?
  20. var body: some View {
  21. GuidePage(content: {
  22. VStack {
  23. LeadingImage("Pod")
  24. HStack {
  25. InstructionList(instructions: [
  26. LocalizedString("Prepare site.", comment: "Label text for step one of attach pod instructions"),
  27. LocalizedString("Remove the Pod's clear needle cap and check cannula. Then remove paper backing.", comment: "Label text for step two of attach pod instructions"),
  28. LocalizedString("Check Pod, apply to site, then confirm pod attachment.", comment: "Label text for step three of attach pod instructions")
  29. ])
  30. }
  31. .padding(.bottom, 8)
  32. }
  33. .accessibility(sortPriority: 1)
  34. }) {
  35. Button(action: {
  36. activeModal = .attachConfirmationModal
  37. }) {
  38. FrameworkLocalText("Continue", comment: "Action button title for attach pod view")
  39. .accessibility(identifier: "button_next_action")
  40. .actionButtonStyle(.primary)
  41. }
  42. .animation(nil)
  43. .padding()
  44. .background(Color(UIColor.systemBackground))
  45. .zIndex(1)
  46. }
  47. .animation(.default)
  48. .alert(item: $activeModal, content: self.alert(for:))
  49. .navigationBarTitle(LocalizedString("Attach Pod", comment: "navigation bar title attach pod"), displayMode: .automatic)
  50. .navigationBarItems(trailing: cancelButton)
  51. .navigationBarBackButtonHidden(true)
  52. }
  53. var cancelButton: some View {
  54. Button(LocalizedString("Cancel", comment: "Cancel button text in navigation bar on pair pod UI")) {
  55. activeModal = .cancelModal
  56. }
  57. .accessibility(identifier: "button_cancel")
  58. }
  59. private func alert(for modal: Modal) -> Alert {
  60. switch modal {
  61. case .attachConfirmationModal:
  62. return confirmationModal
  63. case .cancelModal:
  64. return cancelPairingModal
  65. }
  66. }
  67. var confirmationModal: Alert {
  68. return Alert(
  69. title: FrameworkLocalText("Confirm Pod Attachment", comment: "Alert title for confirm pod attachment"),
  70. message: FrameworkLocalText("Please confirm that the Pod is securely attached to your body.\n\nThe cannula can be inserted only once with each Pod. Tap “Confirm” when Pod is attached.", comment: "Alert message body for confirm pod attachment"),
  71. primaryButton: .default(FrameworkLocalText("Confirm", comment: "Button title for confirm attachment option"), action: didConfirmAttachment),
  72. secondaryButton: .cancel()
  73. )
  74. }
  75. var cancelPairingModal: Alert {
  76. return Alert(
  77. title: FrameworkLocalText("Are you sure you want to cancel Pod setup?", comment: "Alert title for cancel pairing modal"),
  78. 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"),
  79. primaryButton: .destructive(FrameworkLocalText("Yes, Deactivate Pod", comment: "Button title for confirm deactivation option"), action: didRequestDeactivation),
  80. secondaryButton: .default(FrameworkLocalText("No, Continue With Pod", comment: "Continue pairing button title of in pairing cancel modal"))
  81. )
  82. }
  83. }
  84. struct AttachPodView_Previews: PreviewProvider {
  85. static var previews: some View {
  86. NavigationView {
  87. ZStack {
  88. Color(UIColor.secondarySystemBackground).edgesIgnoringSafeArea(.all)
  89. AttachPodView(didConfirmAttachment: {}, didRequestDeactivation: {})
  90. }
  91. }
  92. }
  93. }