forked from ole/swiftui-view-lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRootView.swift
92 lines (85 loc) · 2.63 KB
/
RootView.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
import SwiftUI
struct RootView: View {
@State private var columnVisibility: NavigationSplitViewVisibility = .doubleColumn
var body: some View {
NavigationSplitView(columnVisibility: $columnVisibility) {
Sidebar()
} detail: {
Text("Select an item in the sidebar.")
}
}
}
struct Sidebar: View {
@State private var selection: CaseStudy? = nil
var body: some View {
List {
ForEach(categories) { section in
Section {
ForEach(section.elements) { caseStudy in
NavigationLink(value: caseStudy.id) {
VStack(alignment: .leading, spacing: 4) {
Text(caseStudy.label)
.lineLimit(nil)
if let description = caseStudy.description {
Text(description)
.font(.callout)
.foregroundStyle(.secondary)
.lineLimit(nil)
}
}
}
}
} header: {
Text(section.label)
}
}
}
.navigationTitle("SwiftUI View Lifecycle")
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.navigationDestination(for: CaseStudy.ID.self) { id in
MainContent(caseStudyID: id)
}
}
}
struct MainContent: View {
var caseStudyID: CaseStudy.ID
var body: some View {
switch caseStudyID {
case .ifElse:
CaseStudyIfElse()
case .switch:
CaseStudySwitch()
case .id:
CaseStudyIDModifier()
case .opacity:
CaseStudyOpacity()
case .scrollViewStatic:
CaseStudyScrollViewStatic()
case .scrollViewDynamic:
CaseStudyScrollViewDynamic()
case .listDynamic:
CaseStudyListDynamic()
case .listStatic:
CaseStudyListStatic()
case .lazyVStack:
CaseStudyLazyVStack()
case .lazyVGrid:
CaseStudyLazyVGrid()
case .navigationStack:
#if os(macOS)
CaseStudyNavigationStackMac()
#else
CaseStudyNavigationStack()
#endif
case .tabView:
CaseStudyTabView()
}
}
}
struct RootView_Previews: PreviewProvider {
static var previews: some View {
RootView()
}
}