Skip to content

Commit 5348f9f

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Fix possible invalid measurements when width or height is zero pixels (facebook#52073)
Summary: Pull Request resolved: facebook#52073 X-link: facebook/yoga#1820 Fixes facebook/yoga#1819 Yoga has a fast path when measuring a node, if it thinks it knows its dimensions ahead of time. This path has some eroneous logic, to set both axis to owner size, if *either* will evaluate to zero, while having an `YGMeasureModeAtMost`/`FitContent` constraint. This means that if a node is given a zero width, and Yoga later measures with with `FitContent`, its height will become the maximum allowable height, even if it shouldn't be that large. We can fix this, by only allowing if both axis are this fixed case, instead of just one. This bug has existed for about a decade (going back to at least D3312496). Changelog: [General][Fixed] - Fix possible invalid measurements with width or height is zero pixels Reviewed By: yungsters Differential Revision: D76793705 fbshipit-source-id: ea4c00e688912a58c08801e4a14ddf1b293a5d86
1 parent e08e27a commit 5348f9f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ static void measureNodeWithoutChildren(
415415
Dimension::Height);
416416
}
417417

418+
inline bool isFixedSize(float dim, SizingMode sizingMode) {
419+
return yoga::isDefined(dim) &&
420+
(sizingMode == SizingMode::StretchFit ||
421+
(sizingMode == SizingMode::FitContent && dim <= 0.0));
422+
}
423+
418424
static bool measureNodeWithFixedSize(
419425
yoga::Node* const node,
420426
const Direction direction,
@@ -424,12 +430,8 @@ static bool measureNodeWithFixedSize(
424430
const SizingMode heightSizingMode,
425431
const float ownerWidth,
426432
const float ownerHeight) {
427-
if ((yoga::isDefined(availableWidth) &&
428-
widthSizingMode == SizingMode::FitContent && availableWidth <= 0.0f) ||
429-
(yoga::isDefined(availableHeight) &&
430-
heightSizingMode == SizingMode::FitContent && availableHeight <= 0.0f) ||
431-
(widthSizingMode == SizingMode::StretchFit &&
432-
heightSizingMode == SizingMode::StretchFit)) {
433+
if (isFixedSize(availableWidth, widthSizingMode) &&
434+
isFixedSize(availableHeight, heightSizingMode)) {
433435
node->setLayoutMeasuredDimension(
434436
boundAxis(
435437
node,

0 commit comments

Comments
 (0)