PodSetupView.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // PodSetupView.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 5/17/21.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKitUI
  10. struct PodSetupView: View {
  11. @Environment(\.dismissAction) private var dismiss
  12. private struct AlertIdentifier: Identifiable {
  13. enum Choice {
  14. case skipOnboarding
  15. }
  16. var id: Choice
  17. }
  18. @State private var alertIdentifier: AlertIdentifier?
  19. let nextAction: () -> Void
  20. let allowDebugFeatures: Bool
  21. let skipOnboarding: () -> Void
  22. var body: some View {
  23. VStack(alignment: .leading) {
  24. close
  25. ScrollView {
  26. content
  27. }
  28. Spacer()
  29. continueButton
  30. .padding(.bottom)
  31. }
  32. .padding(.horizontal)
  33. .navigationBarHidden(true)
  34. .alert(item: $alertIdentifier) { alert in
  35. switch alert.id {
  36. case .skipOnboarding:
  37. return skipOnboardingAlert
  38. }
  39. }
  40. }
  41. @ViewBuilder
  42. private var close: some View {
  43. HStack {
  44. Spacer()
  45. cancelButton
  46. }
  47. .padding(.top)
  48. }
  49. @ViewBuilder
  50. private var content: some View {
  51. VStack(alignment: .leading, spacing: 2) {
  52. title
  53. .padding(.top, 5)
  54. .onLongPressGesture(minimumDuration: 2) {
  55. didLongPressOnTitle()
  56. }
  57. Divider()
  58. bodyText
  59. .foregroundColor(.secondary)
  60. .padding(.top)
  61. }
  62. }
  63. @ViewBuilder
  64. private var title: some View {
  65. Text(LocalizedString("Pod Setup", comment: "Title for PodSetupView"))
  66. .font(.largeTitle)
  67. .bold()
  68. .padding(.vertical)
  69. }
  70. @ViewBuilder
  71. private var bodyText: some View {
  72. Text(LocalizedString("You will now begin the process of configuring your reminders, filling your Pod with insulin, pairing to your device and placing it on your body.", comment: "bodyText for PodSetupView"))
  73. }
  74. private var cancelButton: some View {
  75. Button(LocalizedString("Cancel", comment: "Cancel button title"), action: {
  76. self.dismiss()
  77. })
  78. }
  79. private var continueButton: some View {
  80. Button(LocalizedString("Continue", comment: "Text for continue button on PodSetupView"), action: nextAction)
  81. .buttonStyle(ActionButtonStyle())
  82. }
  83. private var skipOnboardingAlert: Alert {
  84. Alert(title: Text("Skip Omnipod Onboarding?"),
  85. message: Text("Are you sure you want to skip Omnipod Onboarding?"),
  86. primaryButton: .cancel(),
  87. secondaryButton: .destructive(Text("Yes"), action: skipOnboarding))
  88. }
  89. private func didLongPressOnTitle() {
  90. if allowDebugFeatures {
  91. alertIdentifier = AlertIdentifier(id: .skipOnboarding)
  92. }
  93. }
  94. }
  95. struct PodSetupView_Previews: PreviewProvider {
  96. static var previews: some View {
  97. PodSetupView(nextAction: {}, allowDebugFeatures: true, skipOnboarding: {})
  98. }
  99. }