diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f88d83431..0267e342b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,4 @@ - Move more properties from ASTableView, ASCollectionView to their respective node classes. [Adlai Holler](https://github.com/Adlai-Holler) - Remove finalLayoutElement [Michael Schneider] (https://github.com/maicki)[#96](https://github.com/TextureGroup/Texture/pull/96) - Add ASPageTable - A map table for fast retrieval of objects within a certain page [Huy Nguyen](https://github.com/nguyenhuy) +- [ASDisplayNode] Pass drawParameter in rendering context callbacks [Michael Schneider](https://github.com/maicki)[#248](https://github.com/TextureGroup/Texture/pull/248) diff --git a/Source/ASDisplayNode.h b/Source/ASDisplayNode.h index 0c2fa1fa8d..207b284fb6 100644 --- a/Source/ASDisplayNode.h +++ b/Source/ASDisplayNode.h @@ -56,7 +56,7 @@ typedef void (^ASDisplayNodeDidLoadBlock)(__kindof ASDisplayNode * node); /** * ASDisplayNode will / did render node content in context. */ -typedef void (^ASDisplayNodeContextModifier)(CGContextRef context); +typedef void (^ASDisplayNodeContextModifier)(CGContextRef context, id _Nullable drawParameters); /** * ASDisplayNode layout spec block. This block can be used instead of implementing layoutSpecThatFits: in subclass diff --git a/Source/ASImageNode.mm b/Source/ASImageNode.mm index e933461ad3..606652cb4a 100644 --- a/Source/ASImageNode.mm +++ b/Source/ASImageNode.mm @@ -413,8 +413,11 @@ struct ASImageNodeDrawParameters { return nil; } - ASWeakMapEntry *entry = [self.class contentsForkey:contentsKey isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled]; - if (entry == nil) { // If nil, we were cancelled. + ASWeakMapEntry *entry = [self.class contentsForkey:contentsKey + drawParameters:parameter + isCancelled:isCancelled]; + // If nil, we were cancelled. + if (entry == nil) { return nil; } @@ -428,7 +431,7 @@ struct ASImageNodeDrawParameters { static ASWeakMap *cache = nil; static ASDN::Mutex cacheLock; -+ (ASWeakMapEntry *)contentsForkey:(ASImageNodeContentsKey *)key isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled ++ (ASWeakMapEntry *)contentsForkey:(ASImageNodeContentsKey *)key drawParameters:(id)drawParameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled { { ASDN::MutexLocker l(cacheLock); @@ -443,7 +446,7 @@ static ASDN::Mutex cacheLock; } // cache miss - UIImage *contents = [self createContentsForkey:key isCancelled:isCancelled]; + UIImage *contents = [self createContentsForkey:key drawParameters:drawParameters isCancelled:isCancelled]; if (contents == nil) { // If nil, we were cancelled return nil; } @@ -454,7 +457,7 @@ static ASDN::Mutex cacheLock; } } -+ (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled ++ (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(id)drawParameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled { // The following `UIGraphicsBeginImageContextWithOptions` call will sometimes take take longer than 5ms on an // A5 processor for a 400x800 backingSize. @@ -471,7 +474,7 @@ static ASDN::Mutex cacheLock; CGContextRef context = UIGraphicsGetCurrentContext(); if (context && key.willDisplayNodeContentWithRenderingContext) { - key.willDisplayNodeContentWithRenderingContext(context); + key.willDisplayNodeContentWithRenderingContext(context, drawParameters); contextIsClean = NO; } @@ -503,7 +506,7 @@ static ASDN::Mutex cacheLock; } if (context && key.didDisplayNodeContentWithRenderingContext) { - key.didDisplayNodeContentWithRenderingContext(context); + key.didDisplayNodeContentWithRenderingContext(context, drawParameters); } // The following `UIGraphicsGetImageFromCurrentImageContext` call will commonly take more than 20ms on an @@ -517,7 +520,7 @@ static ASDN::Mutex cacheLock; UIGraphicsEndImageContext(); - if (key.imageModificationBlock != NULL) { + if (key.imageModificationBlock) { result = key.imageModificationBlock(result); } diff --git a/Source/Private/ASDisplayNode+AsyncDisplay.mm b/Source/Private/ASDisplayNode+AsyncDisplay.mm index e34357f0a5..201caed8c8 100644 --- a/Source/Private/ASDisplayNode+AsyncDisplay.mm +++ b/Source/Private/ASDisplayNode+AsyncDisplay.mm @@ -251,7 +251,7 @@ // For -display methods, we don't have a context, and thus will not call the _willDisplayNodeContentWithRenderingContext or // _didDisplayNodeContentWithRenderingContext blocks. It's up to the implementation of -display... to do what it needs. if (willDisplayNodeContentWithRenderingContext != nil) { - willDisplayNodeContentWithRenderingContext(currentContext); + willDisplayNodeContentWithRenderingContext(currentContext, drawParameters); } // Decide if we use a class or instance method to draw or display. @@ -266,7 +266,7 @@ } if (didDisplayNodeContentWithRenderingContext != nil) { - didDisplayNodeContentWithRenderingContext(currentContext); + didDisplayNodeContentWithRenderingContext(currentContext, drawParameters); } if (shouldCreateGraphicsContext) { diff --git a/examples/LayoutSpecExamples-Swift/Sample/LayoutExampleNode.swift b/examples/LayoutSpecExamples-Swift/Sample/LayoutExampleNode.swift index 2f057d7507..a3c9dc02f5 100644 --- a/examples/LayoutSpecExamples-Swift/Sample/LayoutExampleNode.swift +++ b/examples/LayoutSpecExamples-Swift/Sample/LayoutExampleNode.swift @@ -74,7 +74,7 @@ class PhotoWithInsetTextOverlay : LayoutExampleNode { backgroundColor = .clear photoNode.url = URL(string: "http://asyncdisplaykit.org/static/images/layout-examples-photo-with-inset-text-overlay-photo.png") - photoNode.willDisplayNodeContentWithRenderingContext = { context in + photoNode.willDisplayNodeContentWithRenderingContext = { context, drawParameters in let bounds = context.boundingBoxOfClipPath UIBezierPath(roundedRect: bounds, cornerRadius: 10).addClip() } diff --git a/examples/LayoutSpecExamples/Sample/LayoutExampleNodes.m b/examples/LayoutSpecExamples/Sample/LayoutExampleNodes.m index 5628c53863..00d4b3421f 100644 --- a/examples/LayoutSpecExamples/Sample/LayoutExampleNodes.m +++ b/examples/LayoutSpecExamples/Sample/LayoutExampleNodes.m @@ -125,7 +125,7 @@ _photoNode = [[ASNetworkImageNode alloc] init]; _photoNode.URL = [NSURL URLWithString:@"http://asyncdisplaykit.org/static/images/layout-examples-photo-with-inset-text-overlay-photo.png"]; - _photoNode.willDisplayNodeContentWithRenderingContext = ^(CGContextRef context) { + _photoNode.willDisplayNodeContentWithRenderingContext = ^(CGContextRef context, id drawParameters) { CGRect bounds = CGContextGetClipBoundingBox(context); [[UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:10] addClip]; };