-
Notifications
You must be signed in to change notification settings - Fork 1
/
05-SubscribeDataWithCombine.swift
49 lines (44 loc) · 1.25 KB
/
05-SubscribeDataWithCombine.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
//
// SubscribeDataView.swift
// Example
//
// Created by linhey on 1/2/25.
//
import SectionUI
import SwiftUI
import Combine
struct SubscribeDataWithCombineView: View {
let colors = [UIColor.red, .green, .blue, .yellow, .orange]
@State
var subject = CurrentValueSubject<[TextCell.Model], Never>.init([])
@State
var section = TextCell
.wrapperToSingleTypeSection()
var body: some View {
SKUIController {
SKCollectionViewController().reload(section)
}
.task {
section.subscribe(models: subject)
}
.ignoresSafeArea()
.overlay(alignment: .bottom) {
Button {
subject.value += ((subject.value.count)...(subject.value.count + 2))
.map({ idx in
TextCell.Model(text: "第 \(idx) 行",
color: colors[idx % colors.count])
})
} label: {
Text("点击加载更多")
.padding()
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.background(.blue)
}
}
}
}
#Preview {
SubscribeDataWithCombineView()
}