From f13f90d1ff152a9cfa6987f51d6064cd7f3d4203 Mon Sep 17 00:00:00 2001 From: Leland Richardson Date: Thu, 21 Dec 2017 08:52:46 -1000 Subject: [PATCH] Avoid using UIView::frame in favor of bounds/center --- YogaKit/Source/YGLayout.m | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 7e4faead..d2fb0aa7 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -451,15 +451,26 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin) topLeft.y + YGNodeLayoutGetHeight(node), }; - const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero; - view.frame = (CGRect) { - .origin = { - .x = YGRoundPixelValue(topLeft.x + origin.x), - .y = YGRoundPixelValue(topLeft.y + origin.y), - }, + const CGPoint origin = preserveOrigin ? (CGPoint){ + .x = view.center.x - (view.bounds.size.width / 2), + .y = view.center.y - (view.bounds.size.height / 2), + } : CGPointZero; + + CGFloat x = topLeft.x + origin.x; + CGFloat y = topLeft.y + origin.y; + CGFloat width = bottomRight.x - topLeft.x; + CGFloat height = bottomRight.y - topLeft.y; + + view.center = (CGPoint) { + .x = YGRoundPixelValue(x + (width / 2)), + .y = YGRoundPixelValue(y + (height / 2)), + }; + + view.bounds = (CGRect) { + .origin = CGPointZero, .size = { - .width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x), - .height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y), + .width = YGRoundPixelValue(width), + .height = YGRoundPixelValue(height), }, }; -- 2.50.1.windows.1