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 =