Skip to content

Commit 7874a1f

Browse files
authored
Merge pull request #242 from surfstudio/hotfix/SPT-1516
[SPT-1516][7.3.7] Правка ambiguity в параметрах
2 parents 6972981 + 31864da commit 7874a1f

File tree

7 files changed

+271
-37
lines changed

7 files changed

+271
-37
lines changed

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ GEM
7272
nanaimo (0.3.0)
7373
nap (1.1.0)
7474
netrc (0.11.0)
75+
nokogiri (1.14.3-arm64-darwin)
76+
racc (~> 1.4)
7577
nokogiri (1.14.3-x86_64-darwin)
7678
racc (~> 1.4)
7779
public_suffix (4.0.7)
@@ -101,6 +103,7 @@ GEM
101103
zeitwerk (2.6.7)
102104

103105
PLATFORMS
106+
arm64-darwin-22
104107
x86_64-darwin-21
105108

106109
DEPENDENCIES

ReactiveDataDisplayManagerTests/Table/Manager/BaseTableManagerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ final class BaseTableManagerTests: XCTestCase {
155155
table.forceLayout()
156156

157157
// when
158-
ddm.remove(gen3, with: nil, needScrollAt: .top, needRemoveEmptySection: false)
158+
ddm.remove(gen3, with: .notAnimated, needScrollAt: .top, needRemoveEmptySection: false)
159159
ddm.forceRefill()
160160

161161
// then
@@ -176,7 +176,7 @@ final class BaseTableManagerTests: XCTestCase {
176176
table.forceLayout()
177177

178178
// when
179-
ddm.remove(gen1, with: nil, needScrollAt: nil, needRemoveEmptySection: false)
179+
ddm.remove(gen1, with: .notAnimated, needScrollAt: nil, needRemoveEmptySection: false)
180180
ddm.forceRefill()
181181

182182
// then

Source/Table/Manager/BaseTableManager.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ open class BaseTableManager: TableGeneratorsProvider, DataDisplayManager {
8989
/// for row when scrolling concludes. See UITableViewScrollPosition for descriptions of valid constants.
9090
/// - needRemoveEmptySection: Pass **true** if you need to remove section if it'll be empty after deleting.
9191
open func remove(_ generator: TableCellGenerator,
92-
with animation: UITableView.RowAnimation?,
92+
with animation: TableRowAnimation,
9393
needScrollAt scrollPosition: UITableView.ScrollPosition?,
9494
needRemoveEmptySection: Bool) {
9595
guard let index = findGenerator(generator) else { return }
@@ -99,6 +99,20 @@ open class BaseTableManager: TableGeneratorsProvider, DataDisplayManager {
9999
needRemoveEmptySection: needRemoveEmptySection)
100100
}
101101

102+
// MARK: - Deprecated
103+
104+
@available(*, deprecated, message: "Please use method with a new `TableRowAnimation` parameter")
105+
open func remove(_ generator: TableCellGenerator,
106+
with animation: UITableView.RowAnimation?,
107+
needScrollAt scrollPosition: UITableView.ScrollPosition?,
108+
needRemoveEmptySection: Bool) {
109+
guard let index = findGenerator(generator) else { return }
110+
self.removeGenerator(with: index,
111+
with: animation.map { .animated($0) } ?? .notAnimated,
112+
needScrollAt: scrollPosition,
113+
needRemoveEmptySection: needRemoveEmptySection)
114+
}
115+
102116
}
103117

104118
// MARK: - Helper
@@ -115,7 +129,7 @@ extension BaseTableManager {
115129
}
116130

117131
func removeGenerator(with index: (sectionIndex: Int, generatorIndex: Int),
118-
with animation: UITableView.RowAnimation? = .automatic,
132+
with animation: TableRowAnimation,
119133
needScrollAt scrollPosition: UITableView.ScrollPosition? = nil,
120134
needRemoveEmptySection: Bool = false) {
121135

@@ -132,7 +146,7 @@ extension BaseTableManager {
132146
}
133147

134148
// apply changes in table
135-
modifier?.removeRows(at: [indexPath], and: sectionIndexPath, with: animation)
149+
modifier?.removeRows(at: [indexPath], and: sectionIndexPath, with: animation.value)
136150

137151
// scroll if needed
138152
if let scrollPosition = scrollPosition {
@@ -174,7 +188,7 @@ extension BaseTableManager {
174188
// MARK: - Inserting
175189

176190
func insert(elements: [(generator: TableCellGenerator, sectionIndex: Int, generatorIndex: Int)],
177-
with animation: UITableView.RowAnimation = .automatic) {
191+
with animation: TableRowAnimation) {
178192

179193
elements.forEach { [weak self] element in
180194
element.generator.registerCell(in: view)
@@ -185,12 +199,12 @@ extension BaseTableManager {
185199
IndexPath(row: $0.generatorIndex, section: $0.sectionIndex)
186200
}
187201

188-
modifier?.insertRows(at: indexPaths, with: animation)
202+
modifier?.insertRows(at: indexPaths, with: animation.value)
189203
}
190-
204+
191205
func insertManual(after generator: TableCellGenerator,
192-
new newGenerators: [TableCellGenerator],
193-
with animation: UITableView.RowAnimation = .automatic) {
206+
new newGenerators: [TableCellGenerator],
207+
with animation: TableRowAnimation) {
194208
guard let index = self.findGenerator(generator) else { return }
195209

196210
let elements = newGenerators.enumerated().map { item in

Source/Table/Manager/GravityTableManager.swift

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,45 @@ open class GravityTableManager: BaseTableManager {
143143

144144
open func replace(oldGenerator: CellGeneratorType,
145145
on newGenerator: CellGeneratorType,
146-
removeAnimation: UITableView.RowAnimation = .automatic,
147-
insertAnimation: UITableView.RowAnimation = .automatic) {
146+
removeInsertAnimation: TableRowAnimationGroup = .animated(.automatic, .automatic)) {
147+
guard let index = self.findGenerator(oldGenerator) else { return }
148+
149+
generators[index.sectionIndex].remove(at: index.generatorIndex)
150+
generators[index.sectionIndex].insert(newGenerator, at: index.generatorIndex)
151+
152+
let indexPath = IndexPath(row: index.generatorIndex, section: index.sectionIndex)
153+
154+
modifier?.replace(at: indexPath, with: removeInsertAnimation.value)
155+
}
156+
157+
open func replace(header: HeaderGeneratorType, with animation: TableRowAnimation = .animated(.fade)) {
158+
guard let indexOfHeader = self.sections.firstIndex(where: { $0 === header }) else {
159+
self.addSectionHeaderGenerator(header)
160+
return
161+
}
162+
163+
self.sections[indexOfHeader] = header
164+
modifier?.reloadSections(at: [indexOfHeader], with: animation.value)
165+
}
166+
167+
open func remove(_ generator: CellGeneratorType,
168+
with animation: TableRowAnimation = .animated(.automatic),
169+
needScrollAt scrollPosition: UITableView.ScrollPosition? = nil,
170+
needRemoveEmptySection: Bool = false) {
171+
guard let index = self.findGenerator(generator) else { return }
172+
self.removeGenerator(with: index,
173+
with: animation,
174+
needScrollAt: scrollPosition,
175+
needRemoveEmptySection: needRemoveEmptySection)
176+
}
177+
178+
// MARK: - Depcrecated
179+
180+
@available(*, deprecated, message: "Please use method with a new `TableRowAnimationGroup` parameters")
181+
open func replace(oldGenerator: CellGeneratorType,
182+
on newGenerator: CellGeneratorType,
183+
removeAnimation: UITableView.RowAnimation,
184+
insertAnimation: UITableView.RowAnimation) {
148185
guard let index = self.findGenerator(oldGenerator) else { return }
149186

150187
generators[index.sectionIndex].remove(at: index.generatorIndex)
@@ -154,7 +191,8 @@ open class GravityTableManager: BaseTableManager {
154191
modifier?.replace(at: indexPath, with: (remove: removeAnimation, insert: insertAnimation))
155192
}
156193

157-
open func replace(header: HeaderGeneratorType, with animation: UITableView.RowAnimation = .fade) {
194+
@available(*, deprecated, message: "Please use method with a new `TableRowAnimation` parameter")
195+
open func replace(header: HeaderGeneratorType, with animation: UITableView.RowAnimation) {
158196
guard let indexOfHeader = self.sections.firstIndex(where: { $0 === header }) else {
159197
self.addSectionHeaderGenerator(header)
160198
return
@@ -164,13 +202,14 @@ open class GravityTableManager: BaseTableManager {
164202
modifier?.reloadSections(at: [indexOfHeader], with: animation)
165203
}
166204

205+
@available(*, deprecated, message: "Please use method with a new `TableRowAnimation` parameter")
167206
open func remove(_ generator: CellGeneratorType,
168-
with animation: UITableView.RowAnimation = .automatic,
207+
with animation: UITableView.RowAnimation,
169208
needScrollAt scrollPosition: UITableView.ScrollPosition? = nil,
170209
needRemoveEmptySection: Bool = false) {
171210
guard let index = self.findGenerator(generator) else { return }
172211
self.removeGenerator(with: index,
173-
with: animation,
212+
with: .animated(animation),
174213
needScrollAt: scrollPosition,
175214
needRemoveEmptySection: needRemoveEmptySection)
176215
}

0 commit comments

Comments
 (0)