Skip to content

Commit 1db5d2c

Browse files
committed
add context to table section constructor with result builder
1 parent b618ff0 commit 1db5d2c

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
@@ -64,8 +64,10 @@ private extension StackCellExampleViewController {
6464
}
6565

6666
// Note that using `UITableViewCell` or `UICollectionViewCell` inside stack is not recommended, but it possible
67-
adapter += TableSection(header: TitleHeaderGenerator(model: "StackView based cells"), footer: EmptyTableFooterGenerator()) {
68-
TableFactory.stack(
67+
adapter += TableSection.create(contextType: TableFactory.self,
68+
header: TitleHeaderGenerator(model: "StackView based cells"),
69+
footer: EmptyTableFooterGenerator()) { it in
70+
it.stack(
6971
model: .build { vStack in
7072
vStack.background(.solid(.rddm))
7173
vStack.style(.init(axis: .vertical,
@@ -89,13 +91,13 @@ private extension StackCellExampleViewController {
8991
it.viewNib(type: TitleTableViewCell.self, model: "3")
9092
}
9193
})
92-
TableFactory.viewClass(type: LabelView.self, model: .build { label in
94+
it.viewClass(type: LabelView.self, model: .build { label in
9395
label.textAlignment(.center)
9496
label.text(.string("Wrapped LabelView"))
9597
label.style(.init(color: .systemBlue, font: .systemFont(ofSize: 16)))
9698
})
97-
TableFactory.cell(type: TitleTableViewCell.self, model: "Cell outside from stack", registerType: .nib)
98-
TableFactory.stack(model: .build { hStack in
99+
it.cell(type: TitleTableViewCell.self, model: "Cell outside from stack", registerType: .nib)
100+
it.stack(model: .build { hStack in
99101
hStack.background(.solid(.systemGreen))
100102
hStack.style(.init(axis: .horizontal,
101103
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)