Skip to content

Commit a394ad0

Browse files
committed
add extension to imporve syntax
1 parent 6a0f777 commit a394ad0

File tree

2 files changed

+69
-36
lines changed

2 files changed

+69
-36
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// UITableViewCell+TableContext.swift
3+
// ReactiveDataDisplayManager
4+
//
5+
// Created by Никита Коробейников on 26.07.2023.
6+
//
7+
8+
import UIKit
9+
import ReactiveDataDisplayManager
10+
11+
public extension ConfigurableItem where Self: RegistrationTypeProvider {
12+
13+
static func build<Context: BuilderContext>(in ctx: Context.Type, with model: Model) -> Context.GeneratorType {
14+
ctx.gen(Self.self, model: model)
15+
}
16+
17+
}
18+
19+
public extension ConfigurableItem where Self: RegistrationTypeProvider, Self: UITableViewCell {
20+
21+
static func build<Context: BuilderContext>(in ctx: Context.Type, with model: Model) -> Context.GeneratorType where Context.ViewType == UITableViewCell {
22+
ctx.gen(Self.self, model: model)
23+
}
24+
25+
}
26+
27+
public extension ConfigurableItem where Self: RegistrationTypeProvider, Self: UICollectionViewCell {
28+
29+
static func build<Context: BuilderContext>(in ctx: Context.Type, with model: Model) -> Context.GeneratorType where Context.ViewType == UICollectionViewCell {
30+
ctx.gen(Self.self, model: model)
31+
}
32+
33+
}
34+

Example/ReactiveDataDisplayManager/Table/StackCellExampleViewController/StackCellExampleViewController.swift

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,56 +66,55 @@ private extension StackCellExampleViewController {
6666

6767
// Note that using `UITableViewCell` or `UICollectionViewCell` inside stack is not recommended, but it possible
6868
adapter += TableSection.create(header: TitleHeaderGenerator(model: "StackView based cells"),
69-
footer: EmptyTableFooterGenerator()) { it in
70-
it.stack(
71-
model: .build { vStack in
72-
vStack.background(.solid(.rddm))
73-
vStack.style(.init(axis: .vertical,
74-
spacing: 8,
75-
alignment: .fill,
76-
distribution: .fill))
77-
vStack.children { it in
78-
it.gen(TitleTableViewCell.self, model: "1")
79-
it.gen(TitleTableViewCell.self, model: "2")
80-
it.stack(model: .build { hStack in
81-
hStack.background(.solid(.systemBlue))
82-
hStack.style(.init(axis: .horizontal,
83-
spacing: 4,
84-
alignment: .fill,
85-
distribution: .fillEqually))
86-
hStack.children { it in
87-
it.gen(TitleTableViewCell.self, model: "4")
88-
it.gen(TitleTableViewCell.self, model: "5")
89-
}
90-
})
91-
it.gen(TitleTableViewCell.self, model: "3")
92-
}
93-
})
94-
it.gen(LabelView.self, model: .build { label in
69+
footer: EmptyTableFooterGenerator()) { ctx in
70+
StackView.build(in: ctx, with: .build { vStack in
71+
vStack.background(.solid(.rddm))
72+
vStack.style(.init(axis: .vertical,
73+
spacing: 8,
74+
alignment: .fill,
75+
distribution: .fill))
76+
vStack.children { ctx in
77+
TitleTableViewCell.build(in: ctx, with: "1")
78+
TitleTableViewCell.build(in: ctx, with: "2")
79+
StackView.build(in: ctx, with: .build { hStack in
80+
hStack.background(.solid(.systemBlue))
81+
hStack.style(.init(axis: .horizontal,
82+
spacing: 4,
83+
alignment: .fill,
84+
distribution: .fillEqually))
85+
hStack.children { ctx in
86+
TitleTableViewCell.build(in: ctx, with: "4")
87+
TitleTableViewCell.build(in: ctx, with: "5")
88+
}
89+
})
90+
TitleTableViewCell.build(in: ctx, with: "3")
91+
}
92+
})
93+
LabelView.build(in: ctx, with: .build { label in
9594
label.textAlignment(.center)
9695
label.text(.string("Wrapped LabelView"))
9796
label.style(.init(color: .systemBlue, font: .systemFont(ofSize: 16)))
9897
})
99-
it.gen(TitleTableViewCell.self, model: "Cell outside from stack")
100-
it.stack(model: .build { hStack in
98+
// TitleTableViewCell.build(in: ctx, with: "Cell outside from stack")
99+
StackView.build(in: ctx, with: .build { hStack in
101100
hStack.background(.solid(.systemGreen))
102101
hStack.style(.init(axis: .horizontal,
103102
spacing: 0,
104103
alignment: .fill,
105104
distribution: .fillEqually))
106-
hStack.children { it in
107-
it.gen(TitleTableViewCell.self, model: "6")
108-
it.stack(model: .build { vStack in
105+
hStack.children { ctx in
106+
TitleTableViewCell.build(in: ctx, with: "6")
107+
StackView.build(in: ctx, with: .build { vStack in
109108
vStack.background(.solid(.systemPink))
110109
vStack.style(.init(axis: .vertical,
111110
spacing: 20,
112111
alignment: .fill,
113112
distribution: .fillEqually))
114-
vStack.children { it in
115-
it.gen(TitleTableViewCell.self, model: "7")
116-
it.gen(TitleTableViewCell.self, model: "8")
117-
it.gen(TitleTableViewCell.self, model: "9")
118-
it.gen(TitleTableViewCell.self, model: "10")
113+
vStack.children { ctx in
114+
TitleTableViewCell.build(in: ctx, with: "7")
115+
TitleTableViewCell.build(in: ctx, with: "8")
116+
TitleTableViewCell.build(in: ctx, with: "9")
117+
TitleTableViewCell.build(in: ctx, with: "10")
119118
}
120119
})
121120
}

0 commit comments

Comments
 (0)