Skip to content

Commit 8779dbc

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

File tree

9 files changed

+70
-62
lines changed

9 files changed

+70
-62
lines changed

Components/Sources/Collection/Extensions/CollectionContext+CollectionWrappedCell.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ extension CollectionContext: BuilderContext {
1616

1717
// TODO: - add support for other types of generators or make (decorated generator)
1818

19-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ReactiveDataDisplayManager.ConfigurableItem, Item : ReactiveDataDisplayManager.RegistrationTypeProvider {
19+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ConfigurableItem,
20+
Item: RegistrationTypeProvider {
2021
Item.rddm.collectionGenerator(with: model, and: Item.prefferedRegistration)
2122
}
2223

23-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ViewType, Item : ConfigurableItem, Item : RegistrationTypeProvider {
24+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ViewType,
25+
Item: ConfigurableItem,
26+
Item: RegistrationTypeProvider {
2427
Item.rddm.baseGenerator(with: model, and: Item.prefferedRegistration)
2528
}
2629

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ConfigurableItem+BuilderContext.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+
}

Components/Sources/Common/Extensions/ConfigurableItem+Context.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

Components/Sources/Common/Views/MessageView.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ extension MessageView: ConfigurableItem {
112112
return model
113113
})
114114
}
115-
115+
116116
/// To set it to **false**, dataDetection and tapHandler must be nil
117117
public static func selectable(_ selectable: Bool) -> Property {
118118
.init(closure: { model in
@@ -292,7 +292,10 @@ private extension MessageView {
292292

293293
extension MessageView: UITextViewDelegate {
294294

295-
public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
295+
public func textView(_ textView: UITextView,
296+
shouldInteractWith URL: URL,
297+
in characterRange: NSRange,
298+
interaction: UITextItemInteraction) -> Bool {
296299
handleDataDetection(URL)
297300
return false
298301
}

Components/Sources/Table/Extensions/TableContext+TableWrappedCell.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ extension TableContext: BuilderContext {
1616

1717
// TODO: - add support for other types of generators or make (decorated generator)
1818

19-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ConfigurableItem, Item : RegistrationTypeProvider {
19+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ConfigurableItem,
20+
Item: RegistrationTypeProvider {
2021
Item.rddm.tableGenerator(with: model, and: Item.prefferedRegistration)
2122
}
2223

23-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ViewType, Item : ConfigurableItem, Item : RegistrationTypeProvider {
24+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ViewType,
25+
Item: ConfigurableItem,
26+
Item: RegistrationTypeProvider {
2427
Item.rddm.baseGenerator(with: model, and: Item.prefferedRegistration)
2528
}
2629

Example/ReactiveDataDisplayManager/Table/StackCellExampleViewController/StackCellExampleViewController.swift

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,56 +66,56 @@ 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+
// TODO: - resolve crash with neb loading
99+
// TitleTableViewCell.build(in: ctx, with: "Cell outside from stack")
100+
StackView.build(in: ctx, with: .build { hStack in
101101
hStack.background(.solid(.systemGreen))
102102
hStack.style(.init(axis: .horizontal,
103103
spacing: 0,
104104
alignment: .fill,
105105
distribution: .fillEqually))
106-
hStack.children { it in
107-
it.gen(TitleTableViewCell.self, model: "6")
108-
it.stack(model: .build { vStack in
106+
hStack.children { ctx in
107+
TitleTableViewCell.build(in: ctx, with: "6")
108+
StackView.build(in: ctx, with: .build { vStack in
109109
vStack.background(.solid(.systemPink))
110110
vStack.style(.init(axis: .vertical,
111111
spacing: 20,
112112
alignment: .fill,
113113
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")
114+
vStack.children { ctx in
115+
TitleTableViewCell.build(in: ctx, with: "7")
116+
TitleTableViewCell.build(in: ctx, with: "8")
117+
TitleTableViewCell.build(in: ctx, with: "9")
118+
TitleTableViewCell.build(in: ctx, with: "10")
119119
}
120120
})
121121
}

Source/Protocols/BuilderContext/RegistrationTypeProvider.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
public protocol RegistrationTypeProvider {
99
static var prefferedRegistration: RegistrationType { get }
1010
}
11-

Source/Stack/Generators/ViewContext.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public struct ViewContext: BuilderContext {
1313
public typealias ViewType = UIView
1414
public typealias GeneratorType = ViewGenerator
1515

16-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ConfigurableItem, Item : RegistrationTypeProvider {
16+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ConfigurableItem,
17+
Item: RegistrationTypeProvider {
1718
Item.rddm.viewGenerator(with: model, and: Item.prefferedRegistration)
1819
}
1920

Source/Table/Generators/TableContext.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ public struct TableContext {
1717
T.rddm.baseGenerator(with: model, and: registerType)
1818
}
1919

20-
2120
}

0 commit comments

Comments
 (0)