@@ -18,15 +18,19 @@ import Differentiator
1818open class RxTableViewSectionedAnimatedDataSource < S: AnimatableSectionModelType >
1919 : TableViewSectionedDataSource < S >
2020 , RxTableViewDataSourceType {
21-
2221 public typealias Element = [ S ]
22+ public typealias DecideViewTransition = ( TableViewSectionedDataSource < S > , UITableView , [ Changeset < S > ] ) -> ViewTransition
2323
2424 /// Animation configuration for data source
2525 public var animationConfiguration : AnimationConfiguration
2626
27+ /// Calculates view transition depending on type of changes
28+ public var decideViewTransition : DecideViewTransition
29+
2730 #if os(iOS)
2831 public init (
2932 animationConfiguration: AnimationConfiguration = AnimationConfiguration ( ) ,
33+ decideViewTransition: @escaping DecideViewTransition = { _, _, _ in . animated } ,
3034 configureCell: @escaping ConfigureCell ,
3135 titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil } ,
3236 titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil } ,
@@ -36,6 +40,7 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
3640 sectionForSectionIndexTitle: @escaping SectionForSectionIndexTitle = { _, _, index in index }
3741 ) {
3842 self . animationConfiguration = animationConfiguration
43+ self . decideViewTransition = decideViewTransition
3944 super. init (
4045 configureCell: configureCell,
4146 titleForHeaderInSection: titleForHeaderInSection,
@@ -49,13 +54,15 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
4954 #else
5055 public init (
5156 animationConfiguration: AnimationConfiguration = AnimationConfiguration ( ) ,
57+ decideViewTransition: @escaping DecideViewTransition = { _, _, _ in . animated } ,
5258 configureCell: @escaping ConfigureCell ,
5359 titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil } ,
5460 titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil } ,
5561 canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false } ,
5662 canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false }
5763 ) {
5864 self . animationConfiguration = animationConfiguration
65+ self . decideViewTransition = decideViewTransition
5966 super. init (
6067 configureCell: configureCell,
6168 titleForHeaderInSection: titleForHeaderInSection,
@@ -90,10 +97,17 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
9097 do {
9198 let differences = try Diff . differencesForSectionedView ( initialSections: oldSections, finalSections: newSections)
9299
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)
95104
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
97111 }
98112 }
99113 catch let e {
0 commit comments