Allow full color tinting on grayscale template images. (#1629)

* Allow full color tinting on grayscale template images.

* Signing a commit with the correct email address.

* Add snapshot test for a grayscale image with ASExperimentalDrawingGlobal enabled.
This commit is contained in:
Jessie Alvarez
2019-08-22 12:53:49 -07:00
committed by Rahul Malik
parent 28be9bb21e
commit ccee5666dd
6 changed files with 44 additions and 1 deletions
+8
View File
@@ -594,6 +594,14 @@ static ASWeakMap<ASImageNodeContentsKey *, UIImage *> *cache = nil;
[self setNeedsDisplay];
}
- (void)tintColorDidChange
{
[super tintColorDidChange];
if (_image.renderingMode == UIImageRenderingModeAlwaysTemplate) {
[self setNeedsDisplay];
}
}
#pragma mark Interface State
- (void)clearContents
+9 -1
View File
@@ -47,7 +47,15 @@ UIImage *ASGraphicsCreateImageWithOptions(CGSize size, BOOL opaque, CGFloat scal
UIGraphicsImageRendererFormat *format;
if (sourceImage) {
format = sourceImage.imageRendererFormat;
if (sourceImage.renderingMode == UIImageRenderingModeAlwaysTemplate) {
// Template images will be black and transparent, so if we use
// sourceImage.imageRenderFormat it will assume a grayscale color space.
// This is not good because a template image should be able to tint to any color,
// so we'll just use the default here.
format = defaultFormat;
} else {
format = sourceImage.imageRendererFormat;
}
// We only want the private bits (color space and bits per component) from the image.
// We have our own ideas about opacity and scale.
format.opaque = opaque;
+27
View File
@@ -30,6 +30,14 @@
return [UIImage imageWithContentsOfFile:path];
}
- (UIImage *)testGrayscaleImage
{
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"logo-square-black"
ofType:@"png"
inDirectory:@"TestResources"];
return [UIImage imageWithContentsOfFile:path];
}
- (void)testRenderLogoSquare
{
// trivial test case to ensure ASSnapshotTestCase works
@@ -79,6 +87,25 @@
ASSnapshotVerifyNode(node, @"blue_tint");
}
- (void)testTintColorOnGrayscaleNodePropertyAlwaysTemplate
{
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalDrawingGlobal;
[ASConfigurationManager test_resetWithConfiguration:config];
UIImage *test = [self testGrayscaleImage];
ASImageNode *node = [[ASImageNode alloc] init];
node.image = [test imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
node.tintColor = UIColor.redColor;
ASDisplayNodeSizeToFitSize(node, test.size);
// Tint color should change view
ASSnapshotVerifyNode(node, @"red_tint");
node.tintColor = UIColor.blueColor;
// Tint color should change view
ASSnapshotVerifyNode(node, @"blue_tint");
}
- (void)testTintColorOnNodePropertyAutomatic
{
UIImage *test = [self testImage];
Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB