-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02-MultipleSection.swift
70 lines (61 loc) · 1.94 KB
/
02-MultipleSection.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
//
// 02-MultipleSection.swift
// Example
//
// Created by linhey on 1/2/25.
//
import SwiftUI
import SectionUI
/**
# 多组视图
*/
struct MultipleSectionView: View {
let colors = [UIColor.red, .green, .blue, .yellow, .orange]
@State
var section1 = TextCell
.wrapperToSingleTypeSection()
.onCellAction(.willDisplay) { context in
context.view().desc(context.type.description)
}
.onCellAction(.didEndDisplay) { context in
context.view().desc(context.type.description)
}
.onCellAction(.selected) { context in
context.view().desc(context.type.description)
}
.onCellAction(.deselected) { context in
context.view().desc(context.type.description)
}
@State
var section2 = TextCell
.wrapperToSingleTypeSection()
.setSectionStyle(\.sectionInset, UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0))
.onCellAction(.willDisplay) { context in
context.view().desc(context.type.description)
}
.onCellAction(.didEndDisplay) { context in
context.view().desc(context.type.description)
}
.onCellAction(.selected) { context in
context.view().desc(context.type.description)
}
.onCellAction(.deselected) { context in
context.view().desc(context.type.description)
}
var body: some View {
SKPreview.sections {
[section1, section2]
}.onAppear {
section1.config(models: (0...4).map({ idx in
TextCell.Model(text: "第 1 组, 第 \(idx) 行", color: colors[idx % colors.count])
}))
section2.config(models: (0...4).map({ idx in
TextCell.Model(text: "第 2 组, 第 \(idx) 行", color: colors[idx % colors.count])
}))
}
.ignoresSafeArea()
}
}
#Preview {
MultipleSectionView()
}