Skip to content

Commit 6237c21

Browse files
authored
Merge pull request #198 from surfstudio/hotfix/open_modifier
add public shortcut for modifier
2 parents 3fee008 + e291df5 commit 6237c21

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

Source/Collection/Manager/BaseCollectionManager.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ open class BaseCollectionManager: CollectionGeneratorsProvider, DataDisplayManag
1616
public typealias CellGeneratorType = CollectionCellGenerator
1717
public typealias HeaderGeneratorType = CollectionHeaderGenerator
1818
public typealias FooterGeneratorType = CollectionFooterGenerator
19-
20-
public typealias CollectionAnimator = Animator<CollectionType>
19+
public typealias CollectionModifier = Modifier<CollectionType, CollectionItemAnimation>
2120

2221
// MARK: - Public properties
2322

23+
public var modifier: CollectionModifier? {
24+
dataSource?.modifier
25+
}
26+
2427
// swiftlint:disable implicitly_unwrapped_optional
25-
public weak var view: UICollectionView!
28+
public weak var view: CollectionType!
2629
// swiftlint:enable implicitly_unwrapped_optional
2730

2831
var dataSource: CollectionDataSource?
@@ -32,7 +35,7 @@ open class BaseCollectionManager: CollectionGeneratorsProvider, DataDisplayManag
3235

3336
public func forceRefill() {
3437
CollectionPluginsChecker(delegate: delegate, generators: generators).asyncCheckPlugins()
35-
dataSource?.modifier?.reload()
38+
modifier?.reload()
3639
}
3740

3841
public func addCellGenerator(_ generator: CollectionCellGenerator) {
@@ -78,7 +81,7 @@ open class BaseCollectionManager: CollectionGeneratorsProvider, DataDisplayManag
7881
public func update(generators: [CollectionCellGenerator]) {
7982
let indexes = generators.compactMap { [weak self] in self?.findGenerator($0) }
8083
let indexPaths = indexes.compactMap { IndexPath(row: $0.generatorIndex, section: $0.sectionIndex) }
81-
dataSource?.modifier?.reloadRows(at: indexPaths, with: .animated)
84+
modifier?.reloadRows(at: indexPaths, with: .animated)
8285
}
8386

8487
public func clearCellGenerators() {
@@ -224,7 +227,7 @@ private extension BaseCollectionManager {
224227
IndexPath(row: $0.generatorIndex, section: $0.sectionIndex)
225228
}
226229

227-
dataSource?.modifier?.insertRows(at: indexPaths, with: .animated)
230+
modifier?.insertRows(at: indexPaths, with: .animated)
228231
}
229232

230233
func findGenerator(_ generator: CollectionCellGenerator) -> (sectionIndex: Int, generatorIndex: Int)? {
@@ -254,7 +257,7 @@ private extension BaseCollectionManager {
254257
}
255258

256259
// apply changes in table
257-
dataSource?.modifier?.removeRows(at: [indexPath], and: sectionIndexPath, with: .animated)
260+
modifier?.removeRows(at: [indexPath], and: sectionIndexPath, with: .animated)
258261

259262
// scroll if needed
260263
if let scrollPosition = scrollPosition {

Source/Table/Manager/BaseTableManager.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,26 @@ open class BaseTableManager: TableGeneratorsProvider, DataDisplayManager {
1616
public typealias CollectionType = UITableView
1717
public typealias CellGeneratorType = TableCellGenerator
1818
public typealias HeaderGeneratorType = TableHeaderGenerator
19+
public typealias TableModifier = Modifier<CollectionType, CollectionType.RowAnimation>
1920

2021
// MARK: - Public properties
2122

2223
// swiftlint:disable implicitly_unwrapped_optional
23-
public weak var view: UITableView!
24+
public weak var view: CollectionType!
2425
// swiftlint:enable implicitly_unwrapped_optional
2526

27+
public var modifier: TableModifier? {
28+
dataSource?.modifier
29+
}
30+
2631
var dataSource: TableDataSource?
2732
var delegate: TableDelegate?
2833

2934
// MARK: - DataDisplayManager
3035

3136
public func forceRefill() {
3237
TablePluginsChecker(delegate: delegate, generators: generators).asyncCheckPlugins()
33-
dataSource?.modifier?.reload()
38+
modifier?.reload()
3439
}
3540

3641
open func addCellGenerator(_ generator: TableCellGenerator) {
@@ -67,7 +72,7 @@ open class BaseTableManager: TableGeneratorsProvider, DataDisplayManager {
6772
open func update(generators: [TableCellGenerator]) {
6873
let indexes = generators.compactMap { [weak self] in self?.findGenerator($0) }
6974
let indexPaths = indexes.compactMap { IndexPath(row: $0.generatorIndex, section: $0.sectionIndex) }
70-
dataSource?.modifier?.reloadRows(at: indexPaths, with: .none)
75+
modifier?.reloadRows(at: indexPaths, with: .none)
7176
}
7277

7378
open func clearCellGenerators() {
@@ -127,7 +132,7 @@ extension BaseTableManager {
127132
}
128133

129134
// apply changes in table
130-
dataSource?.modifier?.removeRows(at: [indexPath], and: sectionIndexPath, with: animation)
135+
modifier?.removeRows(at: [indexPath], and: sectionIndexPath, with: animation)
131136

132137
// scroll if needed
133138
if let scrollPosition = scrollPosition {

Source/Table/Manager/GravityTableManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ open class GravityTableManager: BaseTableManager {
151151
generators[index.sectionIndex].insert(newGenerator, at: index.generatorIndex)
152152

153153
let indexPath = IndexPath(row: index.generatorIndex, section: index.sectionIndex)
154-
dataSource?.modifier?.replace(at: indexPath, with: removeAnimation, and: insertAnimation)
154+
modifier?.replace(at: indexPath, with: removeAnimation, and: insertAnimation)
155155
}
156156

157157
open func replace(header: HeaderGeneratorType, with animation: UITableView.RowAnimation = .fade) {
@@ -161,7 +161,7 @@ open class GravityTableManager: BaseTableManager {
161161
}
162162

163163
self.sections[indexOfHeader] = header
164-
dataSource?.modifier?.reloadSections(at: [indexOfHeader], with: animation)
164+
modifier?.reloadSections(at: [indexOfHeader], with: animation)
165165
}
166166

167167
open func remove(_ generator: CellGeneratorType,
@@ -210,7 +210,7 @@ private extension GravityTableManager {
210210
return IndexPath(row: index, section: section)
211211
}
212212

213-
dataSource?.modifier?.insertRows(at: indexPaths, with: .none)
213+
modifier?.insertRows(at: indexPaths, with: .none)
214214
}
215215

216216
func nearestIndex(for generator: CellGeneratorType, in section: Int) -> Int? {

Source/Table/Manager/ManualTableManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class ManualTableManager: BaseTableManager {
8181
guard let index = sections.firstIndex(where: { (headerGenerator) -> Bool in
8282
return headerGenerator === sectionHeaderGenerator
8383
}) else { return }
84-
dataSource?.modifier?.reloadSections(at: [index], with: animation)
84+
modifier?.reloadSections(at: [index], with: animation)
8585
}
8686

8787
/// Inserts new generators to provided TableHeaderGenerator generator.
@@ -117,7 +117,7 @@ public class ManualTableManager: BaseTableManager {
117117
return
118118
}
119119

120-
dataSource?.modifier?.removeRows(at: indexes, and: nil, with: .automatic)
120+
modifier?.removeRows(at: indexes, and: nil, with: .automatic)
121121
}
122122

123123
open func addCellGenerator(_ generator: TableCellGenerator, toHeader headerGenerator: TableHeaderGenerator) {
@@ -327,7 +327,7 @@ public class ManualTableManager: BaseTableManager {
327327
generators[index.sectionIndex].insert(newGenerator, at: index.generatorIndex)
328328
let indexPath = IndexPath(row: index.generatorIndex, section: index.sectionIndex)
329329

330-
dataSource?.modifier?.replace(at: indexPath, with: removeAnimation, and: insertAnimation)
330+
modifier?.replace(at: indexPath, with: removeAnimation, and: insertAnimation)
331331
}
332332

333333
/// Swaps two generators between each other.
@@ -349,7 +349,7 @@ public class ManualTableManager: BaseTableManager {
349349
generators[secondIndex.sectionIndex].insert(firstGenerator, at: secondIndex.generatorIndex)
350350
generators[firstIndex.sectionIndex].insert(secondGenerator, at: firstIndex.generatorIndex)
351351

352-
dataSource?.modifier?.reload()
352+
modifier?.reload()
353353
}
354354

355355
}
@@ -367,7 +367,7 @@ private extension ManualTableManager {
367367
self.sections.insert(headGenerator, at: index)
368368
self.generators.insert([], at: index)
369369

370-
dataSource?.modifier?.insertSections(at: [index], with: animation)
370+
modifier?.insertSections(at: [index], with: animation)
371371
}
372372

373373
func insert(elements: [(generator: TableCellGenerator, sectionIndex: Int, generatorIndex: Int)],
@@ -382,7 +382,7 @@ private extension ManualTableManager {
382382
IndexPath(row: $0.generatorIndex, section: $0.sectionIndex)
383383
}
384384

385-
dataSource?.modifier?.insertRows(at: indexPaths, with: animation)
385+
modifier?.insertRows(at: indexPaths, with: animation)
386386
}
387387

388388
}

0 commit comments

Comments
 (0)