Skip to content

Commit

Permalink
Fabric: Changes in YogaLayoutableShadowNode::applyLayoutConstraints
Browse files Browse the repository at this point in the history
… that prevent descendant nodes overgrow to infinity

Summary:
Instead of changing Yoga styles for a root node, now we pass available height and width to YGNodeCalculateLayout directly.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC, mdvacca

Differential Revision: D26292378

fbshipit-source-id: f99127e1cbddc1d57e4ee116afc141cbff5054ab
  • Loading branch information
shergin authored and facebook-github-bot committed Feb 8, 2021
1 parent 1c7d9c8 commit 81147b6
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@ namespace react {

thread_local LayoutContext threadLocalLayoutContext;

static void applyLayoutConstraints(
YGStyle &yogaStyle,
LayoutConstraints const &layoutConstraints) {
yogaStyle.minDimensions()[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.width);
yogaStyle.minDimensions()[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.height);

yogaStyle.maxDimensions()[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.maximumSize.width);
yogaStyle.maxDimensions()[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.maximumSize.height);

yogaStyle.direction() =
yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection);
}

ShadowNodeTraits YogaLayoutableShadowNode::BaseTraits() {
auto traits = LayoutableShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::YogaLayoutableKind);
Expand Down Expand Up @@ -350,7 +333,25 @@ void YogaLayoutableShadowNode::layoutTree(
*/
yogaConfig_.pointScaleFactor = layoutContext.pointScaleFactor;

applyLayoutConstraints(yogaNode_.getStyle(), layoutConstraints);
auto &yogaStyle = yogaNode_.getStyle();

auto direction =
yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection);

// We enforce maximum size here by applying corresponding styles because
// `YGNodeCalculateLayout` does not support specifying maximum size explicitly
// via parameters.
yogaStyle.minDimensions()[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.width);
yogaStyle.minDimensions()[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.height);

auto availableWidth = std::isinf(layoutConstraints.maximumSize.width)
? YGUndefined
: yogaFloatFromFloat(layoutConstraints.maximumSize.width);
auto availableHeight = std::isinf(layoutConstraints.maximumSize.height)
? YGUndefined
: yogaFloatFromFloat(layoutConstraints.maximumSize.height);

threadLocalLayoutContext = layoutContext;

Expand All @@ -362,7 +363,7 @@ void YogaLayoutableShadowNode::layoutTree(
SystraceSection s("YogaLayoutableShadowNode::YGNodeCalculateLayout");

YGNodeCalculateLayout(
&yogaNode_, YGUndefined, YGUndefined, YGDirectionInherit);
&yogaNode_, availableWidth, availableHeight, direction);
}

if (yogaNode_.getHasNewLayout()) {
Expand Down

0 comments on commit 81147b6

Please sign in to comment.