From 5037c2f3650dc5b77dfd1b2e0a6530de55302e6b Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Thu, 9 Feb 2017 13:05:38 -0800 Subject: [PATCH] Preserve the origin of the root view. Summary: Currently, we have an issue in YogaKit where it ignores the preexisting bounds a root view. There are multiple fixes for this, but the easiest one for developer experience is to apply the preexisting bounds of the root view to it's frame after layout calculation. Reviewed By: emilsjolander Differential Revision: D4537173 fbshipit-source-id: ccef8b1c1398ea299b4e5710abe597378347a48d --- YogaKit/Source/YGLayout.m | 11 ++++++----- YogaKit/Tests/YogaKitTests.m | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 9c44cc83..80d1a244 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -222,7 +222,7 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) - (void)applyLayout { [self calculateLayoutWithSize:self.view.bounds.size]; - YGApplyLayoutToViewHierarchy(self.view); + YGApplyLayoutToViewHierarchy(self.view, YES); } - (CGSize)intrinsicSize @@ -364,7 +364,7 @@ static CGFloat YGRoundPixelValue(CGFloat value) return round(value * scale) / scale; } -static void YGApplyLayoutToViewHierarchy(UIView *view) +static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin) { NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread."); @@ -385,10 +385,11 @@ static void YGApplyLayoutToViewHierarchy(UIView *view) topLeft.y + YGNodeLayoutGetHeight(node), }; + const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero; view.frame = (CGRect) { .origin = { - .x = YGRoundPixelValue(topLeft.x), - .y = YGRoundPixelValue(topLeft.y), + .x = YGRoundPixelValue(topLeft.x + origin.x), + .y = YGRoundPixelValue(topLeft.y + origin.y), }, .size = { .width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x), @@ -398,7 +399,7 @@ static void YGApplyLayoutToViewHierarchy(UIView *view) if (!yoga.isLeaf) { for (NSUInteger i=0; i