Skip to content

Commit

Permalink
Ensure we can include multiple tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdifran committed Feb 25, 2023
1 parent 98577e0 commit 3eedde7
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 15 deletions.
8 changes: 5 additions & 3 deletions Sources/AdaptiveTabView/AdaptiveTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public enum AdaptiveTabViewSplitViewKind {

/// A container that displays as a ``TabView`` when the horiontal size class is `.compact`, and displays a ``NavigationSplitView`` when
/// it's `.regular`. This allows for simple support of iPhone and iPad screens in one component.
public struct AdaptiveTabView<TabContentView: Sequence, SidebarExtraContent: View, DefaultContentView: View, DefaultDetailView: View>: View where TabContentView.Element: View, TabContentView.Element: TitleImageProviding {
public struct AdaptiveTabView<TabContent: Sequence, SidebarExtraContent: View, DefaultContentView: View, DefaultDetailView: View>: View where TabContent.Element: TabContentView {

private let appName: String
private let splitViewKind: AdaptiveTabViewSplitViewKind
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContentView
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContent
private let defaultContentBuilder: () -> DefaultContentView
private let defaultDetailBuilder: () -> DefaultDetailView
private let sidebarExtraContentBuilder: () -> SidebarExtraContent
Expand All @@ -57,7 +57,7 @@ public struct AdaptiveTabView<TabContentView: Sequence, SidebarExtraContent: Vie
public init(
appName: String,
splitViewKind: AdaptiveTabViewSplitViewKind = .threeColumn,
@SequenceBuilder tabViews: @escaping (AdaptiveTabViewContainerKind) -> TabContentView,
@SequenceBuilder tabViews: @escaping (AdaptiveTabViewContainerKind) -> TabContent,
@ViewBuilder defaultContent: @escaping () -> DefaultContentView = { EmptyView() },
@ViewBuilder defaultDetail: @escaping () -> DefaultDetailView,
@ViewBuilder sidebarExtraContent: @escaping () -> SidebarExtraContent = { EmptyView() }
Expand Down Expand Up @@ -99,6 +99,8 @@ struct AdaptiveTabView_Previews: PreviewProvider {
static var previews: some View {
AdaptiveTabView(appName: "AdaptiveTabView") { (_) in
PreviewTitleImageProvidingView()
PreviewTitleImageProvidingView()
PreviewTitleImageProvidingView()
} defaultContent: {
Text("Content")
} defaultDetail: {
Expand Down
19 changes: 19 additions & 0 deletions Sources/AdaptiveTabView/Extensions/Either+SwiftUI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Either+SwiftUI.swift
//
//
// Created by Mark DiFranco on 2023-02-25.
//

import SwiftUI
import SequenceBuilder

extension Either: TitleImageProviding where Left: TitleImageProviding, Right: TitleImageProviding {
public var title: String {
fold(left: \.title, right: \.title)
}

public var systemImageName: String {
fold(left: \.systemImageName, right: \.systemImageName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

/// An internal struct used for SwiftUI Previews.
struct PreviewTitleImageProvidingView: View, TitleImageProviding {
struct PreviewTitleImageProvidingView: TabContentView {
let title = "Preview View"
let systemImageName = "doc.text.image"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

struct SidebarItemNavigationLink<Content>: View where Content: View, Content: TitleImageProviding {
struct SidebarItemNavigationLink<Content: TabContentView>: View {

let content: Content

Expand Down
6 changes: 3 additions & 3 deletions Sources/AdaptiveTabView/SidebarLayout/SidebarLayoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import SwiftUI
import SequenceBuilder

struct SidebarLayoutView<TabContentView: Sequence, SidebarExtraContent: View, DefaultContentView: View, DefaultDetailView: View>: View where TabContentView.Element: View, TabContentView.Element: TitleImageProviding {
struct SidebarLayoutView<TabContent: Sequence, SidebarExtraContent: View, DefaultContentView: View, DefaultDetailView: View>: View where TabContent.Element: TabContentView {

private let appName: String
private let splitViewKind: AdaptiveTabViewSplitViewKind
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContentView
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContent
private let defaultContentView: DefaultContentView
private let defaultDetailView: DefaultDetailView
private let sidebarExtraContent: () -> SidebarExtraContent

init(
_ appName: String,
splitViewKind: AdaptiveTabViewSplitViewKind,
@SequenceBuilder tabViewBuilder: @escaping (AdaptiveTabViewContainerKind) -> TabContentView,
@SequenceBuilder tabViewBuilder: @escaping (AdaptiveTabViewContainerKind) -> TabContent,
@ViewBuilder defaultContentBuilder: () -> DefaultContentView,
@ViewBuilder defaultDetailBuilder: () -> DefaultDetailView,
@ViewBuilder sidebarExtraContent: @escaping () -> SidebarExtraContent
Expand Down
6 changes: 3 additions & 3 deletions Sources/AdaptiveTabView/SidebarLayout/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import SwiftUI
import SequenceBuilder

struct SidebarView<TabContentView: Sequence, SidebarExtraContent: View>: View where TabContentView.Element: View, TabContentView.Element: TitleImageProviding {
struct SidebarView<TabContent: Sequence, SidebarExtraContent: View>: View where TabContent.Element: TabContentView {

private let appName: String
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContentView
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContent
private let sidebarExtraContent: () -> SidebarExtraContent

init(
_ appName: String,
@SequenceBuilder tabViewBuilder: @escaping (AdaptiveTabViewContainerKind) -> TabContentView,
@SequenceBuilder tabViewBuilder: @escaping (AdaptiveTabViewContainerKind) -> TabContent,
@ViewBuilder sidebarExtraContent: @escaping () -> SidebarExtraContent
) {
self.appName = appName
Expand Down
6 changes: 3 additions & 3 deletions Sources/AdaptiveTabView/TabLayout/TabLayoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import SwiftUI
import SequenceBuilder

struct TabLayoutView<TabContentView: Sequence>: View where TabContentView.Element: View, TabContentView.Element: TitleImageProviding {
struct TabLayoutView<TabContent: Sequence>: View where TabContent.Element: TabContentView {

private let tabViews: TabContentView
private let tabViews: TabContent

init(
@SequenceBuilder _ tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContentView
@SequenceBuilder _ tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContent
) {
self.tabViews = tabViewBuilder(.tabView)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AdaptiveTabView/TabLayout/TabNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

struct TabNavigationView<Content: View>: View where Content: View, Content: TitleImageProviding {
struct TabNavigationView<Content: TabContentView>: View {

private let content: Content

Expand Down
11 changes: 11 additions & 0 deletions Sources/AdaptiveTabView/Typealiases/TabContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// TabContentView.swift
//
//
// Created by Mark DiFranco on 2023-02-25.
//

import SwiftUI

/// A SwiftUI ``View`` that also provides data for a tab item / sidebar item.
public typealias TabContentView = View & TitleImageProviding

0 comments on commit 3eedde7

Please sign in to comment.