From 81c1706f0d7cb227efcd3ea206b9cae08a7f8063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ara=C3=BAjo?= Date: Thu, 14 Nov 2019 11:41:51 -0300 Subject: [PATCH] Fix layout view with yoga disabled --- YogaKit/Source/YGLayout.m | 2 +- YogaKit/Tests/YogaKitTests.m | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 692020ca..f924bfc6 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -445,7 +445,7 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin) const YGLayout *yoga = view.yoga; - if (!yoga.isIncludedInLayout) { + if (!yoga.isEnabled || !yoga.isIncludedInLayout) { return; } diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index f2a71bf4..ca9a607a 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -751,4 +751,29 @@ XCTAssertEqual(view.yoga.borderEndWidth, 7); } +- (void)testLayoutWithYogaNotEnabled +{ + UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)]; + container.yoga.isEnabled = YES; + + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + view.yoga.isEnabled = YES; + view.yoga.flexBasis = YGPointValue(0); + view.yoga.flexGrow = 1; + [container addSubview:view]; + + UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 30, 40)]; + [container addSubview:view2]; + + [container.yoga applyLayoutPreservingOrigin:YES]; + + XCTAssertEqual(50, view.frame.size.width); + XCTAssertEqual(75, view.frame.size.height); + + XCTAssertEqual(10, view2.frame.origin.x); + XCTAssertEqual(20, view2.frame.origin.y); + XCTAssertEqual(30, view2.frame.size.width); + XCTAssertEqual(40, view2.frame.size.height); +} + @end