From 32582fca580d6adeb6af5d3254a3baa09394cf89 Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Tue, 1 Sep 2015 13:19:26 -0700 Subject: [PATCH] Fixes shouldRasterizeSubnodes Currently, subnodes of nodes marked with shouldRasterizeSubnodes do not get layout calls. This adds the call to layout and changes the __layout method to reference self.bounds instead of _layer.bounds. Also adds support for corner radius when rasterizing subnodes. --- AsyncDisplayKit/ASDisplayNode.mm | 4 ++-- .../Private/ASDisplayNode+AsyncDisplay.mm | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index ab1a644091..7258fc3461 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -612,10 +612,10 @@ void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block) { ASDisplayNodeAssertMainThread(); ASDN::MutexLocker l(_propertyLock); - if (CGRectEqualToRect(_layer.bounds, CGRectZero)) { + if (CGRectEqualToRect(self.bounds, CGRectZero)) { return; // Performing layout on a zero-bounds view often results in frame calculations with negative sizes after applying margins, which will cause measureWithSizeRange: on subnodes to assert. } - _placeholderLayer.frame = _layer.bounds; + _placeholderLayer.frame = self.bounds; [self layout]; [self layoutDidFinish]; } diff --git a/AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm b/AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm index 99167a93d4..e6551d7a26 100644 --- a/AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm +++ b/AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm @@ -83,6 +83,13 @@ static void __ASDisplayLayerDecrementConcurrentDisplayCount(BOOL displayIsAsync, if (self.isHidden || self.alpha <= 0.0) { return; } + + BOOL rasterizingFromAscendent = [self __rasterizedContainerNode] != nil; + + // if super node is rasterizing descendents, subnodes will not have had layout calls becase they don't have layers + if (rasterizingFromAscendent) { + [self __layout]; + } // Capture these outside the display block so they are retained. UIColor *backgroundColor = self.backgroundColor; @@ -121,6 +128,11 @@ static void __ASDisplayLayerDecrementConcurrentDisplayCount(BOOL displayIsAsync, CGContextTranslateCTM(context, frame.origin.x, frame.origin.y); + //support cornerRadius + if (rasterizingFromAscendent && self.cornerRadius && self.clipsToBounds) { + [[UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:self.cornerRadius] addClip]; + } + // Fill background if any. CGColorRef backgroundCGColor = backgroundColor.CGColor; if (backgroundColor && CGColorGetAlpha(backgroundCGColor) > 0.0) {