@@ -66,14 +66,25 @@ extension UITableView: DeltaUpdatableView {
66
66
}
67
67
}
68
68
69
- if #available( iOS 11 . 0 , * ) {
70
- performBatchUpdates ( { [ weak self] in
71
- tableViewUpdates. forEach { $0. sectionUpdate. update ( ) }
72
- guard self != nil else { return }
73
- deleteMoveInsert ( )
74
- tableViewUpdates. uniqueAnimationDelegates. forEach { $0. animateAlongsideUpdate ( with: TimeInterval . standardCollectionAnimationDuration) }
75
- } , completion: { [ weak self] animationsCompletedSuccessfully in
76
- guard let strongSelf = self else {
69
+ performBatchUpdates ( . insertDeleteMove, delegates: tableViewUpdates. uniqueAnimationDelegates, { [ weak self] in
70
+ tableViewUpdates. forEach { $0. sectionUpdate. update ( ) }
71
+ guard self != nil else { return }
72
+ deleteMoveInsert ( )
73
+ } , completion: { [ weak self] animationsCompletedSuccessfully in
74
+ guard let strongSelf = self else {
75
+ tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
76
+ return
77
+ }
78
+ guard animationsCompletedSuccessfully else {
79
+ strongSelf. reloadData ( )
80
+ tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
81
+ return
82
+ }
83
+ strongSelf. performBatchUpdates ( . reload, delegates: tableViewUpdates. uniqueAnimationDelegates, { [ weak weakSelf = strongSelf] in
84
+ guard weakSelf != nil else { return }
85
+ reload ( )
86
+ } , completion: { [ weak weakSelf = strongSelf] animationsCompletedSuccessfully in
87
+ guard let strongSelf = weakSelf else {
77
88
tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
78
89
return
79
90
}
@@ -82,73 +93,27 @@ extension UITableView: DeltaUpdatableView {
82
93
tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
83
94
return
84
95
}
85
- strongSelf. performBatchUpdates ( { [ weak weakSelf = strongSelf] in
86
- guard weakSelf != nil else { return }
87
- reload ( )
88
- } , completion: { [ weak weakSelf = strongSelf] animationsCompletedSuccessfully in
89
- guard let strongSelf = weakSelf else {
90
- tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
91
- return
92
- }
93
- guard animationsCompletedSuccessfully else {
94
- strongSelf. reloadData ( )
95
- tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
96
- return
97
- }
98
-
99
- tableViewUpdates. manualReload ( view: strongSelf) {
100
- tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
101
- }
102
- } )
103
- } )
104
- } else {
105
- beginUpdates ( )
106
- tableViewUpdates. forEach { $0. sectionUpdate. update ( ) }
107
- deleteMoveInsert ( )
108
- tableViewUpdates. uniqueAnimationDelegates. forEach { $0. animateAlongsideUpdate ( with: TimeInterval . standardCollectionAnimationDuration) }
109
- endUpdates ( )
110
-
111
- guard isVisibleOnScreen else {
112
- reloadData ( )
113
- tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
114
- return
115
- }
116
96
117
- beginUpdates ( )
118
- reload ( )
119
- endUpdates ( )
120
-
121
- tableViewUpdates. manualReload ( view: self ) {
122
- tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
123
- }
124
- }
97
+ tableViewUpdates. manualReload ( view: strongSelf) {
98
+ tableViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
99
+ }
100
+ } )
101
+ } )
125
102
}
126
103
127
104
public func reloadSections( for sectionUpdates: [ SectionUpdate ] ) {
128
105
129
- if #available( iOS 11 . 0 , * ) {
130
- performBatchUpdates ( { [ weak self] in
131
- sectionUpdates. forEach { sectionUpdate in
132
- sectionUpdate. update ( )
133
- guard self != nil else { return }
134
- let indexSet = IndexSet ( [ sectionUpdate. section] )
135
- reloadSections ( indexSet, with: preferredReloadSectionAnimation ( for: sectionUpdate. section) )
136
- }
137
- sectionUpdates. uniqueAnimationDelegates. forEach { $0. animateAlongsideUpdate ( with: TimeInterval . standardCollectionAnimationDuration) }
138
- } , completion: { _ in
139
- sectionUpdates. forEach { $0. completion ? ( ) }
140
- } )
141
- } else {
142
- beginUpdates ( )
106
+ performBatchUpdates ( { [ weak self] in
143
107
sectionUpdates. forEach { sectionUpdate in
144
108
sectionUpdate. update ( )
109
+ guard self != nil else { return }
145
110
let indexSet = IndexSet ( [ sectionUpdate. section] )
146
111
reloadSections ( indexSet, with: preferredReloadSectionAnimation ( for: sectionUpdate. section) )
147
112
}
148
113
sectionUpdates. uniqueAnimationDelegates. forEach { $0. animateAlongsideUpdate ( with: TimeInterval . standardCollectionAnimationDuration) }
149
- endUpdates ( )
114
+ } , completion : { _ in
150
115
sectionUpdates. forEach { $0. completion ? ( ) }
151
- }
116
+ } )
152
117
}
153
118
}
154
119
@@ -189,7 +154,7 @@ extension UICollectionView: DeltaUpdatableView {
189
154
return
190
155
}
191
156
192
- performBatchUpdates ( { [ weak self] in
157
+ performBatchUpdates ( . insertDeleteMove , delegates : collectionViewUpdates . uniqueAnimationDelegates , { [ weak self] in
193
158
collectionViewUpdates. forEach { $0. sectionUpdate. update ( ) }
194
159
guard let strongSelf = self else { return }
195
160
for update in collectionViewUpdates {
@@ -201,7 +166,6 @@ extension UICollectionView: DeltaUpdatableView {
201
166
}
202
167
strongSelf. insertItems ( at: delta. insertedIndexPaths)
203
168
}
204
- collectionViewUpdates. uniqueAnimationDelegates. forEach { $0. animateAlongsideUpdate ( with: TimeInterval . standardCollectionAnimationDuration) }
205
169
} , completion: { [ weak self] animationsCompletedSuccessfully in
206
170
guard let strongSelf = self else {
207
171
collectionViewUpdates. forEach { $0. sectionUpdate. completion ? ( ) }
@@ -219,7 +183,7 @@ extension UICollectionView: DeltaUpdatableView {
219
183
return
220
184
}
221
185
222
- strongSelf. performBatchUpdates ( { [ weak weakSelf = strongSelf] in
186
+ strongSelf. performBatchUpdates ( . reload , delegates : collectionViewUpdates . uniqueAnimationDelegates , { [ weak weakSelf = strongSelf] in
223
187
guard let strongSelf = weakSelf else { return }
224
188
for update in filteredUpdates {
225
189
let delta = update. indexPathsToAnimate
@@ -497,3 +461,39 @@ private extension Sequence where Element == SectionUpdate {
497
461
} )
498
462
}
499
463
}
464
+
465
+ // MARK: AnimationDelegate Helper
466
+
467
+ private extension UITableView {
468
+
469
+ func performBatchUpdates( _ group: CollectionDataAnimationGroup , delegates: [ CollectionDataAnimationDelegate ] , _ updates: ( ( ) -> Void ) ? , completion: ( ( Bool ) -> Void ) ? = nil ) {
470
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . immediatelyBefore( group: group, duration: TimeInterval . standardCollectionAnimationDuration) ) }
471
+
472
+ performBatchUpdates {
473
+ updates ? ( )
474
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . during( group: group, duration: TimeInterval . standardCollectionAnimationDuration) ) }
475
+ } completion: { value in
476
+ completion ? ( value)
477
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . completed( group: group) ) }
478
+ }
479
+
480
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . immediatelyAfter( group: group, duration: TimeInterval . standardCollectionAnimationDuration) ) }
481
+ }
482
+ }
483
+
484
+ private extension UICollectionView {
485
+
486
+ func performBatchUpdates( _ group: CollectionDataAnimationGroup , delegates: [ CollectionDataAnimationDelegate ] , _ updates: ( ( ) -> Void ) ? , completion: ( ( Bool ) -> Void ) ? = nil ) {
487
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . immediatelyBefore( group: group, duration: TimeInterval . standardCollectionAnimationDuration) ) }
488
+
489
+ performBatchUpdates {
490
+ updates ? ( )
491
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . during( group: group, duration: TimeInterval . standardCollectionAnimationDuration) ) }
492
+ } completion: { value in
493
+ completion ? ( value)
494
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . completed( group: group) ) }
495
+ }
496
+
497
+ delegates. forEach { $0. animateAlongsideUpdate ( for: . immediatelyAfter( group: group, duration: TimeInterval . standardCollectionAnimationDuration) ) }
498
+ }
499
+ }
0 commit comments