-
Notifications
You must be signed in to change notification settings - Fork 11
/
NestedListView.swift
64 lines (54 loc) · 1.42 KB
/
NestedListView.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
import SwiftUI
import SherlockForms
/// Hierarchical `SwiftUI.List` example.
struct NestedListView: View, SherlockView
{
@State public private(set) var searchText: String = ""
@State private var items: [ListItem] = ListItem.presetItems
var body: some View
{
SherlockForm(searchText: $searchText) {
nestedList(
data: items,
rowContent: { item in
Text("\(item.content)")
}
)
}
.navigationBarTitleDisplayMode(.inline)
.formCellCopyable(true)
}
}
// MARK: - Previews
struct NestedListView_Previews: PreviewProvider
{
static var previews: some View
{
NestedListView()
}
}
// MARK: - Private
private struct ListItem: NestedListItem, Identifiable
{
let content: String
var children: [ListItem]?
var id: String { content }
init(content: String, children: [ListItem]?)
{
self.content = content
self.children = children
}
static let presetItems: [ListItem] = (0 ... 3).map { i in
ListItem(
content: "Row \(i)",
children: (0 ... 3).map { j in
ListItem(
content: "Row \(i)-\(j)",
children: (0 ... 3).map { k in
ListItem(content: "Row \(i)-\(j)-\(k)", children: nil)
}
)
}
)
}
}