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

deprecate ASGraphicsCreateImageWithTraitCollectionAndOptions #1836

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
CC583AD81EF9BDC300134156 /* OCMockObject+ASAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC583AC71EF9BAB400134156 /* OCMockObject+ASAdditions.mm */; };
CC583AD91EF9BDC600134156 /* ASDisplayNode+OCMock.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC583AC01EF9BAB400134156 /* ASDisplayNode+OCMock.mm */; };
CC58AA4B1E398E1D002C8CB4 /* ASBlockTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = CC58AA4A1E398E1D002C8CB4 /* ASBlockTypes.h */; settings = {ATTRIBUTES = (Public, ); }; };
CC698827247855F200487428 /* UIImage+ASConvenienceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC698826247855F200487428 /* UIImage+ASConvenienceTests.mm */; };
CC6AA2DA1E9F03B900978E87 /* ASDisplayNode+Ancestry.h in Headers */ = {isa = PBXBuildFile; fileRef = CC6AA2D81E9F03B900978E87 /* ASDisplayNode+Ancestry.h */; settings = {ATTRIBUTES = (Public, ); }; };
CC6AA2DB1E9F03B900978E87 /* ASDisplayNode+Ancestry.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC6AA2D91E9F03B900978E87 /* ASDisplayNode+Ancestry.mm */; };
CC7AF196200D9BD500A21BDE /* ASExperimentalFeatures.h in Headers */ = {isa = PBXBuildFile; fileRef = CC7AF195200D9BD500A21BDE /* ASExperimentalFeatures.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -911,6 +912,7 @@
CC583AC61EF9BAB400134156 /* OCMockObject+ASAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCMockObject+ASAdditions.h"; sourceTree = "<group>"; };
CC583AC71EF9BAB400134156 /* OCMockObject+ASAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "OCMockObject+ASAdditions.mm"; sourceTree = "<group>"; };
CC58AA4A1E398E1D002C8CB4 /* ASBlockTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASBlockTypes.h; sourceTree = "<group>"; };
CC698826247855F200487428 /* UIImage+ASConvenienceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIImage+ASConvenienceTests.mm"; sourceTree = "<group>"; };
CC6AA2D81E9F03B900978E87 /* ASDisplayNode+Ancestry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "ASDisplayNode+Ancestry.h"; path = "Base/ASDisplayNode+Ancestry.h"; sourceTree = "<group>"; };
CC6AA2D91E9F03B900978E87 /* ASDisplayNode+Ancestry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "ASDisplayNode+Ancestry.mm"; path = "Base/ASDisplayNode+Ancestry.mm"; sourceTree = "<group>"; };
CC7AF195200D9BD500A21BDE /* ASExperimentalFeatures.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASExperimentalFeatures.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1391,6 +1393,7 @@
CC3B208D1C3F7D0A00798563 /* ASWeakSetTests.mm */,
695BE2541DC1245C008E6EA5 /* ASWrapperSpecSnapshotTests.mm */,
407B8BAD2310E2ED00CB979E /* ASLayoutSpecUtilitiesTests.mm */,
CC698826247855F200487428 /* UIImage+ASConvenienceTests.mm */,
057D02C01AC0A66700C7AC3C /* AsyncDisplayKitTestHost */,
CC583ABF1EF9BAB400134156 /* Common */,
058D09C6195D04C000B7D73C /* Supporting Files */,
Expand Down Expand Up @@ -2302,6 +2305,7 @@
ACF6ED5C1B178DC700DA7C62 /* ASCenterLayoutSpecSnapshotTests.mm in Sources */,
9F06E5CD1B4CAF4200F015D8 /* ASCollectionViewTests.mm in Sources */,
2911485C1A77147A005D0878 /* ASControlNodeTests.mm in Sources */,
CC698827247855F200487428 /* UIImage+ASConvenienceTests.mm in Sources */,
CC01EB6F23105C7F00CDB61A /* ASImageNodeSnapshotTests.mm in Sources */,
CC3B208E1C3F7D0A00798563 /* ASWeakSetTests.mm in Sources */,
F711994E1D20C21100568860 /* ASDisplayNodeExtrasTests.mm in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ - (void)_updateClipCornerLayerContentsWithRadius:(CGFloat)radius backgroundColor
BOOL isRight = (idx == 1 || idx == 3);

CGSize size = CGSizeMake(radius + 1, radius + 1);
UIImage *newContents = ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, size, NO, self.contentsScaleForDisplay, nil, ^{
UIImage *newContents = ASGraphicsCreateImage(self.primitiveTraitCollection, size, NO, self.contentsScaleForDisplay, nil, nil, ^{
CGContextRef ctx = UIGraphicsGetCurrentContext();
if (isRight == YES) {
CGContextTranslateCTM(ctx, -radius + 1, 0);
Expand Down
3 changes: 1 addition & 2 deletions Source/ASImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return A transformed image.
*/
typedef UIImage * _Nullable (^asimagenode_modification_block_t)(UIImage *image);

typedef UIImage * _Nullable (^asimagenode_modification_block_t)(UIImage *image, ASPrimitiveTraitCollection traitCollection);

/**
* @abstract Draws images.
Expand Down
18 changes: 9 additions & 9 deletions Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ - (UIImage *)placeholderImage
__instanceLock__.lock();
ASPrimitiveTraitCollection tc = _primitiveTraitCollection;
__instanceLock__.unlock();
return ASGraphicsCreateImageWithTraitCollectionAndOptions(tc, size, NO, 1, nil, ^{
return ASGraphicsCreateImage(tc, size, NO, 1, nil, nil, ^{
AS::MutexLocker l(__instanceLock__);
[_placeholderColor setFill];
UIRectFill(CGRectMake(0, 0, size.width, size.height));
Expand Down Expand Up @@ -382,7 +382,7 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameter isCancelled:(NS_NOESC
BOOL stretchable = !UIEdgeInsetsEqualToEdgeInsets(image.capInsets, UIEdgeInsetsZero);
if (stretchable) {
if (imageModificationBlock != NULL) {
image = imageModificationBlock(image);
image = imageModificationBlock(image, drawParameter->_traitCollection);
}
return image;
}
Expand Down Expand Up @@ -498,7 +498,7 @@ + (ASWeakMapEntry *)contentsForkey:(ASImageNodeContentsKey *)key drawParameters:

+ (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(id)parameter isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled
{
// The following `ASGraphicsCreateImageWithTraitCollectionAndOptions` call will sometimes take take longer than 5ms on an
// The following `ASGraphicsCreateImage` call will sometimes take take longer than 5ms on an
// A5 processor for a 400x800 backingSize.
// Check for cancellation before we call it.
if (isCancelled()) {
Expand All @@ -509,7 +509,7 @@ + (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(

// Use contentsScale of 1.0 and do the contentsScale handling in boundsSizeInPixels so ASCroppedImageBackingSizeAndDrawRectInBounds
// will do its rounding on pixel instead of point boundaries
UIImage *result = ASGraphicsCreateImageWithTraitCollectionAndOptions(drawParameters->_traitCollection, key.backingSize, key.isOpaque, 1.0, key.image, ^{
UIImage *result = ASGraphicsCreateImage(drawParameters->_traitCollection, key.backingSize, key.isOpaque, 1.0, key.image, isCancelled, ^{
BOOL contextIsClean = YES;

CGContextRef context = UIGraphicsGetCurrentContext();
Expand Down Expand Up @@ -561,7 +561,7 @@ + (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(
}

if (key.imageModificationBlock) {
result = key.imageModificationBlock(result);
result = key.imageModificationBlock(result, drawParameters->_traitCollection);
}

return result;
Expand Down Expand Up @@ -810,8 +810,8 @@ - (void)asyncTraitCollectionDidChangeWithPreviousTraitCollection:(ASPrimitiveTra

asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(CGFloat borderWidth, UIColor *borderColor)
{
return ^(UIImage *originalImage) {
return ASGraphicsCreateImageWithOptions(originalImage.size, NO, originalImage.scale, originalImage, nil, ^{
return ^(UIImage *originalImage, ASPrimitiveTraitCollection traitCollection) {
return ASGraphicsCreateImage(traitCollection, originalImage.size, NO, originalImage.scale, originalImage, nil, ^{
UIBezierPath *roundOutline = [UIBezierPath bezierPathWithOvalInRect:(CGRect){CGPointZero, originalImage.size}];

// Make the image round
Expand All @@ -832,8 +832,8 @@ asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(CGFloat

asimagenode_modification_block_t ASImageNodeTintColorModificationBlock(UIColor *color)
{
return ^(UIImage *originalImage) {
UIImage *modifiedImage = ASGraphicsCreateImageWithOptions(originalImage.size, NO, originalImage.scale, originalImage, nil, ^{
return ^(UIImage *originalImage, ASPrimitiveTraitCollection traitCollection) {
UIImage *modifiedImage = ASGraphicsCreateImage(traitCollection, originalImage.size, NO, originalImage.scale, originalImage, nil, ^{
// Set color and render template
[color setFill];
UIImage *templateImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Expand Down
2 changes: 1 addition & 1 deletion Source/ASMapNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ - (void)takeSnapshot

CGRect finalImageRect = CGRectMake(0, 0, image.size.width, image.size.height);

image = ASGraphicsCreateImageWithTraitCollectionAndOptions(strongSelf.primitiveTraitCollection, image.size, YES, image.scale, image, ^{
image = ASGraphicsCreateImage(strongSelf.primitiveTraitCollection, image.size, YES, image.scale, image, nil, ^{
[image drawAtPoint:CGPointZero];

UIImage *pinImage;
Expand Down
2 changes: 1 addition & 1 deletion Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(NS_NOES
UIEdgeInsets textContainerInsets = drawParameter ? drawParameter->_textContainerInsets : UIEdgeInsetsZero;
ASTextKitRenderer *renderer = [drawParameter rendererForBounds:drawParameter->_bounds];

UIImage *result = ASGraphicsCreateImageWithTraitCollectionAndOptions(drawParameter->_traitCollection, CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height), drawParameter->_opaque, drawParameter->_contentScale, nil, ^{
UIImage *result = ASGraphicsCreateImage(drawParameter->_traitCollection, CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height), drawParameter->_opaque, drawParameter->_contentScale, nil, nil, ^{
CGContextRef context = UIGraphicsGetCurrentContext();
ASDisplayNodeAssert(context, @"This is no good without a context.");

Expand Down
6 changes: 4 additions & 2 deletions Source/Debug/AsyncDisplayKit+Debug.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ - (void)layout
UIColor *clipsBorderColor = [UIColor colorWithRed:30/255.0 green:90/255.0 blue:50/255.0 alpha:0.7];
CGRect imgRect = CGRectMake(0, 0, 2.0 * borderWidth + 1.0, 2.0 * borderWidth + 1.0);

UIImage *debugHighlightImage = ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, imgRect.size, NO, 1, nil, ^{
UIImage *debugHighlightImage = ASGraphicsCreateImage(self.primitiveTraitCollection, imgRect.size, NO, 1, nil, nil, ^{
[fillColor setFill];
UIRectFill(imgRect);

Expand Down Expand Up @@ -729,13 +729,15 @@ - (ASTextNode *)createDebugTextNode
- (ASImageNode *)createRangeNodeWithColor:(UIColor *)color
{
ASImageNode *rangeBarImageNode = [[ASImageNode alloc] init];
ASPrimitiveTraitCollection primitiveTraitCollection = ASPrimitiveTraitCollectionFromUITraitCollection(self.traitCollection);
rangeBarImageNode.image = [UIImage as_resizableRoundedImageWithCornerRadius:RANGE_BAR_CORNER_RADIUS
cornerColor:[UIColor clearColor]
fillColor:[color colorWithAlphaComponent:0.5]
borderColor:[[UIColor blackColor] colorWithAlphaComponent:0.9]
borderWidth:RANGE_BAR_BORDER_WIDTH
roundedCorners:UIRectCornerAllCorners
scale:[[UIScreen mainScreen] scale]];
scale:[[UIScreen mainScreen] scale]
traitCollection:primitiveTraitCollection];
[self addSubnode:rangeBarImageNode];

return rangeBarImageNode;
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASGraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ AS_EXTERN UIImage *ASGraphicsCreateImage(ASPrimitiveTraitCollection traitCollect
*
* @return The rendered image. You can also render intermediary images using UIGraphicsGetImageFromCurrentImageContext.
*/
AS_EXTERN UIImage *ASGraphicsCreateImageWithTraitCollectionAndOptions(ASPrimitiveTraitCollection traitCollection, CGSize size, BOOL opaque, CGFloat scale, UIImage * _Nullable sourceImage, void (NS_NOESCAPE ^work)(void));
AS_EXTERN UIImage *ASGraphicsCreateImageWithTraitCollectionAndOptions(ASPrimitiveTraitCollection traitCollection, CGSize size, BOOL opaque, CGFloat scale, UIImage * _Nullable sourceImage, void (NS_NOESCAPE ^work)(void)) ASDISPLAYNODE_DEPRECATED_MSG("Use ASGraphicsCreateImage instead");

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions Source/Private/ASDisplayNode+AsyncDisplay.mm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ - (asyncdisplaykit_async_transaction_operation_block_t)_displayBlockWithAsynchro
displayBlock = ^id{
CHECK_CANCELLED_AND_RETURN_NIL();

UIImage *image = ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, bounds.size, opaque, contentsScaleForDisplay, nil, ^{
UIImage *image = ASGraphicsCreateImage(self.primitiveTraitCollection, bounds.size, opaque, contentsScaleForDisplay, nil, isCancelledBlock, ^{
for (dispatch_block_t block in displayBlocks) {
if (isCancelledBlock()) return;
block();
Expand Down Expand Up @@ -247,7 +247,7 @@ - (asyncdisplaykit_async_transaction_operation_block_t)_displayBlockWithAsynchro
};

if (shouldCreateGraphicsContext) {
return ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, bounds.size, opaque, contentsScaleForDisplay, nil, workWithContext);
return ASGraphicsCreateImage(self.primitiveTraitCollection, bounds.size, opaque, contentsScaleForDisplay, nil, isCancelledBlock, workWithContext);
} else {
workWithContext();
return image;
Expand Down
59 changes: 56 additions & 3 deletions Source/UIImage+ASConvenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/ASBaseDefines.h>
#import <AsyncDisplayKit/ASTraitCollection.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -68,7 +69,20 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (UIImage *)as_resizableRoundedImageWithCornerRadius:(CGFloat)cornerRadius
cornerColor:(nullable UIColor *)cornerColor
fillColor:(UIColor *)fillColor NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT;
fillColor:(UIColor *)fillColor NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use as_resizableRoundedImageWithCornerRadius:cornerColor:fillColor:traitCollection: instead");

/**
* This generates a flat-color, rounded-corner resizeable image
*
* @param cornerRadius The radius of the rounded-corner
* @param cornerColor The fill color of the corners (For Alpha corners use clearColor)
* @param fillColor The fill color of the rounded-corner image
* @param traitCollection The trait collection.
*/
+ (UIImage *)as_resizableRoundedImageWithCornerRadius:(CGFloat)cornerRadius
cornerColor:(nullable UIColor *)cornerColor
fillColor:(UIColor *)fillColor
traitCollection:(ASPrimitiveTraitCollection) traitCollection NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT;

/**
* This generates a flat-color, rounded-corner resizeable image with a border
Expand All @@ -83,7 +97,43 @@ NS_ASSUME_NONNULL_BEGIN
cornerColor:(UIColor *)cornerColor
fillColor:(UIColor *)fillColor
borderColor:(nullable UIColor *)borderColor
borderWidth:(CGFloat)borderWidth NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT;
borderWidth:(CGFloat)borderWidth NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use as_resizableRoundedImageWithCornerRadius:cornerColor:fillColor:borderColor:borderWidth:traitCollection: instead");

/**
* This generates a flat-color, rounded-corner resizeable image with a border
*
* @param cornerRadius The radius of the rounded-corner
* @param cornerColor The fill color of the corners (For Alpha corners use clearColor)
* @param fillColor The fill color of the rounded-corner image
* @param borderColor The border color. Set to nil for no border.
* @param borderWidth The border width. Dummy value if borderColor = nil.
* @param traitCollection The trait collection.
*/
+ (UIImage *)as_resizableRoundedImageWithCornerRadius:(CGFloat)cornerRadius
cornerColor:(UIColor *)cornerColor
fillColor:(UIColor *)fillColor
borderColor:(nullable UIColor *)borderColor
borderWidth:(CGFloat)borderWidth traitCollection:(ASPrimitiveTraitCollection) traitCollection NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT;

/**
* This generates a flat-color, rounded-corner resizeable image with a border
*
* @param cornerRadius The radius of the rounded-corner
* @param cornerColor The fill color of the corners (For Alpha corners use clearColor)
* @param fillColor The fill color of the rounded-corner image
* @param borderColor The border color. Set to nil for no border.
* @param borderWidth The border width. Dummy value if borderColor = nil.
* @param roundedCorners Select individual or multiple corners to round. Set to UIRectCornerAllCorners to round all 4 corners.
* @param scale The number of pixels per point. Provide 0.0 to use the screen scale.
*/
+ (UIImage *)as_resizableRoundedImageWithCornerRadius:(CGFloat)cornerRadius
cornerColor:(nullable UIColor *)cornerColor
fillColor:(UIColor *)fillColor
borderColor:(nullable UIColor *)borderColor
borderWidth:(CGFloat)borderWidth
roundedCorners:(UIRectCorner)roundedCorners
scale:(CGFloat)scale NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use as_resizableRoundedImageWithCornerRadius:cornerColor:fillColor:borderColor:borderWidth:roundedCorners:traitCollection: instead");
;

/**
* This generates a flat-color, rounded-corner resizeable image with a border
Expand All @@ -95,14 +145,17 @@ NS_ASSUME_NONNULL_BEGIN
* @param borderWidth The border width. Dummy value if borderColor = nil.
* @param roundedCorners Select individual or multiple corners to round. Set to UIRectCornerAllCorners to round all 4 corners.
* @param scale The number of pixels per point. Provide 0.0 to use the screen scale.
* @param traitCollection The trait collection.
*/
+ (UIImage *)as_resizableRoundedImageWithCornerRadius:(CGFloat)cornerRadius
cornerColor:(nullable UIColor *)cornerColor
fillColor:(UIColor *)fillColor
borderColor:(nullable UIColor *)borderColor
borderWidth:(CGFloat)borderWidth
roundedCorners:(UIRectCorner)roundedCorners
scale:(CGFloat)scale NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT;
scale:(CGFloat)scale
traitCollection:(ASPrimitiveTraitCollection) traitCollection
NS_RETURNS_RETAINED AS_WARN_UNUSED_RESULT;

@end

Expand Down
Loading