-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
116 lines (108 loc) · 3.41 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// ContentView.swift
// Test-Navigation-Layout
//
// Created by Peter C. Allport on 11/24/22.
//
import SwiftUI
struct ContentView: View {
@State private var isViewOneActive = true
var body: some View {
NavigationView {
// Sidebar
List {
NavigationLink(destination: List {
Text("View One (2nd Column)")
}
.toolbar {
ToolbarItem {
Button {} label: {
Image(systemName: "plus")
.help("New Thing")
}
}
},
isActive: $isViewOneActive, label: {
Text("View One")
})
NavigationLink(destination: {
List {
Text("View Two (2nd Column)")
}
.toolbar {
ToolbarItem {
Button {} label: {
Image(systemName: "plus")
.help("New Thing")
}
}
}
}) {
Text("View Two")
}
}
.toolbar {
ToolbarItem {
Button {
toggleSidebar()
} label: {
Image(systemName: "sidebar.left")
.help("Toggle Sidebar")
}
}
}
.listStyle(SidebarListStyle())
// SwiftUI needs initial view .toolbar(s) defined within
// NavigationView() in order to create correct layout.
List {}
.frame(minWidth: 300, idealWidth: 300, maxWidth: .infinity, maxHeight: .infinity)
.toolbar {
ToolbarItem {
Button {} label: {
Image(systemName: "plus")
.help("New Thing")
}
}
}
if isViewOneActive {
List {
Text("View One (3rd Column)")
}
.toolbar {
Button {} label: {
Image(systemName: "pencil")
.help("Edit Thing")
}
.disabled(true)
}
} else {
List {
Text("View Two (3rd Column)")
}
.toolbar {
Button {} label: {
Image(systemName: "pencil")
.help("Edit Thing")
}
.disabled(true)
}
}
}
// Change title depending on current view
.navigationTitle(isViewOneActive ? "View One" : "View Two")
}
func toggleSidebar() {
#if os(macOS)
NSApp.keyWindow?.firstResponder?
.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)),
with: nil)
#endif
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
ContentView()
}
}
}