Skip to content

Commit 8e1cfc8

Browse files
committed
add concrete type for buildIn func and prepare example of decorations and transformations
1 parent df6434e commit 8e1cfc8

File tree

11 files changed

+46
-19
lines changed

11 files changed

+46
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ReactiveDataDisplayManager
99

1010
public extension CollectionContext {
1111

12-
static func stack(model: StackView.Model) -> CollectionCellGenerator {
12+
static func stack(model: StackView.Model) -> BaseCellGenerator<CollectionWrappedCell<StackView>> {
1313
StackView.rddm.collectionGenerator(with: model)
1414
}
1515

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ import ReactiveDataDisplayManager
1010

1111
public extension ConfigurableItem where Self: RegistrationTypeProvider {
1212

13-
static func build(in ctx: ViewContext.Type, with model: Model) -> ViewContext.GeneratorType {
13+
static func build(in ctx: ViewContext.Type, with model: Model) -> BaseViewGenerator<Self> {
1414
ctx.gen(Self.self, model: model)
1515
}
1616

17-
static func build(in ctx: TableContext.Type, with model: Model) -> TableContext.GeneratorType where Self: UITableViewCell {
17+
static func build(in ctx: TableContext.Type, with model: Model) -> BaseCellGenerator<Self> where Self: UITableViewCell {
1818
ctx.gen(Self.self, model: model)
1919
}
2020

21-
static func build(in ctx: TableContext.Type, with model: Model) -> TableContext.GeneratorType {
21+
static func build(in ctx: TableContext.Type, with model: Model) -> BaseCellGenerator<TableWrappedCell<Self>> {
2222
ctx.gen(Self.self, model: model)
2323
}
2424

25-
static func build(in ctx: TableContext.Type, with model: Model) -> TableContext.GeneratorType where Self: UICollectionViewCell {
25+
static func build(in ctx: CollectionContext.Type, with model: Model) -> BaseCellGenerator<Self> where Self: UICollectionViewCell {
2626
ctx.gen(Self.self, model: model)
2727
}
2828

29-
static func build(in ctx: CollectionContext.Type, with model: Model) -> CollectionContext.GeneratorType {
29+
static func build(in ctx: CollectionContext.Type, with model: Model) -> BaseCellGenerator<CollectionWrappedCell<Self>> {
3030
ctx.gen(Self.self, model: model)
3131
}
3232

Components/Sources/Common/Extensions/ViewContext+Stack.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ReactiveDataDisplayManager
1111

1212
public extension ViewContext {
1313

14-
static func stack(model: StackView.Model) -> ViewGenerator {
14+
static func stack(model: StackView.Model) -> BaseViewGenerator<StackView> {
1515
StackView.rddm.viewGenerator(with: model, and: .class)
1616
}
1717

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ReactiveDataDisplayManager
99

1010
public extension TableContext {
1111

12-
static func stack(model: StackView.Model) -> TableCellGenerator {
12+
static func stack(model: StackView.Model) -> BaseCellGenerator<TableWrappedCell<StackView>> {
1313
StackView.rddm.tableGenerator(with: model)
1414
}
1515

Example/ReactiveDataDisplayManager/Collection/StackCellExampleCollectionViewController/StackCellExampleCollectionViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ private extension StackCellExampleCollectionViewController {
103103
}
104104
})
105105
TitleCollectionViewCell.build(in: ctx, with: "Some text outside of stack")
106+
.didSelectEvent {
107+
print("Did select cell outside of stack")
108+
}
106109
}
107110

108111
// Tell adapter that we've changed generators

Example/ReactiveDataDisplayManager/Table/StackCellExampleViewController/StackCellExampleViewController.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class StackCellExampleViewController: UIViewController {
2626

2727
private lazy var adapter = tableView.rddm.manualBuilder
2828
.add(plugin: .selectable())
29+
.add(plugin: .foldable())
2930
.add(plugin: .highlightable())
3031
.add(plugin: .accessibility())
3132
.build()
@@ -73,13 +74,18 @@ private extension StackCellExampleViewController {
7374
})
7475
TitleTableViewCell.build(in: ctx, with: "3")
7576
}
76-
})
77+
}).didSelectEvent {
78+
print("StackView did select")
79+
}
7780
LabelView.build(in: ctx, with: .build { label in
7881
label.textAlignment(.center)
7982
label.text(.string("Wrapped LabelView"))
8083
label.style(.init(color: .systemBlue, font: .preferredFont(forTextStyle: .body)))
8184
})
8285
TitleTableViewCell.build(in: ctx, with: "Cell outside from stack")
86+
.didSelectEvent {
87+
print("Cell outside from stack did select")
88+
}
8389
StackView.build(in: ctx, with: .build { hStack in
8490
hStack.background(.solid(.systemGreen))
8591
hStack.style(.init(axis: .horizontal,
@@ -103,6 +109,21 @@ private extension StackCellExampleViewController {
103109
})
104110
}
105111
})
112+
FoldableTableViewCell.build(in: ctx, with: .init(title: "example", isExpanded: false))
113+
.asFoldable { ctx in
114+
TitleTableViewCell.build(in: ctx, with: "first child")
115+
.didSelectEvent {
116+
print("first child did select")
117+
}
118+
TitleTableViewCell.build(in: ctx, with: "second child")
119+
.didSelectEvent {
120+
print("second child did select")
121+
}
122+
}
123+
.animation((.bottom, .top))
124+
.didFoldEvent {
125+
print("Foldable cell is \($0 ? "expanded" : "collapsed")")
126+
}
106127
}
107128

108129
// Tell adapter that we've changed generators

Example/ReactiveDataDisplayManager/Table/Views/Cells/FoldableTableViewCell/FoldableTableViewCell.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ extension FoldableTableViewCell: ConfigurableItem {
8080

8181
}
8282

83+
// MARK: - RegistrationTypeProvider
84+
85+
extension FoldableTableViewCell: RegistrationTypeProvider {
86+
87+
static var prefferedRegistration: RegistrationType { .nib }
88+
89+
}
90+
8391
// MARK: - Configuration
8492

8593
private extension FoldableTableViewCell {

Source/Collection/Generators/CollectionContext.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ public struct CollectionContext: BuilderContext {
1313
public typealias ViewType = UICollectionViewCell
1414
public typealias GeneratorType = CollectionCellGenerator
1515

16-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: BaseItem {
16+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> BaseCellGenerator<CollectionWrappedCell<Item>> where Item: BaseItem {
1717
Item.rddm.collectionGenerator(with: model)
1818
}
1919

20-
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ViewType,
21-
Item: BaseItem {
20+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> BaseCellGenerator<Item> where Item: ViewType & BaseItem {
2221
Item.rddm.baseGenerator(with: model, and: Item.prefferedRegistration)
2322
}
2423

Source/Protocols/BuilderContext/BuilderContext.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@ import UIKit
99

1010
public protocol BuilderContext {
1111
associatedtype ViewType: UIView
12-
associatedtype GeneratorType
13-
14-
static func gen<Item: BaseItem>(_ type: Item.Type, model: Item.Model) -> GeneratorType
1512
}

Source/Stack/Generators/ViewContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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: BaseItem {
16+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> BaseViewGenerator<Item> where Item: BaseItem {
1717
Item.rddm.viewGenerator(with: model, and: Item.prefferedRegistration)
1818
}
1919

0 commit comments

Comments
 (0)