Add -waitUntilAllUpdatesAreCommitted to ASTableView and ASCollectionView

The API allows consumer of ASTableView or ASCollectionCiew to block execution of the main thread until all section and row updates are committed.
This commit is contained in:
Michael Schneider 2016-03-02 19:20:58 -08:00
parent e82d1408d2
commit aa2ae87c81
6 changed files with 41 additions and 0 deletions

View File

@ -165,6 +165,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)reloadDataImmediately;
/**
* Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
*/
- (void)waitUntilAllUpdatesAreCommitted;
/**
* Registers the given kind of supplementary node for use in creating node-backed supplementary views.
*

View File

@ -268,6 +268,12 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[super reloadData];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
[_dataController waitUntilAllUpdatesAreCommitted];
}
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
{
// UIKit can internally generate a call to this method upon changing the asyncDataSource; only assert for non-nil.

View File

@ -163,6 +163,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^ _Nullable)(BOOL completed))completion;
/**
* Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
*/
- (void)waitUntilAllUpdatesAreCommitted;
/**
* Inserts one or more sections, with an option to animate the insertion.
*

View File

@ -394,6 +394,12 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
[_dataController endUpdatesAnimated:animated completion:completion];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
[_dataController waitUntilAllUpdatesAreCommitted];
}
- (void)layoutSubviews
{
if (_nodesConstrainedWidth != self.bounds.size.width) {

View File

@ -181,6 +181,8 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
- (void)waitUntilAllUpdatesAreCommitted;
/** @name Data Querying */
- (NSUInteger)numberOfSections;

View File

@ -462,6 +462,23 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
}];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
ASDisplayNodeAssert(_batchUpdateCounter == 0, @"Should not be called between beginUpdate or endUpdate");
// This should never be called in a batch update, return immediately therefore
if (_batchUpdateCounter > 0) { return; }
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
// Schedule block in main serial queue to wait until all operations are finished that are
// where scheduled while waiting for the _editingTransactionQueue to finish
[_mainSerialQueue performBlockOnMainThread:^{
ASDisplayNodeAssert(_editingTransactionQueue.operationCount == 0, @"No operation should be in the _editingTransactionQueue anymore");
}];
}
#pragma mark - Data Source Access (Calling _dataSource)
/**