1
0

NavigationSplitView.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /// A view that presents views in two or three columns.
  2. public struct NavigationSplitView<Sidebar: View, MiddleBar: View, Detail: View>: View {
  3. public var body: some View {
  4. SplitView(
  5. sidebar: {
  6. return sidebar
  7. },
  8. detail: {
  9. if MiddleBar.self == EmptyView.self {
  10. detail
  11. } else {
  12. SplitView(
  13. sidebar: {
  14. return content
  15. },
  16. detail: {
  17. return detail
  18. }
  19. )
  20. }
  21. }
  22. )
  23. }
  24. /// The sidebar content.
  25. public var sidebar: Sidebar
  26. /// The middle content.
  27. public var content: MiddleBar
  28. /// The detail content.
  29. public var detail: Detail
  30. /// Creates a three column split view.
  31. ///
  32. /// - Parameters:
  33. /// - sidebar: The sidebar content.
  34. /// - content: The middle content.
  35. /// - detail: The detail content.
  36. public init(
  37. @ViewBuilder sidebar: () -> Sidebar,
  38. @ViewBuilder content: () -> MiddleBar,
  39. @ViewBuilder detail: () -> Detail
  40. ) {
  41. self.sidebar = sidebar()
  42. self.content = content()
  43. self.detail = detail()
  44. }
  45. }
  46. extension NavigationSplitView where MiddleBar == EmptyView {
  47. /// Creates a two column split view.
  48. ///
  49. /// - Parameters:
  50. /// - sidebar: The sidebar content.
  51. /// - detail: The detail content.
  52. public init(
  53. @ViewBuilder sidebar: () -> Sidebar,
  54. @ViewBuilder detail: () -> Detail
  55. ) {
  56. self.sidebar = sidebar()
  57. content = EmptyView()
  58. self.detail = detail()
  59. }
  60. }