NotificationPermissionStepView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // NotificationPermissionStepView.swift
  3. // Trio
  4. //
  5. // Created by Cengiz Deniz on 18.04.25.
  6. //
  7. import SwiftUI
  8. import UserNotifications
  9. struct NotificationPermissionStepView: View {
  10. @Bindable var state: Onboarding.StateModel
  11. var currentStep: Binding<OnboardingStep>
  12. var body: some View {
  13. VStack(alignment: .leading, spacing: 20) {
  14. Text("Allow Notifications")
  15. .font(.title3)
  16. .bold()
  17. .multilineTextAlignment(.leading)
  18. Text(
  19. "Trio can notify of different events when you use it. You must allow Trio to send you notifications to work properly."
  20. )
  21. .font(.body)
  22. .multilineTextAlignment(.leading)
  23. .foregroundColor(Color.secondary)
  24. .padding(.bottom)
  25. VStack(alignment: .leading, spacing: 20) {
  26. HStack(spacing: 12) {
  27. Image(systemName: "ellipsis.message.fill")
  28. .font(.system(size: 24))
  29. .foregroundColor(Color.bgDarkBlue)
  30. .frame(width: 44, height: 44)
  31. .background(Circle().fill(Color.primary.opacity(0.8)))
  32. Text("Receive optional real‑time low/high glucose alerts.")
  33. .font(.body)
  34. .foregroundColor(.primary)
  35. }
  36. HStack(spacing: 12) {
  37. Image(systemName: "exclamationmark.triangle.fill")
  38. .font(.system(size: 24))
  39. .foregroundColor(Color.bgDarkBlue)
  40. .frame(width: 44, height: 44)
  41. .background(Circle().fill(Color.primary.opacity(0.8)))
  42. Text("Be warned of connectivity or looping issues.")
  43. .font(.body)
  44. .foregroundColor(.primary)
  45. }
  46. HStack(spacing: 12) {
  47. Image(systemName: "app.badge.fill")
  48. .font(.system(size: 24))
  49. .foregroundColor(Color.bgDarkBlue)
  50. .frame(width: 44, height: 44)
  51. .background(Circle().fill(Color.primary.opacity(0.8)))
  52. Text("See a badge count when you need a carb correction.")
  53. .font(.body)
  54. .foregroundColor(.primary)
  55. }
  56. }
  57. Text("You can change these permissions any time in the iOS Settings app.")
  58. .font(.footnote)
  59. .multilineTextAlignment(.leading)
  60. .foregroundColor(Color.secondary)
  61. .padding(.top)
  62. }.padding(.horizontal)
  63. .background(
  64. SystemAlert(
  65. isPresented: $state.shouldDisplayCustomNotificationAlert,
  66. title: String(localized: "Notifications for “Trio” are Disabled"),
  67. message: String(
  68. localized: "After completing onboarding, a red banner will appear on Trio's main screen to guide you to the iOS Settings app, where you can enable notifications."
  69. ),
  70. allowTitle: String(localized: "Got it!"),
  71. denyTitle: String(localized: "Cancel"),
  72. onAllow: {
  73. DispatchQueue.main.async {
  74. state.shouldDisplayCustomNotificationAlert = false
  75. if let next = currentStep.wrappedValue.next {
  76. currentStep.wrappedValue = next
  77. }
  78. }
  79. },
  80. onDeny: {
  81. DispatchQueue.main.async {
  82. state.shouldDisplayCustomNotificationAlert = false
  83. if let next = currentStep.wrappedValue.next {
  84. currentStep.wrappedValue = next
  85. }
  86. }
  87. }
  88. )
  89. )
  90. }
  91. }