Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for ASImageNode dynamic tint color #1644

Merged
merged 1 commit into from Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion Tests/ASImageNodeSnapshotTests.mm
Expand Up @@ -11,6 +11,18 @@

#import <AsyncDisplayKit/AsyncDisplayKit.h>

#if AS_AT_LEAST_IOS13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this method would need to be only used in iOS13+ only, is there a particular reason this is guarded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic color is only available for 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.