mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
- Address various issues with tint color on text nodes
- Avoid accessing `self.tintColor` off-main since this will trigger an
assertion and might be undefined behavior
- Trigger setNeedsDisplay in cases of hierarchy change and
tintColorDidChange in ASButtonNode, ASTextNode{1,2}
- Fix bug in _ASTableViewCell where we were overwriting the tint color
instead of inheriting the correct value
- Add tests for new logic in changing hierarchy
116 lines
3.9 KiB
Plaintext
116 lines
3.9 KiB
Plaintext
//
|
|
// ASButtonNodeSnapshotTests.mm
|
|
// Texture
|
|
//
|
|
// Copyright (c) Pinterest, Inc. All rights reserved.
|
|
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
|
#import "ASSnapshotTestCase.h"
|
|
|
|
@interface ASButtonNodeSnapshotTests : ASSnapshotTestCase
|
|
|
|
@end
|
|
|
|
|
|
@implementation ASButtonNodeSnapshotTests
|
|
|
|
- (void)setUp
|
|
{
|
|
[super setUp];
|
|
self.recordMode = NO;
|
|
}
|
|
|
|
- (UIImage *)testImage
|
|
{
|
|
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"logo-square"
|
|
ofType:@"png"
|
|
inDirectory:@"TestResources"];
|
|
return [[UIImage imageWithContentsOfFile:path] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
}
|
|
|
|
- (void)testTintColor
|
|
{
|
|
|
|
ASButtonNode *node = [[ASButtonNode alloc] init];
|
|
node.tintColor = UIColor.redColor;
|
|
[node setImage:[self testImage] forState:UIControlStateNormal];
|
|
[node setTitle:@"Press Me"
|
|
withFont:[UIFont systemFontOfSize:48]
|
|
withColor:nil
|
|
forState:UIControlStateNormal];
|
|
node.imageNode.style.width = ASDimensionMake(200);
|
|
node.imageNode.style.height = ASDimensionMake(200);
|
|
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
|
|
ASSnapshotVerifyNode(node, nil);
|
|
}
|
|
|
|
- (void)testChangingTintColor
|
|
{
|
|
ASButtonNode *node = [[ASButtonNode alloc] init];
|
|
node.tintColor = UIColor.redColor;
|
|
[node setImage:[self testImage] forState:UIControlStateNormal];
|
|
[node setTitle:@"Press Me"
|
|
withFont:[UIFont systemFontOfSize:48]
|
|
withColor:nil
|
|
forState:UIControlStateNormal];
|
|
node.imageNode.style.width = ASDimensionMake(200);
|
|
node.imageNode.style.height = ASDimensionMake(200);
|
|
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
|
|
ASSnapshotVerifyNode(node, nil);
|
|
|
|
node.tintColor = UIColor.blueColor;
|
|
ASSnapshotVerifyNode(node, @"modified_tint");
|
|
}
|
|
|
|
|
|
- (void)testTintColorWithForegroundColorSet
|
|
{
|
|
ASButtonNode *node = [[ASButtonNode alloc] init];
|
|
node.tintColor = UIColor.redColor;
|
|
[node setImage:[self testImage] forState:UIControlStateNormal];
|
|
[node setTitle:@"Press Me"
|
|
withFont:[UIFont systemFontOfSize:48]
|
|
withColor:[UIColor blueColor]
|
|
forState:UIControlStateNormal];
|
|
node.imageNode.style.width = ASDimensionMake(200);
|
|
node.imageNode.style.height = ASDimensionMake(200);
|
|
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
|
|
ASSnapshotVerifyNode(node, nil);
|
|
}
|
|
|
|
- (void)testTintColorWithInheritedTintColor
|
|
{
|
|
ASDisplayNode *container = [[ASDisplayNode alloc] init];
|
|
container.tintColor = UIColor.redColor;
|
|
|
|
// Add to hierarchy, assert new tint is picked up
|
|
ASButtonNode *node = [[ASButtonNode alloc] init];
|
|
[container addSubnode:node];
|
|
[node setImage:[[self testImage] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
|
[node setTitle:@"Press Me"
|
|
withFont:[UIFont systemFontOfSize:48]
|
|
withColor:nil
|
|
forState:UIControlStateNormal];
|
|
node.imageNode.style.width = ASDimensionMake(200);
|
|
node.imageNode.style.height = ASDimensionMake(200);
|
|
container.style.preferredSize = CGSizeMake(1000,1000);
|
|
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
|
|
// Force load so the superview is set for the button _ASDisplayView
|
|
__unused UIView *v = container.view;
|
|
ASSnapshotVerifyNode(node, @"red_inherited_tint");
|
|
|
|
// Change hierarchy, assert new tint is picked up
|
|
ASDisplayNode *container2 = [[ASDisplayNode alloc] init];
|
|
container2.tintColor = UIColor.greenColor;
|
|
container2.style.preferredSize = CGSizeMake(1000,1000);
|
|
[container2 addSubnode:node];
|
|
ASDisplayNodeSizeToFitSize(node, CGSizeMake(1000, 1000));
|
|
// Force load so the superview is set for the button _ASDisplayView
|
|
__unused UIView *v2 = container2.view; // Force load
|
|
ASSnapshotVerifyNode(node, @"green_inherited_tint");
|
|
}
|
|
|
|
@end
|