Skip to content

Commit

Permalink
Fixing the issue with node dimensions rounding in Yoga
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D5406211

fbshipit-source-id: df1d54ed0805dfc3abbd8f0ceae30f6d8c26d61a
  • Loading branch information
Georgiy Kassabli authored and facebook-github-bot committed Jul 12, 2017
1 parent 9f87728 commit 820026f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ReactCommon/yoga/yoga/Yoga.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 820026f

Please sign in to comment.