Expose calculated frame on layout

This commit is contained in:
Levi McCallum
2016-02-09 13:11:17 -08:00
parent a93013702d
commit 8cdea808ec
2 changed files with 33 additions and 0 deletions

View File

@@ -122,6 +122,11 @@ extern BOOL CGPointIsNull(CGPoint point);
*/
- (ASLayout *)flattenedLayoutUsingPredicateBlock:(BOOL (^)(ASLayout *evaluatedLayout))predicateBlock;
/**
* @abstract Returns a valid frame for the current layout computed with the size and position.
*/
- (CGRect)frame;
@end
NS_ASSUME_NONNULL_END

View File

@@ -119,4 +119,32 @@ extern BOOL CGPointIsNull(CGPoint point)
return [ASLayout flattenedLayoutWithLayoutableObject:_layoutableObject size:_size sublayouts:flattenedSublayouts];
}
- (CGRect)frame
{
CGRect subnodeFrame = CGRectZero;
CGPoint adjustedOrigin = _position;
if (isfinite(adjustedOrigin.x) == NO) {
ASDisplayNodeAssert(0, @"Layout has an invalid position");
adjustedOrigin.x = 0;
}
if (isfinite(adjustedOrigin.y) == NO) {
ASDisplayNodeAssert(0, @"Layout has an invalid position");
adjustedOrigin.y = 0;
}
subnodeFrame.origin = adjustedOrigin;
CGSize adjustedSize = _size;
if (isfinite(adjustedSize.width) == NO) {
ASDisplayNodeAssert(0, @"Layout has an invalid size");
adjustedSize.width = 0;
}
if (isfinite(adjustedSize.height) == NO) {
ASDisplayNodeAssert(0, @"Layout has an invalid position");
adjustedSize.height = 0;
}
subnodeFrame.size = adjustedSize;
return subnodeFrame;
}
@end