Merge pull request #405 from eanagel/reloadData-completion

Add (optional) completion handler for ASTableView and AsCollectionView reloadData
This commit is contained in:
appleguy
2015-05-03 19:25:06 -07:00
6 changed files with 38 additions and 6 deletions

View File

@@ -70,6 +70,15 @@
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*
* @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
* the main thread.
* @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,15 @@
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*
* @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
* the main thread.
* @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);
}
});
}];
}