Skip to content

Commit c280fdc

Browse files
authored
Merge pull request #240 from surfstudio/hotfix/SPT-1515
[SPT-1515][7.3.7] Очищать BaseEvents и сделать FoldableGenerator доступным
2 parents 7874a1f + a42fc5c commit c280fdc

File tree

17 files changed

+273
-88
lines changed

17 files changed

+273
-88
lines changed

Example/ReactiveDataDisplayManager/Collection/FoldableCollectionViewController/FoldableCollectionViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ private extension FoldableCollectionViewController {
9595
adapter.forceRefill()
9696
}
9797

98-
func makeFoldableCellGenerator(color: UIColor, expanded: Bool) -> FoldableCollectionCellGenerator {
98+
func makeFoldableCellGenerator(color: UIColor, expanded: Bool) -> CollectionCellGenerator & CollectionFoldableItem {
9999
// Create foldable generator
100-
let viewModel = FoldableCollectionViewCell.ViewModel(color: color)
101-
let generator = FoldableCollectionCellGenerator(with: viewModel)
100+
let generator = FoldableCollectionViewCell.rddm.foldableGenerator(with: .init(color: color))
102101

103102
// Configure foldable initial state
104103
generator.isExpanded = expanded

Example/ReactiveDataDisplayManager/Collection/Views/Cells/FoldableCollectionViewCell/FoldableCollectionViewCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
import ReactiveDataDisplayManager
1111
import Nuke
1212

13-
final class FoldableCollectionViewCell: UICollectionViewCell {
13+
final class FoldableCollectionViewCell: UICollectionViewCell, FoldableStateHolder {
1414

1515
// MARK: - ViewModel
1616

@@ -36,9 +36,9 @@ final class FoldableCollectionViewCell: UICollectionViewCell {
3636
setupInitialState()
3737
}
3838

39-
// MARK: - Internal Methods
39+
// MARK: - Foldable
4040

41-
func update(isExpanded: Bool) {
41+
func setExpanded(_ isExpanded: Bool) {
4242
UIView.animate(withDuration: Constants.animationDuration) { [weak self] in
4343
self?.arrowImageView.transform = isExpanded ? .identity : CGAffineTransform(rotationAngle: .pi)
4444
}

Example/ReactiveDataDisplayManager/Collection/Views/Cells/Generators/FoldableCollectionCellGenerator.swift

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

Example/ReactiveDataDisplayManager/Table/AllPluginsTableViewController/AllPluginsTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private extension AllPluginsTableViewController {
176176

177177
for _ in 0...3 {
178178
// Create foldable generator
179-
let generator = FoldableCellGenerator(with: .init(title: "", isExpanded: false))
179+
let generator = FoldableTableViewCell.rddm.foldableGenerator(with: .init(title: "", isExpanded: false))
180180

181181
// Create and add child generators
182182
generator.childGenerators = Constants.titles.map { TitleTableViewCell.rddm.baseGenerator(with: $0) }

Example/ReactiveDataDisplayManager/Table/FoldableTableViewController/FoldableTableViewController.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ private extension FoldableTableViewController {
5656
// Add foldable cell generator to adapter
5757
adapter.addCellGenerator(makeFoldableCellGenerator(id: "2"))
5858

59+
// Add foldable cell generator to adapter
60+
adapter.addCellGenerator(makeFoldableCellGenerator(id: "3"))
61+
62+
// Add foldable cell generator to adapter
63+
adapter.addCellGenerator(makeFoldableCellGenerator(id: "4"))
64+
65+
// Add foldable cell generator to adapter
66+
adapter.addCellGenerator(makeFoldableCellGenerator(id: "5"))
67+
68+
// Add foldable cell generator to adapter
69+
adapter.addCellGenerator(makeFoldableCellGenerator(id: "6"))
70+
5971
// Tell adapter that we've changed generators
6072
adapter.forceRefill()
6173
}
@@ -68,9 +80,9 @@ private extension FoldableTableViewController {
6880
return generators
6981
}
7082

71-
func makeFoldableCellGenerator(id: String) -> FoldableCellGenerator {
83+
func makeFoldableCellGenerator(id: String) -> TableCellGenerator {
7284
// Create foldable generator
73-
let generator = FoldableCellGenerator(with: .init(title: id, isExpanded: false))
85+
let generator = FoldableTableViewCell.rddm.foldableGenerator(with: .init(title: id, isExpanded: false))
7486

7587
// Create and add child generators
7688
generator.childGenerators = Constants.titleForSubcells.map { TitleTableViewCell.rddm.baseGenerator(with: $0) }

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

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

12-
final class FoldableTableViewCell: UITableViewCell {
12+
final class FoldableTableViewCell: UITableViewCell, FoldableStateHolder {
1313

1414
struct Model {
1515
let title: String
@@ -35,9 +35,9 @@ final class FoldableTableViewCell: UITableViewCell {
3535
setupInitialState()
3636
}
3737

38-
// MARK: - Internal Methods
38+
// MARK: - Foldable
3939

40-
func update(isExpanded: Bool) {
40+
func setExpanded(_ isExpanded: Bool) {
4141
UIView.animate(withDuration: Constants.animationDuration) { [weak self] in
4242
self?.arrowImageView.transform = isExpanded ? .identity : CGAffineTransform(rotationAngle: .pi)
4343
}

Example/ReactiveDataDisplayManager/Table/Views/Cells/Generators/FoldableCellGenerator.swift

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

Example/ReactiveDataDisplayManager/Table/Views/Cells/Generators/GravityFoldableCellGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import ReactiveDataDisplayManager
1010

11-
final class GravityFoldableCellGenerator: FoldableCellGenerator {
11+
final class GravityFoldableCellGenerator: FoldableCellGenerator<FoldableTableViewCell> {
1212

1313
// MARK: - Properties
1414

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
//
2+
// BaseEventTests.swift
3+
// ReactiveDataDisplayManager
4+
//
5+
// Created by korshunov on 26.06.2023.
6+
//
7+
8+
import XCTest
9+
@testable import ReactiveDataDisplayManager
10+
11+
final class BaseEventTests: XCTestCase {
12+
13+
func testWhenValueInvokesCorrectly() {
14+
// given
15+
16+
let event = BaseEvent<String>()
17+
var result = ""
18+
19+
event.addListner { result = $0 }
20+
21+
// when
22+
23+
event.invoke(with: "invoked")
24+
25+
// then
26+
27+
XCTAssertEqual(result, "invoked")
28+
}
29+
30+
func testWhenNListnersThenNEvents() {
31+
// given
32+
33+
let event = BaseEvent<Int>()
34+
let n = 100
35+
var eventHandled = 0
36+
37+
for _ in 0..<n {
38+
event.addListner({ _ in eventHandled += 1 })
39+
}
40+
41+
// when
42+
43+
event.invoke(with: 0)
44+
45+
// then
46+
47+
XCTAssertEqual(eventHandled, n)
48+
}
49+
50+
func testWhenNListnersThenClear() {
51+
// given
52+
53+
let event = BaseEvent<Int>()
54+
let n = 100
55+
56+
for _ in 0..<n {
57+
event.addListner({ _ in })
58+
}
59+
60+
// when
61+
62+
event.clear()
63+
64+
// then
65+
66+
XCTAssertTrue(event.isEmpty)
67+
}
68+
69+
func testWhenUniqueListnerThenReplaced() {
70+
// given
71+
72+
let event = BaseEvent<Int>()
73+
let id = "uniqueId"
74+
var result = 0
75+
76+
event.addListner(with: id) { _ in
77+
result = 1
78+
}
79+
80+
// when
81+
82+
event.addListner(with: id) { _ in
83+
result = 2
84+
}
85+
event.invoke(with: 0)
86+
87+
// then
88+
89+
XCTAssertEqual(result, 2)
90+
XCTAssertEqual(event.count, 1)
91+
}
92+
93+
func testWhenNUniqueListnersThenReplaced() {
94+
// given
95+
96+
let event = BaseEvent<Int>()
97+
let n = 100
98+
let ids = Array(repeating: 0, count: n).map { _ in UUID().uuidString }
99+
100+
ids.forEach { event.addListner(with: $0, { _ in }) }
101+
102+
// when
103+
104+
ids.forEach { event.addListner(with: $0, { _ in }) }
105+
106+
// then
107+
108+
XCTAssertEqual(event.count, n)
109+
}
110+
111+
func testWhenClearThenNoEvents() {
112+
// given
113+
114+
let event = BaseEvent<Int>()
115+
var result = false
116+
117+
event.addListner { _ in result = true }
118+
119+
// when
120+
121+
event.clear()
122+
event.invoke(with: 0)
123+
124+
// then
125+
126+
XCTAssertFalse(result)
127+
XCTAssertTrue(event.isEmpty)
128+
}
129+
130+
}

Source/Collection/CollectionCell+RDDM.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ public extension StaticDataDisplayWrapper where Base: UICollectionViewCell & Con
1717
}
1818

1919
}
20+
21+
public extension StaticDataDisplayWrapper where Base: UICollectionViewCell & ConfigurableItem & FoldableStateHolder {
22+
23+
func foldableGenerator(with model: Base.Model, and registerType: CellRegisterType = .nib) -> FoldableCollectionCellGenerator<Base> {
24+
.init(with: model, registerType: registerType)
25+
}
26+
27+
}

0 commit comments

Comments
 (0)