• This repository has been archived on 02/Oct/2022
  • Stars
    star
    125
  • Rank 277,400 (Top 6 %)
  • Language
    Swift
  • Created over 3 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal example of three-column navigation for iPad and macOS using SwiftUI

Triple Trouble

A minimal example of three-column navigation for iPad and macOS using SwiftUI.

See the post for more info.

WARNING: This solution requires Big Sur.

Code

import SwiftUI

@main
struct TestSidebarApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        // Uncomment to hide title
        // .windowToolbarStyle(UnifiedWindowToolbarStyle(showsTitle: false))
        .commands {
            SidebarCommands()
        }
    }
}

struct ContentView: View {

    var body: some View {
        NavigationView {
            SidebarView()
            Text("No Sidebar Selection")
            Text("No Message Selection")
        }
    }
}

struct SidebarView: View {
    @State private var isDefaultItemActive = true

    var body: some View {
        let list = List {
            Text("Favorites")
                .font(.caption)
                .foregroundColor(.secondary)
            NavigationLink(destination: IndoxView(), isActive: $isDefaultItemActive) {
                Label("Inbox", systemImage: "tray.2")
            }
            NavigationLink(destination: SentView()) {
                Label("Sent", systemImage: "paperplane")
            }
        }
        .listStyle(SidebarListStyle())

        #if os(macOS)
        list.toolbar {
            Button(action: toggleSidebar) {
                Image(systemName: "sidebar.left")
            }
        }
        #else
        list
        #endif
    }
}

#if os(macOS)
private func toggleSidebar() {
    NSApp.keyWindow?.firstResponder?
        .tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
}
#endif

struct IndoxView: View {
    var body: some View {
        List(Array(0...100).map(String.init), id: \.self) { message in
            NavigationLink(destination: MessageDetailsView(message: message)) {
                Text(message)
            }
        }
        .navigationTitle("Inbox")
        .toolbar {
            Button(action: { /* Open filters */ }) {
                Image(systemName: "line.horizontal.3.decrease.circle")
            }
        }
    }
}

struct SentView: View {
    var body: some View {
        Text("No Sent Messages")
            .navigationTitle("Sent")
            .toolbar {
                Button(action: {}) {
                    Image(systemName: "line.horizontal.3.decrease.circle")
                }
            }
    }
}

struct MessageDetailsView: View {
    let message: String

    var body: some View {
        Text("Details for \(message)")
            .toolbar {
                Button(action: {}) {
                    Image(systemName: "square.and.arrow.up")
                }
            }
    }
}

Screenshot


Screen Shot 2021-02-15 at 14 38 54


Screen Shot 2021-02-15 at 14 35 30

More Repositories

1

Nuke

Image loading system
Swift
7,830
star
2

Pulse

Network Logger for Apple platforms
Swift
5,914
star
3

DFImageManager

Image loading, processing, caching and preheating
Objective-C
1,182
star
4

Get

Web API client built using async/await
Swift
896
star
5

Preheat

Automates prefetching of content in UITableView and UICollectionView
Swift
630
star
6

PulsePro

A macOS app for viewing logs from Pulse
Swift
485
star
7

Align

Intuitive and powerful Auto Layout library
Swift
352
star
8

Future

Streamlined Future<Value, Error> implementation
Swift
318
star
9

FetchImage

Makes it easy to download images using Nuke and display them in SwiftUI apps
Swift
212
star
10

Arranged

Open source replacement of UIStackView for iOS 8 (100% layouts supported)
Swift
209
star
11

Regex

Open source regex engine
Swift
202
star
12

Formatting

Swift
177
star
13

VPN

Sample custom VPN client/server in Swift
Swift
169
star
14

DFCache

Composite LRU cache with fast metadata using UNIX extended file attributes
Objective-C
162
star
15

RxNuke

RxSwift extensions for Nuke
Swift
149
star
16

CreateAPI

Delightful code generator for OpenAPI specs
Swift
142
star
17

SwiftSQL

Swift API for SQLite
Swift
131
star
18

Stacks

A micro UIStackView convenience API inspired by SwiftUI
Swift
73
star
19

Nuke-FLAnimatedImage-Plugin

FLAnimatedImage plugin for Nuke
Swift
53
star
20

RxUI

Auto-binding for RxSwift inspired by SwiftUI
Swift
42
star
21

Nuke-Alamofire-Plugin

Alamofire plugin for Nuke
Swift
39
star
22

DFJPEGTurbo

Objective-C libjpeg-turbo wrapper
C
33
star
23

NukeDemo

Nuke Demo
Swift
30
star
24

ImagePublisher

Combine publishers for Nuke
Swift
25
star
25

articles

Articles for kean.github.io
18
star
26

URLQueryEncoder

URL query encoder with support for all OpenAPI serialization options
Swift
17
star
27

NukeUI

Lazy image loading for Apple platforms: SwiftUI, UIKit, AppKit
Swift
15
star
28

NukeBuilder

A fun and convenient way to use Nuke
Swift
14
star
29

ScrollViewPrefetcher

Prefetching for SwiftUI
Swift
14
star
30

PulseLogHandler

SwiftLog Extension for Pulse
Swift
12
star
31

HTTPHeaders

Parsing Simple HTTP Headers
Swift
11
star
32

OctoKit

GitHub API client built with Fuse
Swift
8
star
33

PulseApps

Base Pulse macOS and iOS apps and a few demo projects
Swift
7
star