mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
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:
committed by
Rahul Malik
parent
28be9bb21e
commit
ccee5666dd
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 354 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 354 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
Reference in New Issue
Block a user