ConnectionStatusPill.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // LoopFollow
  2. // ConnectionStatusPill.swift
  3. import SwiftUI
  4. /// A pinned, color-coded status banner shown at the top of the onboarding
  5. /// connect screens (Nightscout and Dexcom). It morphs as the connection state
  6. /// changes, giving both screens the same live, above-the-fold status treatment.
  7. ///
  8. /// The pill itself is state-agnostic: each connect screen maps its own view
  9. /// model's status into a `color`, an optional `systemImage`, and whether to show
  10. /// a spinner, so the two different status enums can share one look.
  11. struct ConnectionStatusPill: View {
  12. let color: Color
  13. let message: String
  14. var isLoading: Bool = false
  15. var systemImage: String?
  16. var body: some View {
  17. HStack(spacing: 10) {
  18. Group {
  19. if isLoading {
  20. ProgressView().scaleEffect(0.85)
  21. } else if let systemImage {
  22. Image(systemName: systemImage).foregroundColor(color)
  23. }
  24. }
  25. .frame(width: 20)
  26. Text(message)
  27. .font(.subheadline.weight(.medium))
  28. .foregroundColor(color)
  29. .fixedSize(horizontal: false, vertical: true)
  30. Spacer(minLength: 0)
  31. }
  32. .padding(.horizontal, 14)
  33. .padding(.vertical, 12)
  34. .frame(maxWidth: .infinity, alignment: .leading)
  35. .background(
  36. RoundedRectangle(cornerRadius: 14, style: .continuous)
  37. .fill(color.opacity(0.12))
  38. )
  39. .overlay(
  40. RoundedRectangle(cornerRadius: 14, style: .continuous)
  41. .stroke(color.opacity(0.3), lineWidth: 1)
  42. )
  43. }
  44. }