Remove ASImageNode's tint property.

ASImageNodeTint is inflexible (your options are "no tint" and "use
`[UIColor grayColor]`") and needlessly complicates the ASImageNode
implementation.  Use ASImageNodeTintColorModificationBlock() instead.
Closes #383.
This commit is contained in:
Nadine Salter 2015-03-20 12:37:27 -07:00
parent 1dc4b42dce
commit 7344cb98bb
2 changed files with 2 additions and 51 deletions

View File

@ -9,21 +9,6 @@
#import <AsyncDisplayKit/ASControlNode.h> #import <AsyncDisplayKit/ASControlNode.h>
/**
* Image tints.
*/
typedef NS_ENUM(NSUInteger, ASImageNodeTint) {
/**
* No tint.
*/
ASImageNodeTintNormal = 0,
/**
* Display the image in greyscale.
*/
ASImageNodeTintGreyscale,
};
/** /**
* Image modification block. Use to transform an image before display. * Image modification block. Use to transform an image before display.
* *
@ -49,11 +34,6 @@ typedef UIImage *(^asimagenode_modification_block_t)(UIImage *image);
*/ */
@property (atomic, retain) UIImage *image; @property (atomic, retain) UIImage *image;
/**
* @abstract Simple way to tint the image.
*/
@property (nonatomic, assign) ASImageNodeTint tint;
/** /**
@abstract The placeholder color. @abstract The placeholder color.
*/ */

View File

@ -24,7 +24,6 @@
@property (nonatomic, retain) UIImage *image; @property (nonatomic, retain) UIImage *image;
@property (nonatomic, assign) CGRect bounds; @property (nonatomic, assign) CGRect bounds;
@property (nonatomic, assign) CGFloat contentsScale; @property (nonatomic, assign) CGFloat contentsScale;
@property (nonatomic, assign) ASImageNodeTint tint;
@property (nonatomic, retain) UIColor *backgroundColor; @property (nonatomic, retain) UIColor *backgroundColor;
@property (nonatomic, assign) UIViewContentMode contentMode; @property (nonatomic, assign) UIViewContentMode contentMode;
@property (nonatomic, assign) CGRect cropRect; @property (nonatomic, assign) CGRect cropRect;
@ -35,7 +34,7 @@
// TODO: eliminate explicit parameters with a set of keys copied from the node // TODO: eliminate explicit parameters with a set of keys copied from the node
@implementation _ASImageNodeDrawParameters @implementation _ASImageNodeDrawParameters
- (id)initWithCrop:(BOOL)cropEnabled opaque:(BOOL)opaque image:(UIImage *)image bounds:(CGRect)bounds contentsScale:(CGFloat)contentsScale backgroundColor:(UIColor *)backgroundColor tint:(ASImageNodeTint)tint contentMode:(UIViewContentMode)contentMode cropRect:(CGRect)cropRect imageModificationBlock:(asimagenode_modification_block_t)imageModificationBlock - (id)initWithCrop:(BOOL)cropEnabled opaque:(BOOL)opaque image:(UIImage *)image bounds:(CGRect)bounds contentsScale:(CGFloat)contentsScale backgroundColor:(UIColor *)backgroundColor contentMode:(UIViewContentMode)contentMode cropRect:(CGRect)cropRect imageModificationBlock:(asimagenode_modification_block_t)imageModificationBlock
{ {
self = [self init]; self = [self init];
if (!self) return nil; if (!self) return nil;
@ -46,7 +45,6 @@
_bounds = bounds; _bounds = bounds;
_contentsScale = contentsScale; _contentsScale = contentsScale;
_backgroundColor = backgroundColor; _backgroundColor = backgroundColor;
_tint = tint;
_contentMode = contentMode; _contentMode = contentMode;
_cropRect = cropRect; _cropRect = cropRect;
_imageModificationBlock = [imageModificationBlock copy]; _imageModificationBlock = [imageModificationBlock copy];
@ -56,7 +54,7 @@
- (NSString *)description - (NSString *)description
{ {
return [NSString stringWithFormat:@"<%@ : %p image:%@ cropEnabled:%@ opaque:%@ bounds:%@ contentsScale:%.2f backgroundColor:%@ tint:%zd contentMode:%@ cropRect:%@>", [self class], self, self.image, @(self.cropEnabled), @(self.opaque), NSStringFromCGRect(self.bounds), self.contentsScale, self.backgroundColor, self.tint, ASDisplayNodeNSStringFromUIContentMode(self.contentMode), NSStringFromCGRect(self.cropRect)]; return [NSString stringWithFormat:@"<%@ : %p image:%@ cropEnabled:%@ opaque:%@ bounds:%@ contentsScale:%.2f backgroundColor:%@ contentMode:%@ cropRect:%@>", [self class], self, self.image, @(self.cropEnabled), @(self.opaque), NSStringFromCGRect(self.bounds), self.contentsScale, self.backgroundColor, ASDisplayNodeNSStringFromUIContentMode(self.contentMode), NSStringFromCGRect(self.cropRect)];
} }
@end @end
@ -72,7 +70,6 @@
// Cropping. // Cropping.
BOOL _cropEnabled; // Defaults to YES. BOOL _cropEnabled; // Defaults to YES.
ASImageNodeTint _tint;
CGRect _cropRect; // Defaults to CGRectMake(0.5, 0.5, 0, 0) CGRect _cropRect; // Defaults to CGRectMake(0.5, 0.5, 0, 0)
CGRect _cropDisplayBounds; CGRect _cropDisplayBounds;
} }
@ -124,23 +121,6 @@
return _image; return _image;
} }
- (void)setTint:(ASImageNodeTint)tint
{
ASDN::MutexLocker l(_imageLock);
if (_tint != tint) {
_tint = tint;
ASDisplayNodePerformBlockOnMainThread(^{
[self setNeedsDisplay];
});
}
}
- (ASImageNodeTint)tint
{
ASDN::MutexLocker l(_imageLock);
return _tint;
}
- (void)setPlaceholderColor:(UIColor *)placeholderColor - (void)setPlaceholderColor:(UIColor *)placeholderColor
{ {
_placeholderColor = placeholderColor; _placeholderColor = placeholderColor;
@ -159,7 +139,6 @@
bounds:(hasValidCropBounds ? _cropDisplayBounds : self.bounds) bounds:(hasValidCropBounds ? _cropDisplayBounds : self.bounds)
contentsScale:self.contentsScaleForDisplay contentsScale:self.contentsScaleForDisplay
backgroundColor:self.backgroundColor backgroundColor:self.backgroundColor
tint:self.tint
contentMode:self.contentMode contentMode:self.contentMode
cropRect:self.cropRect cropRect:self.cropRect
imageModificationBlock:self.imageModificationBlock]; imageModificationBlock:self.imageModificationBlock];
@ -230,16 +209,8 @@
// will do its rounding on pixel instead of point boundaries // will do its rounding on pixel instead of point boundaries
UIGraphicsBeginImageContextWithOptions(backingSize, parameters.opaque, 1.0); UIGraphicsBeginImageContextWithOptions(backingSize, parameters.opaque, 1.0);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:imageDrawRect]; [image drawInRect:imageDrawRect];
if (parameters.tint == ASImageNodeTintGreyscale) {
[[UIColor grayColor] setFill];
CGContextSetBlendMode(context, kCGBlendModeColor);
CGContextFillRect(context, (CGRect){.size = backingSize});
}
if (isCancelled()) { if (isCancelled()) {
UIGraphicsEndImageContext(); UIGraphicsEndImageContext();
return nil; return nil;