Skip to content

Commit 3b5f407

Browse files
committed
Support animation configuration
1 parent 4c28f41 commit 3b5f407

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

Sources/DataSources/ASTableNode+Rx/RxASTableAnimatedDataSource.swift

-14
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ import RxSwift
1212
import RxCocoa
1313
import Differentiator
1414

15-
public struct RowAnimation {
16-
public let insertAnimation: UITableViewRowAnimation
17-
public let reloadAnimation: UITableViewRowAnimation
18-
public let deleteAnimation: UITableViewRowAnimation
19-
20-
public init(insertAnimation: UITableViewRowAnimation = .automatic,
21-
reloadAnimation: UITableViewRowAnimation = .automatic,
22-
deleteAnimation: UITableViewRowAnimation = .automatic) {
23-
self.insertAnimation = insertAnimation
24-
self.reloadAnimation = reloadAnimation
25-
self.deleteAnimation = deleteAnimation
26-
}
27-
}
28-
2915
open class RxASTableAnimatedDataSource<S: AnimatableSectionModelType>: ASTableSectionedDataSource<S>, RxASTableDataSourceType {
3016

3117
public typealias Element = [S]

Sources/DataSources/SectionedNodeType+BatchUpdate.swift

+19-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ func indexSet(_ values: [Int]) -> IndexSet {
1818
return indexSet as IndexSet
1919
}
2020

21+
public struct RowAnimation {
22+
public let insertAnimation: UITableViewRowAnimation
23+
public let reloadAnimation: UITableViewRowAnimation
24+
public let deleteAnimation: UITableViewRowAnimation
25+
26+
public init(insertAnimation: UITableViewRowAnimation = .automatic,
27+
reloadAnimation: UITableViewRowAnimation = .automatic,
28+
deleteAnimation: UITableViewRowAnimation = .automatic) {
29+
self.insertAnimation = insertAnimation
30+
self.reloadAnimation = reloadAnimation
31+
self.deleteAnimation = deleteAnimation
32+
}
33+
}
34+
2135
public protocol SectionedNodeType {
2236
func insertItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation)
2337
func deleteItemsAtIndexPaths(_ paths: [IndexPath], animationStyle: UITableViewRowAnimation)
@@ -35,26 +49,26 @@ public protocol SectionedNodeType {
3549
func _performBatchUpdates<V: SectionedNodeType, S: SectionModelType>(_ view: V, changes: Changeset<S>, animationConfiguration: RowAnimation) {
3650
typealias I = S.Item
3751

38-
view.deleteSections(changes.deletedSections, animationStyle: .fade)
52+
view.deleteSections(changes.deletedSections, animationStyle: animationConfiguration.deleteAnimation)
3953
// Updated sections doesn't mean reload entire section, somebody needs to update the section view manually
4054
// otherwise all cells will be reloaded for nothing.
4155
//view.reloadSections(changes.updatedSections, animationStyle: rowAnimation)
42-
view.insertSections(changes.insertedSections, animationStyle: .fade)
56+
view.insertSections(changes.insertedSections, animationStyle: animationConfiguration.insertAnimation)
4357
for (from, to) in changes.movedSections {
4458
view.moveSection(from, to: to)
4559
}
4660

4761
view.deleteItemsAtIndexPaths(
4862
changes.deletedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) },
49-
animationStyle: .fade
63+
animationStyle: animationConfiguration.deleteAnimation
5064
)
5165
view.insertItemsAtIndexPaths(
5266
changes.insertedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) },
53-
animationStyle: .fade
67+
animationStyle: animationConfiguration.insertAnimation
5468
)
5569
view.reloadItemsAtIndexPaths(
5670
changes.updatedItems.map { IndexPath(item: $0.itemIndex, section: $0.sectionIndex) },
57-
animationStyle: .fade
71+
animationStyle: animationConfiguration.reloadAnimation
5872
)
5973

6074
for (from, to) in changes.movedItems {

0 commit comments

Comments
 (0)