Skip to content

Commit

Permalink
tests for ASImageNode dynamic tint color (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
vovasty committed Aug 30, 2019
1 parent 6464153 commit 0cd5561
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion Tests/ASImageNodeSnapshotTests.mm
Expand Up @@ -11,6 +11,18 @@

#import <AsyncDisplayKit/AsyncDisplayKit.h>

#if AS_AT_LEAST_IOS13
static UIImage* makeImageWithColor(UIColor *color, CGSize size) {
CGRect rect = CGRect{.origin = CGPointZero, .size = size};
UIGraphicsBeginImageContextWithOptions(size, false, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
#endif

@interface ASImageNodeSnapshotTests : ASSnapshotTestCase
@end

Expand Down Expand Up @@ -206,6 +218,7 @@ - (void)testUIGraphicsRendererDrawingExperiment
- (void)testDynamicAssetImage
{
if (@available(iOS 13.0, *)) {
// enable experimantal callback for traits change
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalTraitCollectionDidChangeWithPreviousCollection;
[ASConfigurationManager test_resetWithConfiguration:config];
Expand All @@ -222,8 +235,34 @@ - (void)testDynamicAssetImage
[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, @"user_interface_style_dark");
}];
}
}

- (void)testDynamicTintColor
{
if (@available(iOS 13.0, *)) {
// enable experimental callback for traits change
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalTraitCollectionDidChangeWithPreviousCollection;
[ASConfigurationManager test_resetWithConfiguration:config];

NSLog(@"%@", image);
UIImage *image = makeImageWithColor(UIColor.redColor, CGSize{.width = 100, .height = 100});
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIColor* tintColor = UIColor.systemBackgroundColor;
ASImageNode *node = [[ASImageNode alloc] init];

node.image = image;
node.tintColor = tintColor;

ASDisplayNodeSizeToFitSize(node, image.size);

[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, @"user_interface_style_light");
}];

[[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark] performAsCurrentTraitCollection:^{
ASSnapshotVerifyNode(node, @"user_interface_style_dark");
}];
}
}
#endif // #if AS_AT_LEAST_IOS13
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0cd5561

Please sign in to comment.