-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationSplitView_Example.swift
59 lines (45 loc) · 1.38 KB
/
NavigationSplitView_Example.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
//
// NavigationSplitView_Example.swift
// SwiftUI-Components-Library
//
// Created by msz on 2022/12/05.
//
import SwiftUI
struct NavigationSplitView_Example: View {
@State private var selectedMenuIndex: Int? = 0
var body: some View {
NavigationSplitView {
NavigationSplitView_Example_MenuBar(selectedMenuIndex: $selectedMenuIndex)
.navigationTitle("Menu")
} detail: {
Text("Currently selected \(selectedMenuIndex ?? 0)")
}
}
}
struct MenuOption: Identifiable {
var id: String {
return menuTitle
}
var menuIndex: Int
var menuTitle: String
}
struct NavigationSplitView_Example_MenuBar: View {
@Binding var selectedMenuIndex: Int?
static let menuOptions: [MenuOption] = [
.init(menuIndex: 0, menuTitle: "Menu 0"),
.init(menuIndex: 1, menuTitle: "Menu 1"),
.init(menuIndex: 2, menuTitle: "Menu 2"),
.init(menuIndex: 3, menuTitle: "Menu 3")
]
var body: some View {
List(NavigationSplitView_Example_MenuBar.menuOptions, selection: $selectedMenuIndex) { option in
Text(option.menuTitle)
.tag(option.menuIndex)
}
}
}
struct NavigationSplitView_Example_Previews: PreviewProvider {
static var previews: some View {
NavigationSplitView_Example()
}
}