mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-01 12:23:20 +08:00
Merge pull request #945 from rcancro/aslayoutPixelBounds
Enforce pixels bounds for ASLayout size/position, while also protecting against underspecified layouts setting NaN or Inf on CALayer.
This commit is contained in:
@@ -1816,8 +1816,28 @@ void recursivelyEnsureDisplayForLayer(CALayer *layer)
|
||||
CGRect subnodeFrame = CGRectZero;
|
||||
for (ASLayout *subnodeLayout in _layout.sublayouts) {
|
||||
ASDisplayNodeAssert([_subnodes containsObject:subnodeLayout.layoutableObject], @"Cached sublayouts must only contain subnodes' layout.");
|
||||
subnodeFrame.origin = subnodeLayout.position;
|
||||
subnodeFrame.size = subnodeLayout.size;
|
||||
CGPoint adjustedOrigin = subnodeLayout.position;
|
||||
if (isfinite(adjustedOrigin.x) == NO) {
|
||||
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid position");
|
||||
adjustedOrigin.x = 0;
|
||||
}
|
||||
if (isfinite(adjustedOrigin.y) == NO) {
|
||||
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid position");
|
||||
adjustedOrigin.y = 0;
|
||||
}
|
||||
subnodeFrame.origin = adjustedOrigin;
|
||||
|
||||
CGSize adjustedSize = subnodeLayout.size;
|
||||
if (isfinite(adjustedSize.width) == NO) {
|
||||
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid size");
|
||||
adjustedSize.width = 0;
|
||||
}
|
||||
if (isfinite(adjustedSize.height) == NO) {
|
||||
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid position");
|
||||
adjustedSize.height = 0;
|
||||
}
|
||||
subnodeFrame.size = adjustedSize;
|
||||
|
||||
subnode = ((ASDisplayNode *)subnodeLayout.layoutableObject);
|
||||
[subnode setFrame:subnodeFrame];
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#import "ASLayout.h"
|
||||
#import "ASAssert.h"
|
||||
#import "ASLayoutSpecUtilities.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
#import <stack>
|
||||
|
||||
CGPoint const CGPointNull = {NAN, NAN};
|
||||
@@ -37,8 +38,12 @@ extern BOOL CGPointIsNull(CGPoint point)
|
||||
ASLayout *l = [super new];
|
||||
if (l) {
|
||||
l->_layoutableObject = layoutableObject;
|
||||
l->_size = size;
|
||||
l->_position = position;
|
||||
l->_size = CGSizeMake(ASCeilPixelValue(size.width), ASCeilPixelValue(size.height));
|
||||
if (CGPointIsNull(position) == NO) {
|
||||
l->_position = CGPointMake(ASCeilPixelValue(position.x), ASCeilPixelValue(position.y));
|
||||
} else {
|
||||
l->_position = position;
|
||||
}
|
||||
l->_sublayouts = [sublayouts copy];
|
||||
}
|
||||
return l;
|
||||
|
||||
Reference in New Issue
Block a user