diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index 94d47847c40e82dd92ef77552455d7c21183e57f..188417a52d2d27cdcb8499ac9249411411f27187 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -43,7 +43,6 @@ const Dimension TITLE_TEXT_FONT_SIZE = 16.0_fp; const Dimension CONTENT_MARGIN = 4.0_vp; const Color CONTAINER_BACKGROUND_COLOR = Color(0xd6e4e5ed); const Color CONTAINER_BORDER_COLOR = Color(0x33000000); -const Color TITLE_BACKGROUND_COLOR = Color::TRANSPARENT; const Color TITLE_TEXT_COLOR = Color(0xe5000000); const Color CONTENT_BACKGROUND_COLOR = Color(0xffffffff); const Color TITLE_BUTTON_BACKGROUND_COLOR = Color(0x33000000); @@ -150,15 +149,9 @@ RefPtr ContainerModalComponent::BuildTitle() titleChildren.emplace_back(SetPadding(closeBtn, ZERO_PADDING, TITLE_PADDING_END)); // build title box - Border titleBorder; - titleBorder.SetTopLeftRadius(Radius(CONTAINER_OUTER_RADIUS - CONTAINER_BORDER_WIDTH)); - titleBorder.SetTopRightRadius(Radius(CONTAINER_OUTER_RADIUS - CONTAINER_BORDER_WIDTH)); auto titleDecoration = AceType::MakeRefPtr(); - titleDecoration->SetBackgroundColor(TITLE_BACKGROUND_COLOR); - titleDecoration->SetBorder(titleBorder); auto titleBox = AceType::MakeRefPtr(); titleBox->SetHeight(CONTAINER_TITLE_HEIGHT); - titleBox->SetBackDecoration(titleDecoration); auto row = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, titleChildren); // handle mouse move @@ -183,9 +176,7 @@ RefPtr ContainerModalComponent::BuildTitle() RefPtr ContainerModalComponent::BuildContent() { auto contentBox = AceType::MakeRefPtr(); - auto clip = AceType::MakeRefPtr(GetChild()); - contentBox->SetChild(clip); - + contentBox->SetChild(GetChild()); Border contentBorder; contentBorder.SetBorderRadius(Radius(CONTAINER_INNER_RADIUS)); auto contentDecoration = AceType::MakeRefPtr(); @@ -196,12 +187,11 @@ RefPtr ContainerModalComponent::BuildContent() Edge margin; margin.SetLeft(CONTENT_MARGIN); margin.SetRight(CONTENT_MARGIN); - margin.SetBottom(CONTENT_MARGIN); contentBox->SetMargin(margin); - auto flexItem = AceType::MakeRefPtr(1, 1, 0); - flexItem->SetChild(contentBox); - return flexItem; + // adaptive height + contentBox->SetFlexWeight(1.0); + return contentBox; } RefPtr ContainerModalComponent::BuildControlButton(InternalResource::ResourceId icon, @@ -257,6 +247,11 @@ void ContainerModalComponent::BuildInnerChild() containerBox->SetBackDecoration(containerDecoration); containerBox->SetFlex(BoxFlex::FLEX_X); containerBox->SetAlignment(Alignment::CENTER); + + // Use the bottom padding of the containerBox to replace the bottom margin of the contentBox. + Edge padding; + padding.SetBottom(CONTENT_MARGIN); + containerBox->SetPadding(padding); containerBox->SetChild(column); SetChild(containerBox); } diff --git a/frameworks/core/components/container_modal/container_modal_component.h b/frameworks/core/components/container_modal/container_modal_component.h index 56be995678d50a28034ddcb6c791b91130388698..7e9750c592b93883a6c745ff48c2cff90eac6188 100644 --- a/frameworks/core/components/container_modal/container_modal_component.h +++ b/frameworks/core/components/container_modal/container_modal_component.h @@ -50,7 +50,7 @@ private: RefPtr BuildTitle(); RefPtr BuildContent(); RefPtr BuildControlButton(InternalResource::ResourceId icon, std::function&& clickCallback); - RefPtr SetPadding(const RefPtr& component, const Dimension& leftPadding, + static RefPtr SetPadding(const RefPtr& component, const Dimension& leftPadding, const Dimension& rightPadding); WeakPtr context_; diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index 95859b2f38837dcfa96cea0c31b434f2b6173d80..0f851b53ac7fdb87a96b9cc7affae49ccba0ec0d 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -23,49 +23,38 @@ namespace OHOS::Ace { namespace { -constexpr uint32_t COLUMN_CHILD_MIN = 2; +constexpr uint32_t COLUMN_CHILD_NUM = 2; } // namespace RefPtr ContainerModalElement::GetStackElement() const { - auto containerbox = AceType::DynamicCast(GetFirstChild()); - if (!containerbox) { + auto containerBox = AceType::DynamicCast(GetFirstChild()); + if (!containerBox) { LOGE("Get stack element failed. Container box element is null!"); - return RefPtr(); + return {}; } - auto column = AceType::DynamicCast(containerbox->GetFirstChild()); - if (!column || column->GetChildren().size() < COLUMN_CHILD_MIN) { - // column should has more than 2 child + auto column = AceType::DynamicCast(containerBox->GetFirstChild()); + if (!column || column->GetChildren().size() != COLUMN_CHILD_NUM) { + // column should have 2 children, title and content. LOGE("Get stack element failed. Column is null or child size error!"); - return RefPtr(); + return {}; } // Get second child auto secondItr = std::next(column->GetChildren().begin()); - auto contentFlexItem = AceType::DynamicCast(*secondItr); - if (!contentFlexItem) { - LOGE("Get stack element failed. content flex item element is null!"); - return RefPtr(); - } + auto contentBox = AceType::DynamicCast(*secondItr); - auto contentBox = AceType::DynamicCast(contentFlexItem->GetFirstChild()); if (!contentBox) { LOGE("Get stack element failed. content box element is null!"); - return RefPtr(); - } - - auto clip = contentBox->GetFirstChild(); - if (!clip) { - LOGE("Get stack element failed. clip is null!"); - return RefPtr(); + return {}; } - auto stack = clip->GetFirstChild(); + auto stack = contentBox->GetFirstChild(); if (!stack || !AceType::InstanceOf(stack)) { LOGE("Get stack element failed. stack is null or type error!"); - return RefPtr(); + return {}; } return AceType::DynamicCast(stack); @@ -76,16 +65,16 @@ RefPtr ContainerModalElement::GetOverlayElement() const auto stack = GetStackElement(); if (!stack) { LOGE("Get overlay element failed, stack element is null"); - return RefPtr(); + return {}; } - for (auto child : stack->GetChildren()) { + for (const auto& child : stack->GetChildren()) { if (child && AceType::InstanceOf(child)) { return AceType::DynamicCast(child); } } LOGE("Get overlay element failed, all children of stack element do not meet the requirements"); - return RefPtr(); + return {}; } RefPtr ContainerModalElement::GetStageElement() const @@ -93,15 +82,15 @@ RefPtr ContainerModalElement::GetStageElement() const auto stack = GetStackElement(); if (!stack) { LOGE("Get stage element failed, stack element is null"); - return RefPtr(); + return {}; } - for (auto child : stack->GetChildren()) { + for (const auto& child : stack->GetChildren()) { if (child && AceType::InstanceOf(child)) { return AceType::DynamicCast(child); } } LOGE("Get stage element failed, all children of stack element do not meet the requirements"); - return RefPtr(); + return {}; } } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 6edbc71b516e4a1c65564de6af1a6d86c0bb2445..7d64dc1faa6c86ffe45da9480b638f59ca64a474 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -1878,11 +1878,14 @@ void PipelineContext::SetRootBgColor(const Color& color) LOGE("GetTheme failed!"); return; } - appTheme->SetBackgroundColor(color); + if (windowModal_ == WindowModal::CONTAINER_MODAL) { + rootBgColor_ = Color::TRANSPARENT; + } + appTheme->SetBackgroundColor(rootBgColor_); if (rootElement_) { auto renderRoot = DynamicCast(rootElement_->GetRenderNode()); if (renderRoot) { - renderRoot->SetBgColor(color); + renderRoot->SetBgColor(rootBgColor_); } } }