From 2fb01daf70b9809e5caf742b44dd6100037fde65 Mon Sep 17 00:00:00 2001 From: Jernej Strasner Date: Mon, 22 May 2017 11:41:17 -0700 Subject: [PATCH] Expose calculateLayoutWithSize in YogaKit Summary: calculateLayoutWithSize: can be useful when calculating table/collection view sizes before the views are fully laid out by UIKit. Closes https://github.com/facebook/yoga/pull/558 Differential Revision: D5104863 Pulled By: emilsjolander fbshipit-source-id: e0e0c6d502f6745be8d84de8c1b6e24cc25a0352 --- YogaKit/Source/YGLayout.h | 6 ++++++ YogaKit/Source/YGLayout.m | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/YogaKit/Source/YGLayout.h b/YogaKit/Source/YGLayout.h index 5d6ace7d..416de203 100644 --- a/YogaKit/Source/YGLayout.h +++ b/YogaKit/Source/YGLayout.h @@ -120,6 +120,12 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) { */ @property (nonatomic, readonly, assign) CGSize intrinsicSize; +/** + Returns the size of the view based on provided constraints. Pass NaN for an unconstrained dimension. + */ +- (CGSize)calculateLayoutWithSize:(CGSize)size + NS_SWIFT_NAME(calculateLayout(with:)); + /** Returns the number of children that are using Flexbox. */ diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index b48d5e49..df4a4821 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -271,8 +271,6 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) return [self calculateLayoutWithSize:constrainedSize]; } -#pragma mark - Private - - (CGSize)calculateLayoutWithSize:(CGSize)size { NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main."); @@ -293,6 +291,8 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) }; } +#pragma mark - Private + static YGSize YGMeasureView( YGNodeRef node, float width,