Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ - (void)reloadDataWithCompletion:(void (^)())completion
_superIsPendingDataLoad = YES;
[super reloadData];
});
[_dataController reloadDataWithCompletion:completion];
[_dataController reloadDataWithAnimationOptions:kASCollectionViewAnimationNone completion:completion];
}

- (void)reloadData
Expand All @@ -262,7 +262,7 @@ - (void)reloadDataImmediately
{
ASDisplayNodeAssertMainThread();
_superIsPendingDataLoad = YES;
[_dataController reloadDataImmediately];
[_dataController reloadDataImmediatelyWithAnimationOptions:kASCollectionViewAnimationNone];
[super reloadData];
}

Expand Down Expand Up @@ -938,27 +938,6 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAt
}
}

- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController
{
ASDisplayNodeAssertMainThread();

if (!self.asyncDataSource || _superIsPendingDataLoad) {
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
}

if (_performingBatchUpdates) {
[_batchUpdateBlocks addObject:^{
_superIsPendingDataLoad = YES;
[super reloadData];
}];
} else {
[UIView performWithoutAnimation:^{
_superIsPendingDataLoad = YES;
[super reloadData];
}];
}
}

#pragma mark - ASCellNodeDelegate

- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged
Expand Down
20 changes: 6 additions & 14 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ - (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy

- (void)reloadDataWithCompletion:(void (^)())completion
{
[_dataController reloadDataWithCompletion:completion];
ASPerformBlockOnMainThread(^{
[super reloadData];
});
[_dataController reloadDataWithAnimationOptions:UITableViewRowAnimationNone completion:completion];
}

- (void)reloadData
Expand All @@ -309,7 +312,8 @@ - (void)reloadData
- (void)reloadDataImmediately
{
ASDisplayNodeAssertMainThread();
[_dataController reloadDataImmediately];
[_dataController reloadDataImmediatelyWithAnimationOptions:UITableViewRowAnimationNone];
[super reloadData];
}

- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
Expand Down Expand Up @@ -841,18 +845,6 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAt
});
}

- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController
{
ASDisplayNodeAssertMainThread();
LOG(@"UITableView reloadData");

if (!self.asyncDataSource) {
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
}

[super reloadData];
}

#pragma mark - ASDataControllerDelegate

- (ASCellNode *)dataController:(ASDataController *)dataController nodeAtIndexPath:(NSIndexPath *)indexPath
Expand Down
9 changes: 2 additions & 7 deletions AsyncDisplayKit/Details/ASDataController.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
*/
- (void)dataController:(ASDataController *)dataController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;

/**
Called for data reload.
*/
- (void)dataControllerDidReloadData:(ASDataController *)dataController;

@end

/**
Expand Down Expand Up @@ -175,9 +170,9 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;

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

- (void)reloadDataWithCompletion:(void (^ _Nullable)())completion;
- (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions completion:(void (^ _Nullable)())completion;

- (void)reloadDataImmediately;
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;

/** @name Data Querying */

Expand Down
133 changes: 25 additions & 108 deletions AsyncDisplayKit/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ @interface ASDataController () {
BOOL _delegateDidDeleteNodes;
BOOL _delegateDidInsertSections;
BOOL _delegateDidDeleteSections;
BOOL _delegateDidReloadData;
}

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

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

/**
* Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
*/
- (void)_batchLayoutNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
{
[self _batchLayoutNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:NO withAnimationOptions:0];
}

/**
* Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
*/
- (void)_batchLayoutNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{
[self _batchLayoutNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:YES withAnimationOptions:animationOptions];
}

/**
* Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
*/
- (void)_batchLayoutNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths andNotifyDelegate:(BOOL)shouldNotifyDelegate withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{
[self batchLayoutNodes:nodes ofKind:ASDataControllerRowNodeKind atIndexPaths:indexPaths completion:^(NSArray *nodes, NSArray *indexPaths) {
// Insert finished nodes into data storage
[self _insertNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:shouldNotifyDelegate withAnimationOptions:animationOptions];
[self _insertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
}];
}

Expand Down Expand Up @@ -258,14 +240,6 @@ - (void)deleteNodesOfKind:(NSString *)kind atIndexPaths:(NSArray *)indexPaths co
}];
}

- (void)deleteAllNodesOfKind:(NSString *)kind
{
[_editingNodes[kind] removeAllObjects];
[_mainSerialQueue performBlockOnMainThread:^{
[_completedNodes[kind] removeAllObjects];
}];
}

- (void)insertSections:(NSMutableArray *)sections ofKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet completion:(void (^)(NSArray *sections, NSIndexSet *indexSet))completionBlock
{
if (indexSet.count == 0)
Expand Down Expand Up @@ -303,17 +277,6 @@ - (void)deleteSectionsOfKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet

#pragma mark - Internal Data Querying + Editing

/**
* Inserts the specified nodes into the given index paths and doesn't notify the delegate of newly inserted nodes.
*
* @discussion Nodes are first inserted into the editing store, then the completed store is replaced by a deep copy
* of the editing nodes.
*/
- (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
{
[self _insertNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:NO withAnimationOptions:0];
}

/**
* Inserts the specified nodes into the given index paths and notifies the delegate of newly inserted nodes.
*
Expand All @@ -322,26 +285,10 @@ - (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
*/
- (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{
[self _insertNodes:nodes atIndexPaths:indexPaths andNotifyDelegate:YES withAnimationOptions:animationOptions];
}

/**
* Inserts the specified nodes into the given index paths and notifies the delegate of newly inserted nodes.
*
* @discussion Nodes are first inserted into the editing store, then the completed store is replaced by a deep copy
* of the editing nodes. The delegate is invoked on the main thread.
*/
- (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths andNotifyDelegate:(BOOL)shouldNotifyDelegate withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{
void (^completionBlock)(NSArray *nodes, NSArray *indexPaths) = nil;
if (shouldNotifyDelegate) {
completionBlock = ^(NSArray *nodes, NSArray *indexPaths) {
if (_delegateDidInsertNodes)
[_delegate dataController:self didInsertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
};
}

[self insertNodes:nodes ofKind:ASDataControllerRowNodeKind atIndexPaths:indexPaths completion:completionBlock];
[self insertNodes:nodes ofKind:ASDataControllerRowNodeKind atIndexPaths:indexPaths completion:^(NSArray *nodes, NSArray *indexPaths) {
if (_delegateDidInsertNodes)
[_delegate dataController:self didInsertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
}];
}

/**
Expand All @@ -358,46 +305,18 @@ - (void)_deleteNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASD
}];
}

/**
* Inserts sections, represented as arrays, into the backing store at the given indicies and doesn't notify the delegate.
*
* @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
* in the completed store on the main thread.
*/
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet
{
[self _insertSections:sections atIndexSet:indexSet andNotifyDelegate:NO withAnimationOptions:0];
}

/**
* Inserts sections, represented as arrays, into the backing store at the given indicies and doesn't notify the delegate.
*
* @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
* in the completed store on the main thread.
*/
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{
[self _insertSections:sections atIndexSet:indexSet andNotifyDelegate:YES withAnimationOptions:animationOptions];
}

/**
* Inserts sections, represented as arrays, into the backing store at the given indicies and notifies the delegate.
*
* @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
* in the completed store on the main thread. The delegate is invoked on the main thread.
*/
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet andNotifyDelegate:(BOOL)shouldNotifyDelegate withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
- (void)_insertSections:(NSMutableArray *)sections atIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{

void (^completionBlock)(NSArray *sections, NSIndexSet *indexSet) = nil;
if (shouldNotifyDelegate) {
completionBlock = ^(NSArray *sections, NSIndexSet *indexSet) {
if (_delegateDidInsertSections)
[_delegate dataController:self didInsertSections:sections atIndexSet:indexSet withAnimationOptions:animationOptions];
};
}

[self insertSections:sections ofKind:ASDataControllerRowNodeKind atIndexSet:indexSet completion:completionBlock];
[self insertSections:sections ofKind:ASDataControllerRowNodeKind atIndexSet:indexSet completion:^(NSArray *sections, NSIndexSet *indexSet) {
if (_delegateDidInsertSections)
[_delegate dataController:self didInsertSections:sections atIndexSet:indexSet withAnimationOptions:animationOptions];
}];
}

/**
Expand Down Expand Up @@ -442,17 +361,17 @@ - (void)initialDataLoadingWithAnimationOptions:(ASDataControllerAnimationOptions
}];
}

- (void)reloadDataWithCompletion:(void (^)())completion
- (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions completion:(void (^)())completion
{
[self _reloadDataSynchronously:NO completion:completion];
[self _reloadDataWithAnimationOptions:animationOptions synchronously:NO completion:completion];
}

- (void)reloadDataImmediately
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions
{
[self _reloadDataSynchronously:YES completion:nil];
[self _reloadDataWithAnimationOptions:animationOptions synchronously:YES completion:nil];
}

- (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())completion
- (void)_reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions synchronously:(BOOL)synchronously completion:(void (^)())completion
{
[self performEditCommandWithBlock:^{
ASDisplayNodeAssertMainThread();
Expand All @@ -474,7 +393,12 @@ - (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())comp
LOG(@"Edit Transaction - reloadData");

// Remove everything that existed before the reload, now that we're ready to insert replacements
[self deleteAllNodesOfKind:ASDataControllerRowNodeKind];
NSArray *indexPaths = ASIndexPathsForMultidimensionalArray(_editingNodes[ASDataControllerRowNodeKind]);
[self _deleteNodesAtIndexPaths:indexPaths withAnimationOptions:animationOptions];

NSMutableArray *editingNodes = _editingNodes[ASDataControllerRowNodeKind];
NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, editingNodes.count)];
[self _deleteSectionsAtIndexSet:indexSet withAnimationOptions:animationOptions];

[self willReloadData];

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

[self _insertSections:sections atIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, sectionCount)]];
[self _insertSections:sections atIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, sectionCount)] withAnimationOptions:animationOptions];

[self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths];
[self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOptions];

if (_delegateDidReloadData || completion) {
[_mainSerialQueue performBlockOnMainThread:^{
if (_delegateDidReloadData) {
[_delegate dataControllerDidReloadData:self];
}
if (completion) {
completion();
}
}];
if (completion) {
dispatch_async(dispatch_get_main_queue(), completion);
}
};

Expand Down
7 changes: 0 additions & 7 deletions AsyncDisplayKit/Details/ASRangeController.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;

/**
* Called for data reload.
*
* @param rangeController Sender.
*/
- (void)rangeControllerDidReloadData:(ASRangeController *)rangeController;

@end

NS_ASSUME_NONNULL_END
13 changes: 0 additions & 13 deletions AsyncDisplayKit/Details/ASRangeController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,4 @@ - (void)dataController:(ASDataController *)dataController didDeleteSectionsAtInd
});
}

- (void)dataControllerDidReloadData:(ASDataController *)dataController
{
ASPerformBlockOnMainThread(^{
_rangeIsValid = NO;

// When reload data we need to make sure that _rangeTypeIndexPaths is cleared as well,
// otherwise _updateVisibleNodeIndexPaths may try to retrieve nodes from dataSource that aren't there anymore
[_rangeTypeIndexPaths removeAllObjects];

[_delegate rangeControllerDidReloadData:self];
});
}

@end
8 changes: 0 additions & 8 deletions AsyncDisplayKit/Details/ASRangeControllerBeta.mm
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,4 @@ - (void)dataController:(ASDataController *)dataController didDeleteSectionsAtInd
});
}

- (void)dataControllerDidReloadData:(ASDataController *)dataController
{
ASPerformBlockOnMainThread(^{
_rangeIsValid = NO;
[_delegate rangeControllerDidReloadData:self];
});
}

@end