SettingDescription.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // SettingDescription.swift
  3. // LoopKitUI
  4. //
  5. // Created by Michael Pangburn on 4/15/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct SettingDescription<InformationalContent: View>: View {
  10. var text: Text
  11. var informationalContent: InformationalContent
  12. @State var displayHelpPage: Bool = false
  13. public init(
  14. text: Text,
  15. @ViewBuilder informationalContent: @escaping () -> InformationalContent
  16. ) {
  17. self.text = text
  18. self.informationalContent = informationalContent()
  19. }
  20. public var body: some View {
  21. HStack(spacing: 8) {
  22. text
  23. .font(.callout)
  24. .foregroundColor(Color(.secondaryLabel))
  25. .fixedSize(horizontal: false, vertical: true)
  26. Spacer()
  27. infoButton
  28. .sheet(isPresented: $displayHelpPage) {
  29. NavigationView {
  30. self.informationalContent
  31. }
  32. }
  33. }
  34. }
  35. private var infoButton: some View {
  36. Button(
  37. action: {
  38. self.displayHelpPage = true
  39. },
  40. label: {
  41. Image(systemName: "info.circle")
  42. .font(.system(size: 25))
  43. .foregroundColor(.accentColor)
  44. }
  45. )
  46. .padding(.trailing, 4)
  47. }
  48. }