diff --git a/frameworks/core/components/box/render_box_base.h b/frameworks/core/components/box/render_box_base.h index c723799f223c17c0f1562853ea175f58b40d6b42..53029dad6433492aa8409e7fe5d9bb281e43a584 100644 --- a/frameworks/core/components/box/render_box_base.h +++ b/frameworks/core/components/box/render_box_base.h @@ -114,6 +114,12 @@ public: } } + void SetPadding(const Edge& padding) + { + paddingOrigin_ = padding; + MarkNeedLayout(); + } + double GetWidth() const // add for animation { return width_.Value(); diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index c26aa8e5960963f3f1c766ea35bb2194397d51e6..646081ac74b6141698ee6425d53e72716cd74e37 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,6 +18,7 @@ #include "core/components/box/box_component.h" #include "core/components/button/button_component.h" #include "core/components/clip/clip_component.h" +#include "core/components/container_modal/container_modal_constants.h" #include "core/components/container_modal/container_modal_element.h" #include "core/components/container_modal/render_container_modal.h" #include "core/components/flex/flex_component.h" @@ -28,27 +29,6 @@ #include "core/components/tween/tween_component.h" namespace OHOS::Ace { -namespace { - -const Dimension CONTAINER_INNER_RADIUS = 14.0_vp; -const Dimension CONTAINER_OUTER_RADIUS = 16.0_vp; -const Dimension CONTAINER_BORDER_WIDTH = 1.0_vp; -const Dimension CONTAINER_TITLE_HEIGHT = 48.0_vp; -const Dimension TITLE_PADDING_START = 24.0_vp; -const Dimension TITLE_PADDING_END = 24.0_vp; -const Dimension ZERO_PADDING = 0.0_vp; -const Dimension TITLE_ELEMENT_MARGIN_HORIZONTAL = 16.0_vp; -const Dimension TITLE_ICON_SIZE = 20.0_vp; -const Dimension TITLE_BUTTON_SIZE = 24.0_vp; -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_TEXT_COLOR = Color(0xe5000000); -const Color CONTENT_BACKGROUND_COLOR = Color(0xffffffff); -const Color TITLE_BUTTON_BACKGROUND_COLOR = Color(0x33000000); - -} // namespace RefPtr ContainerModalComponent::Create( const WeakPtr& context, const RefPtr& child) @@ -133,11 +113,6 @@ RefPtr ContainerModalComponent::BuildContent() contentDecoration->SetBorder(contentBorder); contentBox->SetBackDecoration(contentDecoration); - Edge margin; - margin.SetLeft(CONTENT_MARGIN); - margin.SetRight(CONTENT_MARGIN); - contentBox->SetMargin(margin); - // adaptive height contentBox->SetFlexWeight(1.0); return contentBox; @@ -199,9 +174,7 @@ void ContainerModalComponent::BuildInnerChild() 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); + Edge padding = Edge(CONTENT_PADDING, Dimension(0.0), CONTENT_PADDING, CONTENT_PADDING); containerBox->SetPadding(padding); containerBox->SetChild(stackComponent); 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 0a47618cd5269da9fac9ee1b168035ff2bf5c482..81a1920ef5b8bdd2e0232d6def19709d31b5a899 100644 --- a/frameworks/core/components/container_modal/container_modal_component.h +++ b/frameworks/core/components/container_modal/container_modal_component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/core/components/container_modal/container_modal_constants.h b/frameworks/core/components/container_modal/container_modal_constants.h new file mode 100644 index 0000000000000000000000000000000000000000..18f12e698eae5b2f475d3cd0c2b970b7f1899567 --- /dev/null +++ b/frameworks/core/components/container_modal/container_modal_constants.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONSTANTS_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONSTANTS_H + +namespace OHOS::Ace { + +const Dimension CONTAINER_INNER_RADIUS = 14.0_vp; +const Dimension CONTAINER_OUTER_RADIUS = 16.0_vp; +const Dimension CONTAINER_BORDER_WIDTH = 1.0_vp; +const Dimension CONTAINER_TITLE_HEIGHT = 48.0_vp; +const Dimension TITLE_PADDING_START = 24.0_vp; +const Dimension TITLE_PADDING_END = 24.0_vp; +const Dimension ZERO_PADDING = 0.0_vp; +const Dimension TITLE_ELEMENT_MARGIN_HORIZONTAL = 16.0_vp; +const Dimension TITLE_ICON_SIZE = 20.0_vp; +const Dimension TITLE_BUTTON_SIZE = 24.0_vp; +const Dimension TITLE_TEXT_FONT_SIZE = 16.0_fp; +const Dimension CONTENT_PADDING = 4.0_vp; +const Color CONTAINER_BACKGROUND_COLOR = Color(0xd6e4e5ed); +const Color CONTAINER_BORDER_COLOR = Color(0x33000000); +const Color TITLE_TEXT_COLOR = Color(0xe5000000); +const Color CONTENT_BACKGROUND_COLOR = Color(0xffffffff); +const Color TITLE_BUTTON_BACKGROUND_COLOR = Color(0x33000000); + +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONSTANTS_H \ No newline at end of file diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index a7954bd2be70f7c2f91c9ccd58c948a63eecbbe1..be69188b62c45a5072e5b6b0e14af57b42be3b7b 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,7 @@ #include "core/components/container_modal/container_modal_element.h" #include "core/components/box/box_element.h" +#include "core/components/container_modal/container_modal_constants.h" #include "core/components/container_modal/render_container_modal.h" #include "core/components/flex/flex_element.h" #include "core/components/flex/flex_item_element.h" @@ -107,6 +108,22 @@ void ContainerModalElement::ShowTitle(bool isShow) LOGE("ContainerModalElement showTitle failed, container box element is null!"); return; } + auto containerRenderBox = AceType::DynamicCast(containerBox->GetRenderNode()); + if (containerRenderBox) { + auto containerDecoration = AceType::MakeRefPtr(); + Edge padding = Edge(); + if (isShow) { + Border outerBorder; + outerBorder.SetBorderRadius(Radius(CONTAINER_OUTER_RADIUS)); + outerBorder.SetColor(CONTAINER_BORDER_COLOR); + outerBorder.SetWidth(CONTAINER_BORDER_WIDTH); + containerDecoration->SetBackgroundColor(CONTAINER_BACKGROUND_COLOR); + containerDecoration->SetBorder(outerBorder); + padding = Edge(CONTENT_PADDING, Dimension(0.0), CONTENT_PADDING, CONTENT_PADDING); + } + containerRenderBox->SetBackDecoration(containerDecoration); + containerRenderBox->SetPadding(padding); + } auto stackElement = AceType::DynamicCast(containerBox->GetFirstChild()); if (!stackElement) { @@ -121,6 +138,18 @@ void ContainerModalElement::ShowTitle(bool isShow) return; } + auto contentRenderBox = AceType::DynamicCast(column->GetLastChild()->GetRenderNode()); + if (contentRenderBox) { + auto contentDecoration = AceType::MakeRefPtr(); + contentDecoration->SetBackgroundColor(CONTENT_BACKGROUND_COLOR); + if (isShow) { + Border contentBorder; + contentBorder.SetBorderRadius(Radius(CONTAINER_INNER_RADIUS)); + contentDecoration->SetBorder(contentBorder); + } + contentRenderBox->SetBackDecoration(contentDecoration); + } + // Get first child : title auto display = AceType::DynamicCast(column->GetFirstChild()); if (!display) { diff --git a/frameworks/core/components/container_modal/container_modal_element.h b/frameworks/core/components/container_modal/container_modal_element.h index c2f20590be262c8882c1c06d9169f839c3787b05..0ba18d8aa00f63504dc58b64719b7992a6ce2535 100644 --- a/frameworks/core/components/container_modal/container_modal_element.h +++ b/frameworks/core/components/container_modal/container_modal_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/core/components/container_modal/render_container_modal.cpp b/frameworks/core/components/container_modal/render_container_modal.cpp index 8dd2c1bb6940a79faa2afc6a5b5403bfb6b29856..69bee675d77bc32fe4ccc8d0b0370bcc8690ab1b 100644 --- a/frameworks/core/components/container_modal/render_container_modal.cpp +++ b/frameworks/core/components/container_modal/render_container_modal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/core/components/container_modal/render_container_modal.h b/frameworks/core/components/container_modal/render_container_modal.h index f99d1c00b1e4d5b480cb4c69ae50e9a4318e9256..7200340fa01c7d288877b487ee44e8c51eb1a539 100644 --- a/frameworks/core/components/container_modal/render_container_modal.h +++ b/frameworks/core/components/container_modal/render_container_modal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at