Skip to content

Commit 4debacb

Browse files
committed
move base contexts (ex factories) to core lib
1 parent c1d9f20 commit 4debacb

File tree

15 files changed

+156
-88
lines changed

15 files changed

+156
-88
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// CollectionContext+CollectionWrappedCell.swift
3+
// ReactiveDataDisplayManager
4+
//
5+
// Created by Никита Коробейников on 21.07.2023.
6+
//
7+
8+
import UIKit
9+
import Foundation
10+
import ReactiveDataDisplayManager
11+
12+
public extension CollectionContext {
13+
14+
static func stack(model: StackView.Model) -> CollectionCellGenerator {
15+
StackView.rddm.collectionGenerator(with: model, and: .class)
16+
}
17+
18+
static func viewNib<T: UICollectionViewCell & ConfigurableItem>(type: T.Type,
19+
model: T.Model) -> BaseCollectionCellGenerator<CollectionWrappedCell<T>> {
20+
T.rddm.collectionGenerator(with: model, and: .nib)
21+
}
22+
23+
static func viewClass<T: UICollectionViewCell & ConfigurableItem>(type: T.Type,
24+
model: T.Model) -> BaseCollectionCellGenerator<CollectionWrappedCell<T>> {
25+
T.rddm.collectionGenerator(with: model, and: .class)
26+
}
27+
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// ViewContext+Stack.swift
3+
// ReactiveDataDisplayManager
4+
//
5+
// Created by Никита Коробейников on 21.07.2023.
6+
//
7+
8+
import UIKit
9+
import Foundation
10+
import ReactiveDataDisplayManager
11+
12+
public extension ViewContext {
13+
14+
static func stack(model: StackView.Model) -> StackCellGenerator {
15+
StackView.rddm.viewGenerator(with: model, and: .class)
16+
}
17+
18+
}

Components/Sources/Common/Utils/ViewGeneratorsBuilder.swift

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

Components/Sources/Common/Views/StackView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ extension StackView: ConfigurableItem {
4949
}
5050

5151
/// Only for stack. Cannot be included in common macros.
52-
public static func children(@GeneratorsBuilder<StackCellGenerator>_ content: @escaping (ViewFactory.Type) -> [StackCellGenerator]) -> Property {
52+
public static func children(@GeneratorsBuilder<StackCellGenerator>_ content: @escaping (ViewContext.Type) -> [StackCellGenerator]) -> Property {
5353
.init(closure: { model in
5454
var model = model
55-
model.set(children: content(ViewFactory.self))
55+
model.set(children: content(ViewContext.self))
5656
return model
5757
})
5858
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// TableContext+TableWrappedCell.swift
3+
// ReactiveDataDisplayManager
4+
//
5+
// Created by Никита Коробейников on 21.07.2023.
6+
//
7+
8+
import UIKit
9+
import Foundation
10+
import ReactiveDataDisplayManager
11+
12+
public extension TableContext {
13+
14+
static func stack(model: StackView.Model) -> TableCellGenerator {
15+
StackView.rddm.tableGenerator(with: model, and: .class)
16+
}
17+
18+
static func viewNib<T: UIView & ConfigurableItem>(type: T.Type,
19+
model: T.Model) -> BaseCellGenerator<TableWrappedCell<T>> {
20+
T.rddm.tableGenerator(with: model, and: .nib)
21+
}
22+
23+
static func viewClass<T: UIView & ConfigurableItem>(type: T.Type,
24+
model: T.Model) -> BaseCellGenerator<TableWrappedCell<T>> {
25+
T.rddm.tableGenerator(with: model, and: .class)
26+
}
27+
28+
}

Example/ReactiveDataDisplayManager/Table/StackCellExampleViewController/StackCellExampleViewController.swift

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

6767
// Note that using `UITableViewCell` or `UICollectionViewCell` inside stack is not recommended, but it possible
68-
adapter += TableSection.create(contextType: TableFactory.self,
69-
header: TitleHeaderGenerator(model: "StackView based cells"),
68+
adapter += TableSection.create(header: TitleHeaderGenerator(model: "StackView based cells"),
7069
footer: EmptyTableFooterGenerator()) { it in
7170
it.stack(
7271
model: .build { vStack in

Source/Collection/CollectionSection.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public extension CollectionSection {
2121
self.init(generators: generators, header: header, footer: EmptyCollectionFooterGenerator())
2222
}
2323

24+
static func create(header: HeaderGeneratorType,
25+
footer: FooterGeneratorType,
26+
@GeneratorsBuilder<GeneratorType> generators: (CollectionContext.Type) -> [GeneratorType]) -> Self {
27+
Self(generators: generators(CollectionContext.self), header: header, footer: footer)
28+
}
29+
2430
}

0 commit comments

Comments
 (0)