-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASImageNode tintColor improvements. (#1668)
* ASImageNode tintColor improvements. When ASImageNodes changes tintColor or enters the hierarchy, ensure -setNeedsDisplay is called if the image is templated. Add unit tests to ensure this behavior works.
- Loading branch information
Greg Bolsinga
authored
Sep 12, 2019
1 parent
492da8a
commit 368aa3a
Showing
3 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// | ||
// ASImageNodeTests.m | ||
// Texture | ||
// | ||
// Copyright (c) Pinterest, Inc. All rights reserved. | ||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <OCMock/OCMock.h> | ||
#import <AsyncDisplayKit/ASImageNode.h> | ||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h> | ||
|
||
@interface ASImageTestNode : ASImageNode | ||
@property (nonatomic, readonly) NSUInteger setNeedsDisplayCount; | ||
@end | ||
|
||
@implementation ASImageTestNode | ||
|
||
- (void)setNeedsDisplay | ||
{ | ||
// Do not call super so that the background mechanics do not fire up. | ||
_setNeedsDisplayCount += 1; | ||
} | ||
|
||
@end | ||
|
||
@interface ASImageNodeTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation ASImageNodeTests | ||
|
||
- (void)testImage_didEnterHierarchy | ||
{ | ||
id imageMock = OCMClassMock(UIImage.class); | ||
|
||
ASImageTestNode *imageNode = [[ASImageTestNode alloc] init]; | ||
imageNode.layerBacked = YES; | ||
imageNode.image = imageMock; | ||
|
||
CALayer *layer = imageNode.layer; | ||
XCTAssertNotNil(layer); | ||
id<CALayerDelegate> layerDelegate = layer.delegate; | ||
|
||
NSUInteger initialSetNeedsDisplayCount = imageNode.setNeedsDisplayCount; | ||
XCTAssertEqual(initialSetNeedsDisplayCount, 1); | ||
|
||
[layerDelegate actionForLayer:layer forKey:kCAOnOrderIn]; | ||
|
||
XCTAssertEqual(imageNode.setNeedsDisplayCount, initialSetNeedsDisplayCount); | ||
|
||
[layerDelegate actionForLayer:layer forKey:kCAOnOrderOut]; | ||
|
||
[imageMock stopMocking]; | ||
} | ||
|
||
- (void)testTemplateImage_didEnterHierarchy | ||
{ | ||
id imageMock = OCMClassMock(UIImage.class); | ||
OCMStub([imageMock renderingMode]).andReturn(UIImageRenderingModeAlwaysTemplate); | ||
|
||
ASImageTestNode *imageNode = [[ASImageTestNode alloc] init]; | ||
imageNode.layerBacked = YES; | ||
imageNode.image = imageMock; | ||
|
||
CALayer *layer = imageNode.layer; | ||
XCTAssertNotNil(layer); | ||
id<CALayerDelegate> layerDelegate = layer.delegate; | ||
|
||
NSUInteger initialSetNeedsDisplayCount = imageNode.setNeedsDisplayCount; | ||
XCTAssertEqual(initialSetNeedsDisplayCount, 1); | ||
|
||
[layerDelegate actionForLayer:layer forKey:kCAOnOrderIn]; | ||
|
||
XCTAssertEqual(imageNode.setNeedsDisplayCount, initialSetNeedsDisplayCount + 1); | ||
|
||
[layerDelegate actionForLayer:layer forKey:kCAOnOrderOut]; | ||
|
||
[imageMock stopMocking]; | ||
} | ||
|
||
- (void)testImage_tintColorDidChange | ||
{ | ||
id imageMock = OCMClassMock(UIImage.class); | ||
|
||
ASImageTestNode *imageNode = [[ASImageTestNode alloc] init]; | ||
imageNode.image = imageMock; | ||
|
||
NSUInteger initialSetNeedsDisplayCount = imageNode.setNeedsDisplayCount; | ||
XCTAssertEqual(initialSetNeedsDisplayCount, 1); | ||
|
||
[imageNode tintColorDidChange]; | ||
XCTAssertEqual(imageNode.setNeedsDisplayCount, initialSetNeedsDisplayCount); | ||
|
||
[imageMock stopMocking]; | ||
} | ||
|
||
- (void)testTemplateImage_tintColorDidChange | ||
{ | ||
id imageMock = OCMClassMock(UIImage.class); | ||
OCMStub([imageMock renderingMode]).andReturn(UIImageRenderingModeAlwaysTemplate); | ||
|
||
ASImageTestNode *imageNode = [[ASImageTestNode alloc] init]; | ||
imageNode.image = imageMock; | ||
|
||
NSUInteger initialSetNeedsDisplayCount = imageNode.setNeedsDisplayCount; | ||
XCTAssertEqual(initialSetNeedsDisplayCount, 1); | ||
|
||
[imageNode tintColorDidChange]; | ||
XCTAssertEqual(imageNode.setNeedsDisplayCount, initialSetNeedsDisplayCount + 1); | ||
|
||
[imageMock stopMocking]; | ||
} | ||
|
||
@end |