mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +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;
|
- (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.
|
* 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];
|
[super reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)waitUntilAllUpdatesAreCommitted
|
||||||
|
{
|
||||||
|
ASDisplayNodeAssertMainThread();
|
||||||
|
[_dataController waitUntilAllUpdatesAreCommitted];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
|
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
|
||||||
{
|
{
|
||||||
// UIKit can internally generate a call to this method upon changing the asyncDataSource; only assert for non-nil.
|
// 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;
|
- (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.
|
* 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];
|
[_dataController endUpdatesAnimated:animated completion:completion];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)waitUntilAllUpdatesAreCommitted
|
||||||
|
{
|
||||||
|
ASDisplayNodeAssertMainThread();
|
||||||
|
[_dataController waitUntilAllUpdatesAreCommitted];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)layoutSubviews
|
- (void)layoutSubviews
|
||||||
{
|
{
|
||||||
if (_nodesConstrainedWidth != self.bounds.size.width) {
|
if (_nodesConstrainedWidth != self.bounds.size.width) {
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
@interface ASChangeSetDataController ()
|
@interface ASChangeSetDataController ()
|
||||||
|
|
||||||
@property (nonatomic, assign) NSUInteger batchUpdateCounter;
|
@property (nonatomic, assign) NSUInteger changeSetBatchUpdateCounter;
|
||||||
@property (nonatomic, strong) _ASHierarchyChangeSet *changeSet;
|
@property (nonatomic, strong) _ASHierarchyChangeSet *changeSet;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -28,7 +28,7 @@
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
_batchUpdateCounter = 0;
|
_changeSetBatchUpdateCounter = 0;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -38,18 +38,18 @@
|
|||||||
- (void)beginUpdates
|
- (void)beginUpdates
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
if (_batchUpdateCounter == 0) {
|
if (_changeSetBatchUpdateCounter == 0) {
|
||||||
_changeSet = [_ASHierarchyChangeSet new];
|
_changeSet = [_ASHierarchyChangeSet new];
|
||||||
}
|
}
|
||||||
_batchUpdateCounter++;
|
_changeSetBatchUpdateCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion
|
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
_batchUpdateCounter--;
|
_changeSetBatchUpdateCounter--;
|
||||||
|
|
||||||
if (_batchUpdateCounter == 0) {
|
if (_changeSetBatchUpdateCounter == 0) {
|
||||||
[_changeSet markCompleted];
|
[_changeSet markCompleted];
|
||||||
|
|
||||||
[super beginUpdates];
|
[super beginUpdates];
|
||||||
@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
- (BOOL)batchUpdating
|
- (BOOL)batchUpdating
|
||||||
{
|
{
|
||||||
BOOL batchUpdating = (_batchUpdateCounter != 0);
|
BOOL batchUpdating = (_changeSetBatchUpdateCounter != 0);
|
||||||
// _changeSet must be available during batch update
|
// _changeSet must be available during batch update
|
||||||
ASDisplayNodeAssertTrue(batchUpdating == (_changeSet != nil));
|
ASDisplayNodeAssertTrue(batchUpdating == (_changeSet != nil));
|
||||||
return batchUpdating;
|
return batchUpdating;
|
||||||
|
|||||||
@ -181,6 +181,8 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
|
|||||||
|
|
||||||
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
- (void)reloadDataImmediatelyWithAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
||||||
|
|
||||||
|
- (void)waitUntilAllUpdatesAreCommitted;
|
||||||
|
|
||||||
/** @name Data Querying */
|
/** @name Data Querying */
|
||||||
|
|
||||||
- (NSUInteger)numberOfSections;
|
- (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)
|
#pragma mark - Data Source Access (Calling _dataSource)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user