From 6366ee45ab6adfaf610a8ec2994d1bf1e90de6d9 Mon Sep 17 00:00:00 2001 From: Pavel Mazurin Date: Mon, 31 Jul 2017 15:43:15 +0200 Subject: [PATCH] Add unit test. Fix the layout for non-UIView subclasses --- YogaKit/Source/YGLayout.m | 3 ++- YogaKit/Tests/YogaKitTests.m | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 996504f3..9cc4a6a7 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -306,7 +306,8 @@ static YGSize YGMeasureView( UIView *view = (__bridge UIView*) YGNodeGetContext(node); CGSize sizeThatFits = CGSizeZero; - if ([view.subviews count] > 0) { + // Fix for https://github.com/facebook/yoga/issues/606 + if (![view isMemberOfClass:[UIView class]] || [view.subviews count] > 0) { sizeThatFits = [view sizeThatFits:(CGSize) { .width = constrainedWidth, .height = constrainedHeight, diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index ed4169c5..b6c3b8a3 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -129,6 +129,16 @@ XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width); } +- (void)testSizeThatFitsEmptyView +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)]; + view.yoga.isEnabled = YES; + + const CGSize viewSize = view.yoga.intrinsicSize; + XCTAssertEqual(viewSize.height, 0); + XCTAssertEqual(viewSize.width, 0); +} + - (void)testPreservingOrigin { UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)];