mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-01 12:23:20 +08:00
Addressing Scott's comments
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import "_ASDisplayLayer.h"
|
||||
|
||||
@interface ASDisplayNode (Beta)
|
||||
|
||||
+ (BOOL)shouldUseNewRenderingRange;
|
||||
@@ -22,10 +20,6 @@
|
||||
*/
|
||||
- (void)recursivelyEnsureDisplaySynchronously:(BOOL)synchronously;
|
||||
|
||||
- (void)drawRect:(CGRect)bounds withParameters:(id <NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing;
|
||||
|
||||
- (UIImage *)displayWithParameters:(id <NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled;
|
||||
|
||||
/**
|
||||
* @abstract allow modification of a context before the node's content is drawn
|
||||
*
|
||||
@@ -34,13 +28,13 @@
|
||||
* restoring context if necessary. Restoring can be done in contextDidDisplayNodeContent
|
||||
* This block can be called from *any* thread and it is unsafe to access any UIKit main thread properties from it.
|
||||
*/
|
||||
@property (nonatomic, strong) ASDisplayNodeContextModifier willDisplayNodeContentBlock;
|
||||
@property (nonatomic, strong) ASDisplayNodeContextModifier willDisplayNodeContentWithRenderingContext;
|
||||
|
||||
/**
|
||||
* @abstract allow modification of a context after the node's content is drawn
|
||||
*
|
||||
* @discussion
|
||||
*/
|
||||
@property (nonatomic, strong) ASDisplayNodeContextModifier didDisplayNodeContentBlock;
|
||||
@property (nonatomic, strong) ASDisplayNodeContextModifier didDisplayNodeContentWithRenderingContext;
|
||||
|
||||
@end
|
||||
|
||||
@@ -170,8 +170,8 @@
|
||||
|
||||
ASDN::MutexUnlocker u(_imageLock);
|
||||
|
||||
ASDisplayNodeContextModifier preContextBlock = self.willDisplayNodeContentBlock;
|
||||
ASDisplayNodeContextModifier postContextBlock = self.didDisplayNodeContentBlock;
|
||||
ASDisplayNodeContextModifier preContextBlock = self.willDisplayNodeContentWithRenderingContext;
|
||||
ASDisplayNodeContextModifier postContextBlock = self.didDisplayNodeContentWithRenderingContext;
|
||||
|
||||
BOOL hasValidCropBounds = cropEnabled && !CGRectIsNull(cropDisplayBounds) && !CGRectIsEmpty(cropDisplayBounds);
|
||||
|
||||
@@ -286,12 +286,21 @@
|
||||
[super displayDidFinish];
|
||||
|
||||
ASDN::MutexLocker l(_imageLock);
|
||||
|
||||
void (^displayCompletionBlock)(BOOL canceled) = _displayCompletionBlock;
|
||||
UIImage *image = _image;
|
||||
|
||||
ASDN::MutexLocker u(_imageLock);
|
||||
|
||||
// If we've got a block to perform after displaying, do it.
|
||||
if (_image && _displayCompletionBlock) {
|
||||
if (image && displayCompletionBlock) {
|
||||
|
||||
// FIXME: _displayCompletionBlock is not protected by lock
|
||||
_displayCompletionBlock(NO);
|
||||
displayCompletionBlock(NO);
|
||||
|
||||
ASDN::MutexLocker l(_imageLock);
|
||||
_displayCompletionBlock = nil;
|
||||
ASDN::MutexLocker u(_imageLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -274,8 +274,8 @@ static void __ASDisplayLayerDecrementConcurrentDisplayCount(BOOL displayIsAsync,
|
||||
}
|
||||
|
||||
CGContextRef currentContext = UIGraphicsGetCurrentContext();
|
||||
if (_preContextModifier) {
|
||||
_preContextModifier(currentContext);
|
||||
if (_willDisplayNodeContentWithRenderingContext) {
|
||||
_willDisplayNodeContentWithRenderingContext(currentContext);
|
||||
}
|
||||
|
||||
if (_flags.implementsInstanceDrawRect) {
|
||||
@@ -284,8 +284,8 @@ static void __ASDisplayLayerDecrementConcurrentDisplayCount(BOOL displayIsAsync,
|
||||
[[self class] drawRect:bounds withParameters:drawParameters isCancelled:isCancelledBlock isRasterizing:rasterizing];
|
||||
}
|
||||
|
||||
if (_postContextModifier) {
|
||||
_postContextModifier(currentContext);
|
||||
if (_didDisplayNodeContentWithRenderingContext) {
|
||||
_didDisplayNodeContentWithRenderingContext(currentContext);
|
||||
}
|
||||
|
||||
if (isCancelledBlock()) {
|
||||
@@ -389,28 +389,28 @@ static void __ASDisplayLayerDecrementConcurrentDisplayCount(BOOL displayIsAsync,
|
||||
[_displaySentinel increment];
|
||||
}
|
||||
|
||||
- (ASDisplayNodeContextModifier)willDisplayNodeContentBlock
|
||||
- (ASDisplayNodeContextModifier)willDisplayNodeContentWithRenderingContext
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _preContextModifier;
|
||||
return _willDisplayNodeContentWithRenderingContext;
|
||||
}
|
||||
|
||||
- (ASDisplayNodeContextModifier)didDisplayNodeContentBlock
|
||||
- (ASDisplayNodeContextModifier)didDisplayNodeContentWithRenderingContext
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _postContextModifier;
|
||||
return _didDisplayNodeContentWithRenderingContext;
|
||||
}
|
||||
|
||||
- (void)setWillDisplayNodeContentBlock:(ASDisplayNodeContextModifier)contextModifier
|
||||
- (void)setWillDisplayNodeContentWithRenderingContext:(ASDisplayNodeContextModifier)contextModifier
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_preContextModifier = contextModifier;
|
||||
_willDisplayNodeContentWithRenderingContext = contextModifier;
|
||||
}
|
||||
|
||||
- (void)setDidDisplayNodeContentBlock:(ASDisplayNodeContextModifier)contextModifier;
|
||||
- (void)setDidDisplayNodeContentWithRenderingContext:(ASDisplayNodeContextModifier)contextModifier;
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_postContextModifier = contextModifier;
|
||||
_didDisplayNodeContentWithRenderingContext = contextModifier;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#import "ASSentinel.h"
|
||||
#import "ASThread.h"
|
||||
#import "ASLayoutOptions.h"
|
||||
#import "_ASDisplayLayer.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -100,6 +101,18 @@ typedef NS_OPTIONS(NSUInteger, ASHierarchyState)
|
||||
*/
|
||||
- (void)recursivelyEnsureDisplaySynchronously:(BOOL)synchronously;
|
||||
|
||||
/**
|
||||
* @abstract instance version of drawRect class method
|
||||
* @see drawRect:withParameters:isCancelled:isRasterizing class method
|
||||
*/
|
||||
- (void)drawRect:(CGRect)bounds withParameters:(id <NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing;
|
||||
|
||||
/**
|
||||
* @abstract instance version of display class method
|
||||
* @see displayWithParameters:isCancelled class method
|
||||
*/
|
||||
- (UIImage *)displayWithParameters:(id <NSObject>)parameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled;
|
||||
|
||||
/**
|
||||
* @abstract Allows a node to bypass all ensureDisplay passes. Defaults to NO.
|
||||
*
|
||||
|
||||
@@ -103,8 +103,8 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides)
|
||||
|
||||
ASDisplayNodeExtraIvars _extra;
|
||||
|
||||
ASDisplayNodeContextModifier _preContextModifier;
|
||||
ASDisplayNodeContextModifier _postContextModifier;
|
||||
ASDisplayNodeContextModifier _willDisplayNodeContentWithRenderingContext;
|
||||
ASDisplayNodeContextModifier _didDisplayNodeContentWithRenderingContext;
|
||||
|
||||
#if TIME_DISPLAYNODE_OPS
|
||||
@public
|
||||
|
||||
Reference in New Issue
Block a user