Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 83aaa46

Browse files
author
Scott Goodson
committed
Revert "ASDataController now handles reloadData more efficiently and notify its delegate once instead of a series of deletes and inserts"
This reverts commit 2e4d716. Possible issue with this commit.
1 parent cb5e570 commit 83aaa46

8 files changed

Lines changed: 36 additions & 179 deletions

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ - (void)reloadDataWithCompletion:(void (^)())completion
250250
_superIsPendingDataLoad = YES;
251251
[super reloadData];
252252
});
253-
[_dataController reloadDataWithCompletion:completion];
253+
[_dataController reloadDataWithAnimationOptions:kASCollectionViewAnimationNone completion:completion];
254254
}
255255

256256
- (void)reloadData
@@ -262,7 +262,7 @@ - (void)reloadDataImmediately
262262
{
263263
ASDisplayNodeAssertMainThread();
264264
_superIsPendingDataLoad = YES;
265-
[_dataController reloadDataImmediately];
265+
[_dataController reloadDataImmediatelyWithAnimationOptions:kASCollectionViewAnimationNone];
266266
[super reloadData];
267267
}
268268

@@ -938,25 +938,6 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAt
938938
}
939939
}
940940

941-
- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController
942-
{
943-
ASDisplayNodeAssertMainThread();
944-
945-
if (!self.asyncDataSource || _superIsPendingDataLoad) {
946-
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
947-
}
948-
949-
if (_performingBatchUpdates) {
950-
[_batchUpdateBlocks addObject:^{
951-
[super reloadData];
952-
}];
953-
} else {
954-
[UIView performWithoutAnimation:^{
955-
[super reloadData];
956-
}];
957-
}
958-
}
959-
960941
#pragma mark - ASCellNodeDelegate
961942

962943
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged

AsyncDisplayKit/ASTableView.mm

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ - (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy
298298

299299
- (void)reloadDataWithCompletion:(void (^)())completion
300300
{
301-
[_dataController reloadDataWithCompletion:completion];
301+
ASPerformBlockOnMainThread(^{
302+
[super reloadData];
303+
});
304+
[_dataController reloadDataWithAnimationOptions:UITableViewRowAnimationNone completion:completion];
302305
}
303306

304307
- (void)reloadData
@@ -309,7 +312,8 @@ - (void)reloadData
309312
- (void)reloadDataImmediately
310313
{
311314
ASDisplayNodeAssertMainThread();
312-
[_dataController reloadDataImmediately];
315+
[_dataController reloadDataImmediatelyWithAnimationOptions:UITableViewRowAnimationNone];
316+
[super reloadData];
313317
}
314318

315319
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
@@ -841,18 +845,6 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAt
841845
});
842846
}
843847

844-
- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController
845-
{
846-
ASDisplayNodeAssertMainThread();
847-
LOG(@"UITableView reloadData");
848-
849-
if (!self.asyncDataSource) {
850-
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
851-
}
852-
853-
[super reloadData];
854-
}
855-
856848
#pragma mark - ASDataControllerDelegate
857849

858850
- (ASCellNode *)dataController:(ASDataController *)dataController nodeAtIndexPath:(NSIndexPath *)indexPath

AsyncDisplayKit/Details/ASCollectionDataController.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ - (void)prepareForReloadData
5555

5656
- (void)willReloadData
5757
{
58-
[_pendingNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *nodes, BOOL *stop) {
58+
[_pendingNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *nodes, BOOL *stop) {
5959
// Remove everything that existed before the reload, now that we're ready to insert replacements
6060
NSArray *indexPaths = [self indexPathsForEditingNodesOfKind:kind];
6161
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];

AsyncDisplayKit/Details/ASDataController.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
9494
*/
9595
- (void)dataController:(ASDataController *)dataController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
9696

97-
/**
98-
Called for data reload.
99-
*/
100-
- (void)dataControllerDidReloadData:(ASDataController *)dataController;
101-
10297
@end
10398

10499
/**
@@ -175,9 +170,9 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
175170

176171
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
177172

178-
- (void)reloadDataWithCompletion:(void (^ _Nullable)())completion;
173+
- (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions completion:(void (^ _Nullable)())completion;
179174

180-
- (void)reloadDataImmediately;
175+
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
181176

182177
/** @name Data Querying */
183178

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 25 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ @interface ASDataController () {
4343
BOOL _delegateDidDeleteNodes;
4444
BOOL _delegateDidInsertSections;
4545
BOOL _delegateDidDeleteSections;
46-
BOOL _delegateDidReloadData;
4746
}
4847

4948
@property (atomic, assign) NSUInteger batchUpdateCounter;
@@ -93,7 +92,6 @@ - (void)setDelegate:(id<ASDataControllerDelegate>)delegate
9392
_delegateDidDeleteNodes = [_delegate respondsToSelector:@selector(dataController:didDeleteNodes:atIndexPaths:withAnimationOptions:)];
9493
_delegateDidInsertSections = [_delegate respondsToSelector:@selector(dataController:didInsertSections:atIndexSet:withAnimationOptions:)];
9594
_delegateDidDeleteSections = [_delegate respondsToSelector:@selector(dataController:didDeleteSectionsAtIndexSet:withAnimationOptions:)];
96-
_delegateDidReloadData = [_delegate respondsToSelector:@selector(dataControllerDidReloadData:)];
9795
}
9896

9997
+ (NSUInteger)parallelProcessorCount
@@ -145,30 +143,14 @@ - (void)_layoutNode:(ASCellNode *)node withConstrainedSize:(ASSizeRange)constrai
145143
node.frame = CGRectMake(0.0f, 0.0f, node.calculatedSize.width, node.calculatedSize.height);
146144
}
147145

148-
/**
149-
* Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
150-
*/
151-
- (void)_batchLayoutNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
152-
{
153-
[self _batchLayoutNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:NO withAnimationOptions:0];
154-
}
155-
156146
/**
157147
* Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
158148
*/
159149
- (void)_batchLayoutNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
160-
{
161-
[self _batchLayoutNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:YES withAnimationOptions:animationOptions];
162-
}
163-
164-
/**
165-
* Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
166-
*/
167-
- (void)_batchLayoutNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths andNotifyDelegate:(BOOL)shouldNotifyDelegate withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
168150
{
169151
[self batchLayoutNodes:nodes ofKind:ASDataControllerRowNodeKind atIndexPaths:indexPaths completion:^(NSArray *nodes, NSArray *indexPaths) {
170152
// Insert finished nodes into data storage
171-
[self _insertNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:shouldNotifyDelegate withAnimationOptions:animationOptions];
153+
[self _insertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
172154
}];
173155
}
174156

@@ -258,14 +240,6 @@ - (void)deleteNodesOfKind:(NSString *)kind atIndexPaths:(NSArray *)indexPaths co
258240
}];
259241
}
260242

261-
- (void)deleteAllNodesOfKind:(NSString *)kind
262-
{
263-
[_editingNodes[kind] removeAllObjects];
264-
[_mainSerialQueue performBlockOnMainThread:^{
265-
[_completedNodes[kind] removeAllObjects];
266-
}];
267-
}
268-
269243
- (void)insertSections:(NSMutableArray *)sections ofKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet completion:(void (^)(NSArray *sections, NSIndexSet *indexSet))completionBlock
270244
{
271245
if (indexSet.count == 0)
@@ -303,17 +277,6 @@ - (void)deleteSectionsOfKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet
303277

304278
#pragma mark - Internal Data Querying + Editing
305279

306-
/**
307-
* Inserts the specified nodes into the given index paths and doesn't notify the delegate of newly inserted nodes.
308-
*
309-
* @discussion Nodes are first inserted into the editing store, then the completed store is replaced by a deep copy
310-
* of the editing nodes.
311-
*/
312-
- (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
313-
{
314-
[self _insertNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:NO withAnimationOptions:0];
315-
}
316-
317280
/**
318281
* Inserts the specified nodes into the given index paths and notifies the delegate of newly inserted nodes.
319282
*
@@ -322,26 +285,10 @@ - (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
322285
*/
323286
- (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
324287
{
325-
[self _insertNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:YES withAnimationOptions:animationOptions];
326-
}
327-
328-
/**
329-
* Inserts the specified nodes into the given index paths and notifies the delegate of newly inserted nodes.
330-
*
331-
* @discussion Nodes are first inserted into the editing store, then the completed store is replaced by a deep copy
332-
* of the editing nodes. The delegate is invoked on the main thread.
333-
*/
334-
- (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths andNotifyDelegate:(BOOL)shouldNotifyDelegate withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
335-
{
336-
void (^completionBlock)(NSArray *nodes, NSArray *indexPaths) = nil;
337-
if (shouldNotifyDelegate) {
338-
completionBlock = ^(NSArray *nodes, NSArray *indexPaths) {
339-
if (_delegateDidInsertNodes)
340-
[_delegate dataController:self didInsertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
341-
};
342-
}
343-
344-
[self insertNodes:nodes ofKind:ASDataControllerRowNodeKind atIndexPaths:indexPaths completion:completionBlock];
288+
[self insertNodes:nodes ofKind:ASDataControllerRowNodeKind atIndexPaths:indexPaths completion:^(NSArray *nodes, NSArray *indexPaths) {
289+
if (_delegateDidInsertNodes)
290+
[_delegate dataController:self didInsertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
291+
}];
345292
}
346293

347294
/**
@@ -358,46 +305,18 @@ - (void)_deleteNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASD
358305
}];
359306
}
360307

361-
/**
362-
* Inserts sections, represented as arrays, into the backing store at the given indicies and doesn't notify the delegate.
363-
*
364-
* @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
365-
* in the completed store on the main thread.
366-
*/
367-
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet
368-
{
369-
[self _insertSections:sections atIndexSet:indexSet andNotifyDelegate:NO withAnimationOptions:0];
370-
}
371-
372-
/**
373-
* Inserts sections, represented as arrays, into the backing store at the given indicies and doesn't notify the delegate.
374-
*
375-
* @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
376-
* in the completed store on the main thread.
377-
*/
378-
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
379-
{
380-
[self _insertSections:sections atIndexSet:indexSet andNotifyDelegate:YES withAnimationOptions:animationOptions];
381-
}
382-
383308
/**
384309
* Inserts sections, represented as arrays, into the backing store at the given indicies and notifies the delegate.
385310
*
386311
* @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
387312
* in the completed store on the main thread. The delegate is invoked on the main thread.
388313
*/
389-
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet andNotifyDelegate:(BOOL)shouldNotifyDelegate withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
314+
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
390315
{
391-
392-
void (^completionBlock)(NSArray *sections, NSIndexSet *indexSet) = nil;
393-
if (shouldNotifyDelegate) {
394-
completionBlock = ^(NSArray *sections, NSIndexSet *indexSet) {
395-
if (_delegateDidInsertSections)
396-
[_delegate dataController:self didInsertSections:sections atIndexSet:indexSet withAnimationOptions:animationOptions];
397-
};
398-
}
399-
400-
[self insertSections:sections ofKind:ASDataControllerRowNodeKind atIndexSet:indexSet completion:completionBlock];
316+
[self insertSections:sections ofKind:ASDataControllerRowNodeKind atIndexSet:indexSet completion:^(NSArray *sections, NSIndexSet *indexSet) {
317+
if (_delegateDidInsertSections)
318+
[_delegate dataController:self didInsertSections:sections atIndexSet:indexSet withAnimationOptions:animationOptions];
319+
}];
401320
}
402321

403322
/**
@@ -442,17 +361,17 @@ - (void)initialDataLoadingWithAnimationOptions:(ASDataControllerAnimationOptions
442361
}];
443362
}
444363

445-
- (void)reloadDataWithCompletion:(void (^)())completion
364+
- (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions completion:(void (^)())completion
446365
{
447-
[self _reloadDataSynchronously:NO completion:completion];
366+
[self _reloadDataWithAnimationOptions:animationOptions synchronously:NO completion:completion];
448367
}
449368

450-
- (void)reloadDataImmediately
369+
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
451370
{
452-
[self _reloadDataSynchronously:YES completion:nil];
371+
[self _reloadDataWithAnimationOptions:animationOptions synchronously:YES completion:nil];
453372
}
454373

455-
- (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())completion
374+
- (void)_reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions synchronously:(BOOL)synchronously completion:(void (^)())completion
456375
{
457376
[self performEditCommandWithBlock:^{
458377
ASDisplayNodeAssertMainThread();
@@ -474,7 +393,12 @@ - (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())comp
474393
LOG(@"Edit Transaction - reloadData");
475394

476395
// Remove everything that existed before the reload, now that we're ready to insert replacements
477-
[self deleteAllNodesOfKind:ASDataControllerRowNodeKind];
396+
NSArray *indexPaths = ASIndexPathsForMultidimensionalArray(_editingNodes[ASDataControllerRowNodeKind]);
397+
[self _deleteNodesAtIndexPaths:indexPaths withAnimationOptions:animationOptions];
398+
399+
NSMutableArray *editingNodes = _editingNodes[ASDataControllerRowNodeKind];
400+
NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, editingNodes.count)];
401+
[self _deleteSectionsAtIndexSet:indexSet withAnimationOptions:animationOptions];
478402

479403
[self willReloadData];
480404

@@ -484,19 +408,12 @@ - (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())comp
484408
[sections addObject:[[NSMutableArray alloc] init]];
485409
}
486410

487-
[self _insertSections:sections atIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, sectionCount)]];
411+
[self _insertSections:sections atIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, sectionCount)] withAnimationOptions:animationOptions];
488412

489-
[self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths];
413+
[self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOptions];
490414

491-
if (_delegateDidReloadData || completion) {
492-
[_mainSerialQueue performBlockOnMainThread:^{
493-
if (_delegateDidReloadData) {
494-
[_delegate dataControllerDidReloadData:self];
495-
}
496-
if (completion) {
497-
completion();
498-
}
499-
}];
415+
if (completion) {
416+
dispatch_async(dispatch_get_main_queue(), completion);
500417
}
501418
};
502419

AsyncDisplayKit/Details/ASRangeController.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,6 @@ NS_ASSUME_NONNULL_BEGIN
190190
*/
191191
- (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
192192

193-
/**
194-
* Called for data reload.
195-
*
196-
* @param rangeController Sender.
197-
*/
198-
- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController;
199-
200193
@end
201194

202195
NS_ASSUME_NONNULL_END

AsyncDisplayKit/Details/ASRangeController.mm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,4 @@ - (void)dataController:(ASDataController *)dataController didDeleteSectionsAtInd
276276
});
277277
}
278278

279-
- (void)dataControllerDidReloadData:(ASDataController *)dataController
280-
{
281-
ASPerformBlockOnMainThread(^{
282-
_rangeIsValid = NO;
283-
284-
// When reload data we need to make sure that _rangeTypeIndexPaths is cleared as well,
285-
// otherwise _updateVisibleNodeIndexPaths may try to retrieve nodes from dataSource that aren't there anymore
286-
[_rangeTypeIndexPaths removeAllObjects];
287-
288-
[_delegate rangeControllerDidReloadData:self];
289-
});
290-
}
291-
292279
@end

AsyncDisplayKit/Details/ASRangeControllerBeta.mm

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,4 @@ - (void)dataController:(ASDataController *)dataController didDeleteSectionsAtInd
267267
});
268268
}
269269

270-
- (void)dataControllerDidReloadData:(ASDataController *)dataController
271-
{
272-
ASPerformBlockOnMainThread(^{
273-
_rangeIsValid = NO;
274-
[_delegate rangeControllerDidReloadData:self];
275-
});
276-
}
277-
278270
@end

0 commit comments

Comments
 (0)