-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04-LoadAndPull.swift
65 lines (59 loc) · 1.92 KB
/
04-LoadAndPull.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
//
// 04-LoadAndPull.swift
// Example
//
// Created by linhey on 1/2/25.
//
import SwiftUI
import SectionUI
/**
# 加载更多数据 / 重置数据
*/
struct LoadAndPullView: View {
let colors = [UIColor.red, .green, .blue, .yellow, .orange]
@State
var refreshableTime = 0
@State
var section = TextCell
.wrapperToSingleTypeSection()
var body: some View {
SKUIController {
SKCollectionViewController()
.reloadSections(section)
.refreshable {
refreshableTime = 0
section
.setHeader(TextReusableView.self,
model: .init(text: "header - \(refreshableTime)",
color: .purple))
.config(models: (0...1).map({ idx in
TextCell.Model(text: "第 \(refreshableTime) 批数据",
color: colors[idx % colors.count])
}))
}
}
.ignoresSafeArea()
.overlay(alignment: .bottom) {
Button {
refreshableTime += 1
section
.setHeader(TextReusableView.self,
model: .init(text: "header - \(refreshableTime)",
color: .purple))
.append((0...1).map({ idx in
TextCell.Model(text: "第 \(refreshableTime) 批数据",
color: colors[idx % colors.count])
}))
} label: {
Text("点击加载更多")
.padding()
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.background(.blue)
}
}
}
}
#Preview {
LoadAndPullView()
}