From 8cdea808ec580f72f93c7c732fd78249baf1c593 Mon Sep 17 00:00:00 2001 From: Levi McCallum Date: Tue, 9 Feb 2016 13:11:17 -0800 Subject: [PATCH] Expose calculated frame on layout --- AsyncDisplayKit/Layout/ASLayout.h | 5 +++++ AsyncDisplayKit/Layout/ASLayout.mm | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/AsyncDisplayKit/Layout/ASLayout.h b/AsyncDisplayKit/Layout/ASLayout.h index 75fd51e264..3dffdf227a 100644 --- a/AsyncDisplayKit/Layout/ASLayout.h +++ b/AsyncDisplayKit/Layout/ASLayout.h @@ -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 diff --git a/AsyncDisplayKit/Layout/ASLayout.mm b/AsyncDisplayKit/Layout/ASLayout.mm index c2873b4f00..0e15fcfc16 100644 --- a/AsyncDisplayKit/Layout/ASLayout.mm +++ b/AsyncDisplayKit/Layout/ASLayout.mm @@ -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