QuickPickSectionHeader.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // LoopFollow
  2. // QuickPickSectionHeader.swift
  3. import SwiftUI
  4. struct QuickPickSectionHeader: View {
  5. let title: String
  6. let infoText: String
  7. @State private var showInfo = false
  8. var body: some View {
  9. HStack(spacing: 4) {
  10. Text(title)
  11. Button {
  12. showInfo = true
  13. } label: {
  14. Image(systemName: "info.circle")
  15. .foregroundStyle(Color.accentColor)
  16. }
  17. .buttonStyle(.plain)
  18. }
  19. .sheet(isPresented: $showInfo) {
  20. QuickPickInfoSheet(title: title, text: infoText)
  21. }
  22. }
  23. }
  24. private struct QuickPickInfoSheet: View {
  25. let title: String
  26. let text: String
  27. @Environment(\.dismiss) private var dismiss
  28. var body: some View {
  29. NavigationStack {
  30. ScrollView {
  31. Text(text)
  32. .padding()
  33. .frame(maxWidth: .infinity, alignment: .leading)
  34. }
  35. .navigationTitle(title)
  36. .navigationBarTitleDisplayMode(.inline)
  37. .toolbar {
  38. ToolbarItem(placement: .confirmationAction) {
  39. Button("Done") { dismiss() }
  40. }
  41. }
  42. }
  43. .presentationDetents([.medium])
  44. .presentationDragIndicator(.visible)
  45. }
  46. }
  47. extension QuickPickSectionHeader {
  48. static let bolusInfoText = String(localized: """
  49. These buttons show your most-used recent bolus amounts.
  50. They're based on what you've sent before at similar times on similar days — so if you usually give 4 units before breakfast on weekdays, that button will show up on weekday mornings.
  51. Tap a button to fill in the amount. Nothing is sent until you review and confirm.
  52. """)
  53. static let mealInfoText = String(localized: """
  54. These buttons show your most-used recent meals.
  55. They're based on what you've sent before at similar times on similar days — so if you usually send the same breakfast on weekday mornings, it'll appear as an option.
  56. Tap a button to fill in the details. Nothing is sent until you review and confirm.
  57. """)
  58. }