Skip to content

Commit 32582fc

Browse files
committed
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.
1 parent 9c51bde commit 32582fc

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,10 @@ - (void)__layout
612612
{
613613
ASDisplayNodeAssertMainThread();
614614
ASDN::MutexLocker l(_propertyLock);
615-
if (CGRectEqualToRect(_layer.bounds, CGRectZero)) {
615+
if (CGRectEqualToRect(self.bounds, CGRectZero)) {
616616
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.
617617
}
618-
_placeholderLayer.frame = _layer.bounds;
618+
_placeholderLayer.frame = self.bounds;
619619
[self layout];
620620
[self layoutDidFinish];
621621
}

AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ - (void)_recursivelyRasterizeSelfAndSublayersWithIsCancelledBlock:(asdisplaynode
8383
if (self.isHidden || self.alpha <= 0.0) {
8484
return;
8585
}
86+
87+
BOOL rasterizingFromAscendent = [self __rasterizedContainerNode] != nil;
88+
89+
// if super node is rasterizing descendents, subnodes will not have had layout calls becase they don't have layers
90+
if (rasterizingFromAscendent) {
91+
[self __layout];
92+
}
8693

8794
// Capture these outside the display block so they are retained.
8895
UIColor *backgroundColor = self.backgroundColor;
@@ -121,6 +128,11 @@ - (void)_recursivelyRasterizeSelfAndSublayersWithIsCancelledBlock:(asdisplaynode
121128

122129
CGContextTranslateCTM(context, frame.origin.x, frame.origin.y);
123130

131+
//support cornerRadius
132+
if (rasterizingFromAscendent && self.cornerRadius && self.clipsToBounds) {
133+
[[UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:self.cornerRadius] addClip];
134+
}
135+
124136
// Fill background if any.
125137
CGColorRef backgroundCGColor = backgroundColor.CGColor;
126138
if (backgroundColor && CGColorGetAlpha(backgroundCGColor) > 0.0) {

0 commit comments

Comments
 (0)