From de24ea64a22556f4edf8dd0ae4cfb48761c77655 Mon Sep 17 00:00:00 2001 From: yangfan Date: Tue, 8 Mar 2022 17:38:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRow/Column=E6=B7=BB=E5=8A=A0d?= =?UTF-8?q?isplayPriority=E5=90=8E=E6=92=91=E5=A4=A7=E7=9A=84bug,=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dflex=E6=B7=BB=E5=8A=A0space=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E8=A1=8C=E4=BB=8D=E5=AD=98=E5=9C=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan Change-Id: Ia9842bd6292f05b5b557788994fb95ac6c377cb9 --- .../core/components/flex/render_flex.cpp | 19 ++++++++++++++----- frameworks/core/components/flex/render_flex.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frameworks/core/components/flex/render_flex.cpp b/frameworks/core/components/flex/render_flex.cpp index c8e5b4c2df2..280f6c53b8f 100644 --- a/frameworks/core/components/flex/render_flex.cpp +++ b/frameworks/core/components/flex/render_flex.cpp @@ -18,6 +18,7 @@ #include #include "base/log/dump_log.h" +#include "core/components/common/layout/constants.h" #include "core/components/flex/flex_component.h" #include "core/components/scroll/render_single_child_scroll.h" #include "core/pipeline/base/position_layout_utils.h" @@ -76,6 +77,7 @@ void RenderFlex::Update(const RefPtr& component) space_ = context->NormalizeToPx(flex->GetSpace()); inspectorSpace_ = flex->GetSpace(); useOldLayoutVersion_ = context->GetMinPlatformVersion() <= PLATFORM_VERSION_FIVE; + isDeclarative_ = context->GetIsDeclarative(); if (GreatNotEqual(space_, 0.0)) { mainAxisAlign_ = FlexAlign::SPACE_CUSOMIZATION; } @@ -400,11 +402,13 @@ void RenderFlex::PerformLayoutInIndexMode() auto child = node.node; child->Layout(innerLayout); allocatedSize_ += GetMainSize(child); + allocatedSize_ += space_; } - if (allocatedSize_ > maxMainSize) { + if ((allocatedSize_ - space_) > maxMainSize) { for (const auto& node : nodeList) { auto child = node.node; allocatedSize_ -= GetMainSize(child); + allocatedSize_ -= space_; } break; } @@ -431,7 +435,13 @@ void RenderFlex::PerformLayoutInIndexMode() } LayoutHiddenNodes(); LayoutAbsoluteChildren(); - Size layoutSize = GetConstrainedSize(maxMainSize); + allocatedSize_ -= space_; + Size layoutSize; + if (!isDeclarative_ || mainAxisSize_ == MainAxisSize::MAX) { + layoutSize = GetConstrainedSize(maxMainSize); + } else { + layoutSize = GetConstrainedSize(allocatedSize_); + } SetLayoutSize(layoutSize); mainSize_ = GetMainAxisValue(layoutSize, direction_); crossSize_ = (direction_ == FlexDirection::ROW || direction_ == FlexDirection::ROW_REVERSE) ? layoutSize.Height() @@ -551,9 +561,7 @@ void RenderFlex::PerformLayoutInItemMode() void RenderFlex::ResizeItems(const FlexItemProperties& flexItemProps, BaselineProperties& baselineProps) { double availableMainSize = GetAvailableMainSize(); - auto context = GetContext().Upgrade(); - bool isDeclarative = context ? context->GetIsDeclarative() : false; - if (flexItemProps.totalGrow > 0 && availableMainSize > allocatedSize_ && !isDeclarative) { + if (flexItemProps.totalGrow > 0 && availableMainSize > allocatedSize_ && !isDeclarative_) { mainAxisSize_ = MainAxisSize::MAX; } // remainSpace should be (availableMainSize - allocatedSize_), and do not remain space when MainAxisSize::MIN. @@ -613,6 +621,7 @@ void RenderFlex::DetermineSelfSize(MainAxisSize mainAxisSize, bool useViewPort) // If max size of layoutParam is infinity, use children's allocated size as max size. maxMainSize = allocatedSize_; } + allocatedSize_ -= space_; // useViewPort means that it is the root flex, should be as large as viewPort. Size layoutSize = (mainAxisSize == MainAxisSize::MIN) ? GetConstrainedSize(allocatedSize_) : useViewPort ? GetConstrainedSize(mainViewPort) diff --git a/frameworks/core/components/flex/render_flex.h b/frameworks/core/components/flex/render_flex.h index d993e3c3134..1812aeb7615 100644 --- a/frameworks/core/components/flex/render_flex.h +++ b/frameworks/core/components/flex/render_flex.h @@ -240,6 +240,7 @@ private: double totalFlexWeight_ = 0.0; int32_t maxDisplayIndex_ = 0; bool useOldLayoutVersion_ = false; + bool isDeclarative_ = false; AlignDeclarationPtr alignPtr_ = nullptr; }; -- Gitee