mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Move ASDisplayNodePerformBlockOnMainThread to ASInternalHelpers
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#import "ASCollectionViewLayoutController.h"
|
||||
#import "ASRangeController.h"
|
||||
#import "ASCollectionDataController.h"
|
||||
#import "ASDisplayNodeInternal.h"
|
||||
#import "ASBatchFetching.h"
|
||||
#import "UICollectionViewLayout+ASConvenience.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
@@ -269,7 +268,7 @@ static BOOL _isInterceptedSelector(SEL sel)
|
||||
- (void)reloadDataWithCompletion:(void (^)())completion
|
||||
{
|
||||
ASDisplayNodeAssert(self.asyncDelegate, @"ASCollectionView's asyncDelegate property must be set.");
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
_superIsPendingDataLoad = YES;
|
||||
[super reloadData];
|
||||
});
|
||||
|
||||
@@ -57,17 +57,6 @@ BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector)
|
||||
return ASSubclassOverridesSelector([ASDisplayNode class], subclass, selector);
|
||||
}
|
||||
|
||||
void ASDisplayNodePerformBlockOnMainThread(void (^block)())
|
||||
{
|
||||
if ([NSThread isMainThread]) {
|
||||
block();
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
block();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)())
|
||||
{
|
||||
ASDisplayNodeCAssertNotNil(block, @"block is required");
|
||||
@@ -79,7 +68,7 @@ void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)
|
||||
// Hold the lock to avoid a race where the node gets loaded while the block is in-flight.
|
||||
ASDN::MutexLocker l(node->_propertyLock);
|
||||
if (node.nodeLoaded) {
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
block();
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
_image = image;
|
||||
|
||||
ASDN::MutexUnlocker u(_imageLock);
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
[self invalidateCalculatedLayout];
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
@@ -306,7 +306,7 @@
|
||||
// If we have an image to display, display it, respecting our recrop flag.
|
||||
if (self.image)
|
||||
{
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
if (recropImmediately)
|
||||
[self displayImmediately];
|
||||
else
|
||||
@@ -334,7 +334,7 @@
|
||||
BOOL isCroppingImage = ((boundsSize.width < imageSize.width) || (boundsSize.height < imageSize.height));
|
||||
|
||||
// Re-display if we need to.
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
if (self.nodeLoaded && self.contentMode == UIViewContentModeScaleAspectFill && isCroppingImage)
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#import "ASCollectionViewLayoutController.h"
|
||||
#import "ASLayoutController.h"
|
||||
#import "ASRangeController.h"
|
||||
#import "ASDisplayNodeInternal.h"
|
||||
#import "ASBatchFetching.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
#import "ASLayout.h"
|
||||
@@ -334,7 +333,7 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
|
||||
- (void)reloadDataWithCompletion:(void (^)())completion
|
||||
{
|
||||
ASDisplayNodeAssert(self.asyncDelegate, @"ASTableView's asyncDelegate property must be set.");
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
[super reloadData];
|
||||
});
|
||||
[_dataController reloadDataWithAnimationOptions:UITableViewRowAnimationNone completion:completion];
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#import "ASCellNode.h"
|
||||
#import "ASDisplayNode.h"
|
||||
#import "ASMultidimensionalArrayUtils.h"
|
||||
#import "ASDisplayNodeInternal.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
#import "ASLayout.h"
|
||||
|
||||
//#define LOG(...) NSLog(__VA_ARGS__)
|
||||
@@ -208,7 +208,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
// Deep copy is critical here, or future edits to the sub-arrays will pollute state between _editing and _complete on different threads.
|
||||
NSMutableArray *completedNodes = (NSMutableArray *)ASMultidimensionalArrayDeepMutableCopy(editingNodes);
|
||||
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
_completedNodes[kind] = completedNodes;
|
||||
if (completionBlock) {
|
||||
completionBlock(nodes, indexPaths);
|
||||
@@ -227,7 +227,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
ASDeleteElementsInMultidimensionalArrayAtIndexPaths(editingNodes, indexPaths);
|
||||
_editingNodes[kind] = editingNodes;
|
||||
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths(_completedNodes[kind], indexPaths);
|
||||
ASDeleteElementsInMultidimensionalArrayAtIndexPaths(_completedNodes[kind], indexPaths);
|
||||
if (completionBlock) {
|
||||
@@ -250,7 +250,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
// Deep copy is critical here, or future edits to the sub-arrays will pollute state between _editing and _complete on different threads.
|
||||
NSArray *sectionsForCompleted = (NSMutableArray *)ASMultidimensionalArrayDeepMutableCopy(sections);
|
||||
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
[_completedNodes[kind] insertObjects:sectionsForCompleted atIndexes:indexSet];
|
||||
if (completionBlock) {
|
||||
completionBlock(sections, indexSet);
|
||||
@@ -263,7 +263,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
if (indexSet.count == 0)
|
||||
return;
|
||||
[_editingNodes[kind] removeObjectsAtIndexes:indexSet];
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
[_completedNodes[kind] removeObjectsAtIndexes:indexSet];
|
||||
if (completionBlock) {
|
||||
completionBlock(indexSet);
|
||||
@@ -512,7 +512,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
LOG(@"endUpdatesWithCompletion - beginning");
|
||||
|
||||
[_editingTransactionQueue addOperationWithBlock:^{
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
// Deep copy _completedNodes to _externalCompletedNodes.
|
||||
// Any external queries from now on will be done on _externalCompletedNodes, to guarantee data consistency with the delegate.
|
||||
_externalCompletedNodes = (NSMutableArray *)ASMultidimensionalArrayDeepMutableCopy(_completedNodes[ASDataControllerRowNodeKind]);
|
||||
@@ -532,7 +532,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
[_pendingEditCommandBlocks removeAllObjects];
|
||||
|
||||
[_editingTransactionQueue addOperationWithBlock:^{
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
// Now that the transaction is done, _completedNodes can be accessed externally again.
|
||||
_externalCompletedNodes = nil;
|
||||
|
||||
@@ -819,7 +819,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
||||
// i.e there might be some nodes that were measured using the old constrained size but haven't been added to _completedNodes
|
||||
// (see _layoutNodes:atIndexPaths:withAnimationOptions:).
|
||||
[_editingTransactionQueue addOperationWithBlock:^{
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
for (NSString *kind in [_completedNodes keyEnumerator]) {
|
||||
[self _relayoutNodesOfKind:kind];
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
#import "ASAssert.h"
|
||||
#import "ASDisplayNodeExtras.h"
|
||||
#import "ASDisplayNodeInternal.h"
|
||||
#import "ASMultiDimensionalArrayUtils.h"
|
||||
#import "ASRangeHandlerRender.h"
|
||||
#import "ASRangeHandlerPreload.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
|
||||
@interface ASRangeController () {
|
||||
BOOL _rangeIsValid;
|
||||
@@ -177,13 +177,13 @@
|
||||
#pragma mark - ASDataControllerDelegete
|
||||
|
||||
- (void)dataControllerBeginUpdates:(ASDataController *)dataController {
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
[_delegate rangeControllerBeginUpdates:self];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dataController:(ASDataController *)dataController endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion {
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
[_delegate rangeController:self endUpdatesAnimated:animated completion:completion];
|
||||
});
|
||||
}
|
||||
@@ -196,14 +196,14 @@
|
||||
[nodeSizes addObject:[NSValue valueWithCGSize:node.calculatedSize]];
|
||||
}];
|
||||
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
_rangeIsValid = NO;
|
||||
[_delegate rangeController:self didInsertNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dataController:(ASDataController *)dataController didDeleteNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions {
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
_rangeIsValid = NO;
|
||||
[_delegate rangeController:self didDeleteNodes:nodes atIndexPaths:indexPaths withAnimationOptions:animationOptions];
|
||||
});
|
||||
@@ -222,14 +222,14 @@
|
||||
[sectionNodeSizes addObject:nodeSizes];
|
||||
}];
|
||||
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
_rangeIsValid = NO;
|
||||
[_delegate rangeController:self didInsertSectionsAtIndexSet:indexSet withAnimationOptions:animationOptions];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dataController:(ASDataController *)dataController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions {
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
ASPerformBlockOnMainThread(^{
|
||||
_rangeIsValid = NO;
|
||||
[_delegate rangeController:self didDeleteSectionsAtIndexSet:indexSet withAnimationOptions:animationOptions];
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
return _getFromLayer(cornerRadius);
|
||||
}
|
||||
|
||||
-(void)setCornerRadius:(CGFloat)newCornerRadius
|
||||
- (void)setCornerRadius:(CGFloat)newCornerRadius
|
||||
{
|
||||
_bridge_prologue;
|
||||
_setToLayer(cornerRadius, newCornerRadius);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#import "ASLayoutOptions.h"
|
||||
|
||||
BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector);
|
||||
void ASDisplayNodePerformBlockOnMainThread(void (^block)());
|
||||
void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)());
|
||||
|
||||
typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) {
|
||||
|
||||
@@ -16,6 +16,7 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
|
||||
|
||||
BOOL ASSubclassOverridesSelector(Class superclass, Class subclass, SEL selector);
|
||||
BOOL ASSubclassOverridesClassSelector(Class superclass, Class subclass, SEL selector);
|
||||
void ASPerformBlockOnMainThread(void (^block)());
|
||||
|
||||
CGFloat ASScreenScale();
|
||||
|
||||
|
||||
@@ -46,6 +46,17 @@ static void ASDispatchOnceOnMainThread(dispatch_once_t *predicate, dispatch_bloc
|
||||
}
|
||||
}
|
||||
|
||||
void ASPerformBlockOnMainThread(void (^block)())
|
||||
{
|
||||
if ([NSThread isMainThread]) {
|
||||
block();
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
block();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
CGFloat ASScreenScale()
|
||||
{
|
||||
static CGFloat _scale;
|
||||
|
||||
Reference in New Issue
Block a user