From 820026f69b2021b1392e44386a88570d0122c292 Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Wed, 12 Jul 2017 09:27:51 -0700 Subject: [PATCH] Fixing the issue with node dimensions rounding in Yoga Reviewed By: emilsjolander Differential Revision: D5406211 fbshipit-source-id: df1d54ed0805dfc3abbd8f0ceae30f6d8c26d61a --- ReactCommon/yoga/yoga/Yoga.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 68009fd83..398d37749 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -3474,8 +3474,12 @@ static void YGRoundToPixelGrid(const YGNodeRef node, node->layout.position[YGEdgeTop] = YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding); - const bool hasFractionalWidth = !YGFloatsEqual(fmodf(nodeWidth, 1 / pointScaleFactor), 0); - const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight, 1 / pointScaleFactor), 0); + // We multiply dimension by scale factor and if the result is close to the whole number, we don't have any fraction + // To verify if the result is close to whole number we want to check both floor and ceil numbers + const bool hasFractionalWidth = !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) && + !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0); + const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && + !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); node->layout.dimensions[YGDimensionWidth] = YGRoundValueToPixelGrid(