GuidePage.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // GuidePage.swift
  3. // LoopKitUI
  4. //
  5. // Created by Pete Schwamb on 2020-03-04.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct GuidePage<Content, ActionAreaContent>: View where Content: View, ActionAreaContent: View {
  10. let content: Content
  11. let actionAreaContent: ActionAreaContent
  12. @Environment(\.horizontalSizeClass) var horizontalSizeClass
  13. public init(@ViewBuilder content: @escaping () -> Content,
  14. @ViewBuilder actionAreaContent: @escaping () -> ActionAreaContent)
  15. {
  16. self.content = content()
  17. self.actionAreaContent = actionAreaContent()
  18. }
  19. public var body: some View {
  20. VStack(spacing: 0) {
  21. List {
  22. if self.horizontalSizeClass == .compact {
  23. Section(header: EmptyView(), footer: EmptyView()) {
  24. self.content
  25. }
  26. } else {
  27. self.content
  28. }
  29. }
  30. .insetGroupedListStyle()
  31. VStack {
  32. self.actionAreaContent
  33. }
  34. .padding(self.horizontalSizeClass == .regular ? .bottom : [])
  35. .background(Color(UIColor.systemBackground).shadow(radius: 5))
  36. }
  37. .edgesIgnoringSafeArea(.bottom)
  38. }
  39. }
  40. struct GuidePage_Previews: PreviewProvider {
  41. static var previews: some View {
  42. GuidePage(content: {
  43. Text("content")
  44. Text("more content")
  45. Image(systemName: "circle")
  46. }) {
  47. Button(action: {
  48. print("Button tapped")
  49. }) {
  50. Text("Action Button")
  51. .actionButtonStyle()
  52. }
  53. }
  54. }
  55. }