From c7c7831ec64da0a5e31d90c3fa1730e4bee87265 Mon Sep 17 00:00:00 2001 From: jlmip <44199721+jlmip@users.noreply.github.com> Date: Tue, 3 Oct 2023 06:24:48 -0700 Subject: [PATCH] Fixed issue with first line element gap handling. Summary: If the first element of a line is not contributing (e.g. position absolute), an additional gap will be added to the line, because the first gap element of the line is never identified (wrong start index). Fix: raise the index of the first line element until we find an element that is contributing to the line. X-link: https://github.com/facebook/yoga/pull/1408 Reviewed By: yungsters Differential Revision: D49722065 Pulled By: NickGerleman fbshipit-source-id: 1068cb0b11ae4b04ec8d063e70540cce06181d5a --- .../ReactCommon/yoga/yoga/algorithm/FlexLine.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp index aab71aa20d6..d2034bf2f92 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp @@ -28,6 +28,7 @@ FlexLine calculateFlexLine( float totalFlexGrowFactors = 0.0f; float totalFlexShrinkScaledFactors = 0.0f; size_t endOfLineIndex = startOfLineIndex; + size_t firstElementInLineIndex = startOfLineIndex; float sizeConsumedIncludingMinConstraint = 0; const FlexDirection mainAxis = resolveDirection( @@ -40,10 +41,15 @@ FlexLine calculateFlexLine( auto child = node->getChild(endOfLineIndex); if (child->getStyle().display() == Display::None || child->getStyle().positionType() == PositionType::Absolute) { + if (firstElementInLineIndex == endOfLineIndex) { + // We haven't found the first contributing element in the line yet. + firstElementInLineIndex++; + } continue; } - const bool isFirstElementInLine = (endOfLineIndex - startOfLineIndex) == 0; + const bool isFirstElementInLine = + (endOfLineIndex - firstElementInLineIndex) == 0; child->setLineIndex(lineCount); const float childMarginMainAxis =