mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-15 18:59:54 +00:00
Merge pull request #1310 from maicki/UpdateCommittedAPI
[ASCollection/TableView] Add -waitUntilAllUpdatesAreCommitted to wait for concurrent measurement to finish
This commit is contained in:
commit
edd567a91d
@ -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.
|
||||
*
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
*
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
@interface ASChangeSetDataController ()
|
||||
|
||||
@property (nonatomic, assign) NSUInteger batchUpdateCounter;
|
||||
@property (nonatomic, assign) NSUInteger changeSetBatchUpdateCounter;
|
||||
@property (nonatomic, strong) _ASHierarchyChangeSet *changeSet;
|
||||
|
||||
@end
|
||||
@ -28,7 +28,7 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
_batchUpdateCounter = 0;
|
||||
_changeSetBatchUpdateCounter = 0;
|
||||
|
||||
return self;
|
||||
}
|
||||
@ -38,18 +38,18 @@
|
||||
- (void)beginUpdates
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
if (_batchUpdateCounter == 0) {
|
||||
if (_changeSetBatchUpdateCounter == 0) {
|
||||
_changeSet = [_ASHierarchyChangeSet new];
|
||||
}
|
||||
_batchUpdateCounter++;
|
||||
_changeSetBatchUpdateCounter++;
|
||||
}
|
||||
|
||||
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
_batchUpdateCounter--;
|
||||
_changeSetBatchUpdateCounter--;
|
||||
|
||||
if (_batchUpdateCounter == 0) {
|
||||
if (_changeSetBatchUpdateCounter == 0) {
|
||||
[_changeSet markCompleted];
|
||||
|
||||
[super beginUpdates];
|
||||
@ -86,7 +86,7 @@
|
||||
|
||||
- (BOOL)batchUpdating
|
||||
{
|
||||
BOOL batchUpdating = (_batchUpdateCounter != 0);
|
||||
BOOL batchUpdating = (_changeSetBatchUpdateCounter != 0);
|
||||
// _changeSet must be available during batch update
|
||||
ASDisplayNodeAssertTrue(batchUpdating == (_changeSet != nil));
|
||||
return batchUpdating;
|
||||
|
||||
@ -181,6 +181,8 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
|
||||
|
||||
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
||||
|
||||
- (void)waitUntilAllUpdatesAreCommitted;
|
||||
|
||||
/** @name Data Querying */
|
||||
|
||||
- (NSUInteger)numberOfSections;
|
||||
|
||||
@ -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)
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user