@@ -18,15 +18,19 @@ import Differentiator
18
18
open class RxTableViewSectionedAnimatedDataSource < S: AnimatableSectionModelType >
19
19
: TableViewSectionedDataSource < S >
20
20
, RxTableViewDataSourceType {
21
-
22
21
public typealias Element = [ S ]
22
+ public typealias DecideViewTransition = ( TableViewSectionedDataSource < S > , UITableView , [ Changeset < S > ] ) -> ViewTransition
23
23
24
24
/// Animation configuration for data source
25
25
public var animationConfiguration : AnimationConfiguration
26
26
27
+ /// Calculates view transition depending on type of changes
28
+ public var decideViewTransition : DecideViewTransition
29
+
27
30
#if os(iOS)
28
31
public init (
29
32
animationConfiguration: AnimationConfiguration = AnimationConfiguration ( ) ,
33
+ decideViewTransition: @escaping DecideViewTransition = { _, _, _ in . animated } ,
30
34
configureCell: @escaping ConfigureCell ,
31
35
titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil } ,
32
36
titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil } ,
@@ -36,6 +40,7 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
36
40
sectionForSectionIndexTitle: @escaping SectionForSectionIndexTitle = { _, _, index in index }
37
41
) {
38
42
self . animationConfiguration = animationConfiguration
43
+ self . decideViewTransition = decideViewTransition
39
44
super. init (
40
45
configureCell: configureCell,
41
46
titleForHeaderInSection: titleForHeaderInSection,
@@ -49,13 +54,15 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
49
54
#else
50
55
public init (
51
56
animationConfiguration: AnimationConfiguration = AnimationConfiguration ( ) ,
57
+ decideViewTransition: @escaping DecideViewTransition = { _, _, _ in . animated } ,
52
58
configureCell: @escaping ConfigureCell ,
53
59
titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil } ,
54
60
titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil } ,
55
61
canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false } ,
56
62
canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false }
57
63
) {
58
64
self . animationConfiguration = animationConfiguration
65
+ self . decideViewTransition = decideViewTransition
59
66
super. init (
60
67
configureCell: configureCell,
61
68
titleForHeaderInSection: titleForHeaderInSection,
@@ -90,10 +97,17 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
90
97
do {
91
98
let differences = try Diff . differencesForSectionedView ( initialSections: oldSections, finalSections: newSections)
92
99
93
- for difference in differences {
94
- dataSource. setSections ( difference. finalSections)
100
+ switch self . decideViewTransition ( self , tableView, differences) {
101
+ case . animated:
102
+ for difference in differences {
103
+ dataSource. setSections ( difference. finalSections)
95
104
96
- tableView. performBatchUpdates ( difference, animationConfiguration: self . animationConfiguration)
105
+ tableView. performBatchUpdates ( difference, animationConfiguration: self . animationConfiguration)
106
+ }
107
+ case . reload:
108
+ self . setSections ( newSections)
109
+ tableView. reloadData ( )
110
+ return
97
111
}
98
112
}
99
113
catch let e {
0 commit comments