Skip to content

Commit

Permalink
Add example app, tab identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdifran committed Mar 13, 2023
1 parent cc6f378 commit e354496
Show file tree
Hide file tree
Showing 23 changed files with 768 additions and 13 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "sequencebuilder",
"kind" : "remoteSourceControl",
"location" : "https://github.com/andtie/SequenceBuilder.git",
"state" : {
"revision" : "54d3d1eff31a7e35122f616840fff11899ea85b4",
"version" : "0.0.7"
}
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// AdaptiveTabExampleApp.swift
// AdaptiveTabExample
//
// Created by Mark DiFranco on 2023-03-11.
//

import SwiftUI
import AdaptiveTabView

@main
struct AdaptiveTabExampleApp: App {
@State private var selectedTab = iPhoneTabView.identifier

var body: some Scene {
WindowGroup {
AdaptiveTabView(
appName: "Example",
selectedTab: $selectedTab
) { (containerKind) in
MacOSTabView()
iPhoneTabView()
AppleWatchTabView()
} defaultDetail: {
ContentView(title: "Empty Details")
} sidebarExtraContent: {
SidebarView()
}
.navigationSplitViewStyle(.automatic)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
23 changes: 23 additions & 0 deletions Example/AdaptiveTabExample/AdaptiveTabExample/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ContentView.swift
// AdaptiveTabExample
//
// Created by Mark DiFranco on 2023-03-12.
//

import SwiftUI

struct ContentView: View {
let title: String

var body: some View {
Text(title)
.navigationTitle(title)
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(title: "Hello World")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// SidebarView.swift
// AdaptiveTabExample
//
// Created by Mark DiFranco on 2023-03-13.
//

import SwiftUI
import AdaptiveTabView

struct SidebarView: View {
let identifiers = [1, 2, 3, 4, 5]

var body: some View {
Group {
Section("Folders") {
ForEach(identifiers, id: \.self) { (identifier) in
NavigationLink {
ContentView(title: "Folder \(identifier)")
} label: {
Label("Folder \(identifier)", systemImage: "folder")
}
.tag(TabIdentifier("Folder\(identifier)"))
}
}
}
}
}

struct SidebarView_Previews: PreviewProvider {
static var previews: some View {
SidebarView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// AppleWatchTabView.swift
// AdaptiveTabExample
//
// Created by Mark DiFranco on 2023-03-11.
//

import SwiftUI
import AdaptiveTabView

extension AppleWatchTabView {
static let identifier = TabIdentifier("AppleWatchTabView")
}

struct AppleWatchTabView: View, TitleImageProviding {
let title = "Apple Watches"
let systemImageName = "applewatch"
let id = AppleWatchTabView.identifier

private let watches = [
"Apple Watch SE",
"Apple Watch Ultra",
"Apple Watch Series 8",
"Apple Watch Series 7"
]

var body: some View {
List(watches, id: \.self) { (watch) in
NavigationLink(watch) {
ContentView(title: watch)
}
}
.listStyle(.insetGrouped)
}
}

struct AppleWatchTabView_Previews: PreviewProvider {
static var previews: some View {
AppleWatchTabView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// MacOSTabView.swift
// AdaptiveTabExample
//
// Created by Mark DiFranco on 2023-03-11.
//

import SwiftUI
import AdaptiveTabView

extension MacOSTabView {
static let identifier = TabIdentifier("MacOSTabView")
}

struct MacOSTabView: View, TitleImageProviding {
let title = "macOS Versions"
let systemImageName = "laptopcomputer"
let id = MacOSTabView.identifier

private let versions = [
"Ventura",
"Monterey",
"Big Sur",
"Catalina",
"Mojave"
]

var body: some View {
List(versions, id: \.self) { (version) in
NavigationLink(version) {
ContentView(title: version)
}
}
.listStyle(.insetGrouped)
}
}

struct FirstTabView_Previews: PreviewProvider {
static var previews: some View {
MacOSTabView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// iPhoneTabView.swift
// AdaptiveTabExample
//
// Created by Mark DiFranco on 2023-03-11.
//

import SwiftUI
import AdaptiveTabView

extension iPhoneTabView {
static let identifier = TabIdentifier("iPhoneTabView")
}

struct iPhoneTabView: View, TitleImageProviding {
let title = "iPhones"
let systemImageName = "iphone"
let id = iPhoneTabView.identifier

private let phones = [
"iPhone 14 Pro Max",
"iPhone 13 mini",
"iPhone 12 Pro",
"iPhone 11"
]

var body: some View {
List(phones, id: \.self) { (phone) in
NavigationLink(phone) {
ContentView(title: phone)
}
}
.listStyle(.insetGrouped)
}
}

struct iPhoneTabView_Previews: PreviewProvider {
static var previews: some View {
iPhoneTabView()
}
}
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ Here's an example of how it can be used:
```swift
@main
struct MyApp: App {
@State private var selectedTab = MyFirstTab.identifier

var body: some Scene {
WindowGroup {
AdaptiveTabView(appName: "My App") {
AdaptiveTabView(
appName: "My App",
selectedTab: selectedTab
) {
MyFirstTab()
MySecondTab()
MyThirdTab()
Expand All @@ -33,9 +38,14 @@ struct MyApp: App {
```

```swift
extension MyFirstTab {
static let identifier = TabIdentifier("MyFirstTab")
}

struct MyFirstTab: View, TitleImageProviding {
let title = "My First Tab"
let systemImageName = "1.square"
let id = MyFirstTab.identifier

var body: some View {
...
Expand Down
5 changes: 3 additions & 2 deletions Sources/AdaptiveTabView/AdaptiveTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum AdaptiveTabViewSplitViewKind {
public struct AdaptiveTabView<TabContent: Sequence, SidebarExtraContent: View, DefaultContentView: View, DefaultDetailView: View>: View where TabContent.Element: TabContentView {

private let appName: String
private let selectedTab: Binding<UInt>?
private let selectedTab: Binding<TabIdentifier>?
private let splitViewKind: AdaptiveTabViewSplitViewKind
private let tabViewBuilder: (AdaptiveTabViewContainerKind) -> TabContent
private let defaultContentBuilder: () -> DefaultContentView
Expand All @@ -58,7 +58,7 @@ public struct AdaptiveTabView<TabContent: Sequence, SidebarExtraContent: View, D
/// is ``AdaptiveTabViewContainerKind.sidebarView``.
public init(
appName: String,
selectedTab: Binding<UInt>? = nil,
selectedTab: Binding<TabIdentifier>? = nil,
splitViewKind: AdaptiveTabViewSplitViewKind = .threeColumn,
@SequenceBuilder tabViews: @escaping (AdaptiveTabViewContainerKind) -> TabContent,
@ViewBuilder defaultContent: @escaping () -> DefaultContentView = { EmptyView() },
Expand Down Expand Up @@ -87,6 +87,7 @@ public struct AdaptiveTabView<TabContent: Sequence, SidebarExtraContent: View, D
default:
SidebarLayoutView(
appName,
selectedTab: selectedTab,
splitViewKind: splitViewKind,
tabViewBuilder: tabViewBuilder,
defaultContentBuilder: defaultContentBuilder,
Expand Down
5 changes: 5 additions & 0 deletions Sources/AdaptiveTabView/Extensions/Either+SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import SwiftUI
import SequenceBuilder

extension Either: TitleImageProviding where Left: TitleImageProviding, Right: TitleImageProviding {

public var id: TabIdentifier {
fold(left: \.id, right: \.id)
}

public var title: String {
fold(left: \.title, right: \.title)
}
Expand Down
22 changes: 22 additions & 0 deletions Sources/AdaptiveTabView/Identifiers/TabIdentifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// TabIdentifier.swift
//
//
// Created by Mark DiFranco on 2023-03-12.
//

import Foundation

// MARK: - TabIdentifier

public struct TabIdentifier: Identifiable, Hashable, Equatable, ExpressibleByStringLiteral {
public let id: String

public init(_ id: String) {
self.id = id
}

public init(stringLiteral value: String) {
id = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
struct PreviewTitleImageProvidingView: TabContentView {
let title = "Preview View"
let systemImageName = "doc.text.image"
let id = TabIdentifier("PreviewTitleImageProvidingView")

var body: some View {
NavigationLink {
Expand Down
Loading

0 comments on commit e354496

Please sign in to comment.