add completion block to reloadData methods

This commit is contained in:
Ethan Nagel 2015-03-26 16:32:44 -07:00
parent dd10fda42c
commit 3f509dbd2f
6 changed files with 36 additions and 6 deletions

View File

@ -70,6 +70,14 @@
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*
* @param completion Block to run on completion or nil.
* @warning This method is substantially more expensive than UICollectionView's version.
*/
- (void)reloadDataWithCompletion:(void (^)())completion;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*

View File

@ -162,13 +162,18 @@ static BOOL _isInterceptedSelector(SEL sel)
#pragma mark -
#pragma mark Overrides.
- (void)reloadData
- (void)reloadDataWithCompletion:(void (^)())completion
{
ASDisplayNodeAssert(self.asyncDelegate, @"ASCollectionView's asyncDelegate property must be set.");
ASDisplayNodePerformBlockOnMainThread(^{
[super reloadData];
});
[_dataController reloadDataWithAnimationOption:kASCollectionViewAnimationNone];
[_dataController reloadDataWithAnimationOption:kASCollectionViewAnimationNone completion:completion];
}
- (void)reloadData
{
[self reloadDataWithCompletion:nil];
}
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource

View File

@ -70,6 +70,14 @@
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*
* @param completion Block to run on completion or nil.
* @warning This method is substantially more expensive than UITableView's version.
*/
-(void)reloadDataWithCompletion:(void (^)())completion;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*

View File

@ -205,13 +205,18 @@ static BOOL _isInterceptedSelector(SEL sel)
}
}
- (void)reloadData
- (void)reloadDataWithCompletion:(void (^)())completion
{
ASDisplayNodeAssert(self.asyncDelegate, @"ASTableView's asyncDelegate property must be set.");
ASDisplayNodePerformBlockOnMainThread(^{
[super reloadData];
});
[_dataController reloadDataWithAnimationOption:UITableViewRowAnimationNone];
[_dataController reloadDataWithAnimationOption:UITableViewRowAnimationNone completion:completion];
}
- (void)reloadData
{
[self reloadDataWithCompletion:nil];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType

View File

@ -155,7 +155,7 @@ typedef NSUInteger ASDataControllerAnimationOptions;
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath withAnimationOption:(ASDataControllerAnimationOptions)animationOption;;
- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption;;
- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption completion:(void (^)())completion;
/** @name Data Querying */

View File

@ -437,7 +437,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
});
}
- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption
- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption completion:(void (^)())completion
{
[self performDataFetchingWithBlock:^{
// Fetching data in calling thread
@ -478,6 +478,10 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
}];
[self _batchInsertNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOption];
if (completion) {
dispatch_async(dispatch_get_main_queue(), completion);
}
});
}];
}