Skip to content

Commit c1d9f20

Browse files
committed
add context to table section constructor with result builder
1 parent 9e452aa commit c1d9f20

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Example/ReactiveDataDisplayManager/Table/StackCellExampleViewController/StackCellExampleViewController.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ private extension StackCellExampleViewController {
6565
}
6666

6767
// Note that using `UITableViewCell` or `UICollectionViewCell` inside stack is not recommended, but it possible
68-
adapter += TableSection(header: TitleHeaderGenerator(model: "StackView based cells"), footer: EmptyTableFooterGenerator()) {
69-
TableFactory.stack(
68+
adapter += TableSection.create(contextType: TableFactory.self,
69+
header: TitleHeaderGenerator(model: "StackView based cells"),
70+
footer: EmptyTableFooterGenerator()) { it in
71+
it.stack(
7072
model: .build { vStack in
7173
vStack.background(.solid(.rddm))
7274
vStack.style(.init(axis: .vertical,
@@ -90,13 +92,13 @@ private extension StackCellExampleViewController {
9092
it.viewNib(type: TitleTableViewCell.self, model: "3")
9193
}
9294
})
93-
TableFactory.viewClass(type: LabelView.self, model: .build { label in
95+
it.viewClass(type: LabelView.self, model: .build { label in
9496
label.textAlignment(.center)
9597
label.text(.string("Wrapped LabelView"))
9698
label.style(.init(color: .systemBlue, font: .systemFont(ofSize: 16)))
9799
})
98-
TableFactory.cell(type: TitleTableViewCell.self, model: "Cell outside from stack", registerType: .nib)
99-
TableFactory.stack(model: .build { hStack in
100+
it.cell(type: TitleTableViewCell.self, model: "Cell outside from stack", registerType: .nib)
101+
it.stack(model: .build { hStack in
100102
hStack.background(.solid(.systemGreen))
101103
hStack.style(.init(axis: .horizontal,
102104
spacing: 0,

Source/Models/Section.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public struct Section<GeneratorType, HeaderGeneratorType, FooterGeneratorType> {
3939
self.init(generators: generators(), header: header, footer: footer)
4040
}
4141

42+
/// Context based generic section for tables and collections with @resultBuilder support
43+
public static func create<Context>(contextType: Context.Type,
44+
header: HeaderGeneratorType,
45+
footer: FooterGeneratorType,
46+
@GeneratorsBuilder<GeneratorType> generators: (Context.Type) -> [GeneratorType]) -> Self {
47+
Self(generators: generators(Context.self), header: header, footer: footer)
48+
}
49+
4250
}
4351

4452
public extension Section {

0 commit comments

Comments
 (0)