From 260c64873bc4e04bc9cbf4e95f52c81864312197 Mon Sep 17 00:00:00 2001 From: yan-shuifeng Date: Fri, 11 Mar 2022 15:35:40 +0800 Subject: [PATCH] fixed 9e5d1d8 from https://gitee.com/yan-shuifeng/ace_ace_engine/pulls/1621 enable lazy load for tabs and fix the problem of tab content. Signed-off-by: yan-shuifeng Change-Id: I8d6edab56e22ddb9a025acab62c35d9366a3bd05 --- frameworks/base/log/log_wrapper.h | 4 +- frameworks/bridge/common/dom/dom_tab_bar.cpp | 4 +- .../bridge/common/dom/dom_tab_content.cpp | 4 +- .../jsview/js_tab_content.cpp | 22 ++- .../jsview/js_tab_content.h | 15 +- .../declarative_frontend/jsview/js_tabs.cpp | 39 +++-- .../declarative_frontend/jsview/js_tabs.h | 3 +- frameworks/core/BUILD.gn | 3 +- frameworks/core/components/tab_bar/BUILD.gn | 5 +- .../components/tab_bar/render_tab_bar.cpp | 39 +++-- .../core/components/tab_bar/render_tab_bar.h | 4 +- .../components/tab_bar/render_tab_content.cpp | 58 +++++-- .../components/tab_bar/render_tab_content.h | 43 ++++- .../components/tab_bar/tab_bar_component.h | 6 +- .../components/tab_bar/tab_bar_element.cpp | 4 +- .../tab_bar/tab_content_component.cpp | 6 +- .../tab_bar/tab_content_component.h | 8 +- .../tab_bar/tab_content_element.cpp | 63 +------ .../components/tab_bar/tab_content_element.h | 9 +- .../components/tab_bar/tab_controller.cpp | 42 ++++- .../core/components/tab_bar/tab_controller.h | 27 ++- .../components_v2/common/element_proxy.cpp | 8 +- .../core/components_v2/grid/grid_element.h | 4 +- .../inspector/tab_content_composed_element.h | 4 +- .../inspector/tabs_composed_element.h | 4 +- .../core/components_v2/list/list_element.h | 4 +- .../components_v2/swiper/swiper_element.h | 6 +- frameworks/core/components_v2/tabs/BUILD.gn | 23 +++ .../tabs}/tab_content_item_component.cpp | 15 +- .../tabs}/tab_content_item_component.h | 16 +- .../tabs}/tab_content_item_element.cpp | 11 +- .../tabs}/tab_content_item_element.h | 14 +- .../tabs/tab_content_proxy_element.cpp | 158 ++++++++++++++++++ .../tabs/tab_content_proxy_element.h | 50 ++++++ .../tabs}/tabs_component.cpp | 27 +-- .../tabs}/tabs_component.h | 14 +- .../tabs}/tabs_element.h | 14 +- 37 files changed, 561 insertions(+), 219 deletions(-) create mode 100644 frameworks/core/components_v2/tabs/BUILD.gn rename frameworks/core/{components/tab_bar => components_v2/tabs}/tab_content_item_component.cpp (63%) rename frameworks/core/{components/tab_bar => components_v2/tabs}/tab_content_item_component.h (80%) rename frameworks/core/{components/tab_bar => components_v2/tabs}/tab_content_item_element.cpp (75%) rename frameworks/core/{components/tab_bar => components_v2/tabs}/tab_content_item_element.h (74%) create mode 100644 frameworks/core/components_v2/tabs/tab_content_proxy_element.cpp create mode 100644 frameworks/core/components_v2/tabs/tab_content_proxy_element.h rename frameworks/core/{components/tab_bar => components_v2/tabs}/tabs_component.cpp (73%) rename frameworks/core/{components/tab_bar => components_v2/tabs}/tabs_component.h (88%) rename frameworks/core/{components/tab_bar => components_v2/tabs}/tabs_element.h (68%) diff --git a/frameworks/base/log/log_wrapper.h b/frameworks/base/log/log_wrapper.h index d9e937b3..ecd59a48 100644 --- a/frameworks/base/log/log_wrapper.h +++ b/frameworks/base/log/log_wrapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -24,7 +24,7 @@ #include "base/utils/system_properties.h" #ifdef ACE_INSTANCE_LOG -#define ACE_FMT_PREFIX "[%{private}s(%{private}s)-(%{public}d)] " +#define ACE_FMT_PREFIX "[%{public}s(%{public}s)-(%{public}d)] " #define ACE_LOG_ID , OHOS::Ace::LogWrapper::GetId() #else #define ACE_FMT_PREFIX "[%{private}s(%{private}s)] " diff --git a/frameworks/bridge/common/dom/dom_tab_bar.cpp b/frameworks/bridge/common/dom/dom_tab_bar.cpp index e37c9789..63f7a4d3 100644 --- a/frameworks/bridge/common/dom/dom_tab_bar.cpp +++ b/frameworks/bridge/common/dom/dom_tab_bar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -133,7 +133,7 @@ void DOMTabBar::OnMounted(const RefPtr& parentNode) lastIndex_ = parentNodeTmp->GetTabIndex(); controllerId_ = parentNodeTmp->GetTabControllerId(); const auto& controller = parentNodeTmp->GetTabController(); - controller->SetIndex(lastIndex_); + controller->SetIndexWithoutChangeContent(static_cast(lastIndex_)); tabBarChild_->SetController(controller); PrepareChangeListener(); } diff --git a/frameworks/bridge/common/dom/dom_tab_content.cpp b/frameworks/bridge/common/dom/dom_tab_content.cpp index f8043b8d..05fd1007 100644 --- a/frameworks/bridge/common/dom/dom_tab_content.cpp +++ b/frameworks/bridge/common/dom/dom_tab_content.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -93,7 +93,7 @@ void DOMTabContent::OnMounted(const RefPtr& parentNode) index_ = parentNodeTmp->GetTabIndex(); controllerId_ = parentNodeTmp->GetTabControllerId(); const auto& controller = parentNodeTmp->GetTabController(); - controller->SetIndex(index_); + controller->SetIndexWithoutChangeContent(static_cast(index_)); tabContentChild_->SetController(controller); vertical_ = parentNodeTmp->IsVertical(); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_tab_content.cpp b/frameworks/bridge/declarative_frontend/jsview/js_tab_content.cpp index 77b9567b..2afc5ffd 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_tab_content.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_tab_content.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -32,15 +32,19 @@ constexpr char DEFAULT_TAB_BAR_NAME[] = "TabBar"; void JSTabContent::Create() { - auto tabsComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetTopTabs()); + auto tabsComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetTopTabs()); if (tabsComponent) { auto tabBar = tabsComponent->GetTabBarChild(); std::list> components; - auto tabContentItemComponent = AceType::MakeRefPtr(components); + auto tabContentItemComponent = AceType::MakeRefPtr(components); tabContentItemComponent->SetCrossAxisSize(CrossAxisSize::MAX); tabContentItemComponent->SetTabsComponent(AceType::WeakClaim(AceType::RawPtr(tabsComponent))); tabBar->AppendChild(CreateTabBarLabelComponent(tabContentItemComponent, std::string(DEFAULT_TAB_BAR_NAME))); ViewStackProcessor::GetInstance()->Push(tabContentItemComponent); + auto box = ViewStackProcessor::GetInstance()->GetBoxComponent(); + if (box) { + box->SetBoxClipFlag(true); + } } else { LOGE("fail to create tab content due to tabs missing"); } @@ -49,12 +53,12 @@ void JSTabContent::Create() void JSTabContent::SetTabBar(const JSCallbackInfo& info) { auto tabContentItemComponent = - AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!tabContentItemComponent) { return; } auto weakTabs = tabContentItemComponent->GetTabsComponent(); - RefPtr tabs = weakTabs.Upgrade(); + auto tabs = weakTabs.Upgrade(); if (!tabs) { LOGE("can not get Tabs parent component error."); return; @@ -97,7 +101,7 @@ void JSTabContent::SetTabBar(const JSCallbackInfo& info) } RefPtr JSTabContent::ProcessTabBarBuilderFunction( - RefPtr& tabContent, const JSRef builderFunc) + RefPtr& tabContent, JSRef builderFunc) { tabContent->SetBarText("custom"); ScopedViewStackProcessor builderViewStackProcessor; @@ -109,7 +113,7 @@ RefPtr JSTabContent::ProcessTabBarBuilderFunction( } RefPtr JSTabContent::CreateTabBarLabelComponent( - RefPtr& tabContent, const std::string& labelStr) + RefPtr& tabContent, const std::string& labelStr) { tabContent->SetBarText(labelStr); auto text = AceType::MakeRefPtr(labelStr); @@ -123,7 +127,7 @@ RefPtr JSTabContent::CreateTabBarLabelComponent( } RefPtr JSTabContent::ProcessTabBarLabel( - RefPtr& tabContent, JSRef labelVal) + RefPtr& tabContent, JSRef labelVal) { std::string textStr; if (!ParseJsString(labelVal, textStr)) { @@ -133,7 +137,7 @@ RefPtr JSTabContent::ProcessTabBarLabel( } RefPtr JSTabContent::ProcessTabBarTextIconPair( - RefPtr& tabContent, JSRef textVal, JSRef iconVal) + RefPtr& tabContent, JSRef textVal, JSRef iconVal) { std::string iconUri; if (!ParseJsMedia(iconVal, iconUri)) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_tab_content.h b/frameworks/bridge/declarative_frontend/jsview/js_tab_content.h index ea5b8253..b3055a0c 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_tab_content.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_tab_content.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -19,8 +19,8 @@ #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" #include "frameworks/core/components/tab_bar/tab_content_component.h" -#include "frameworks/core/components/tab_bar/tab_content_item_component.h" -#include "frameworks/core/components/tab_bar/tabs_component.h" +#include "frameworks/core/components_v2/tabs/tab_content_item_component.h" +#include "frameworks/core/components_v2/tabs/tabs_component.h" namespace OHOS::Ace::Framework { @@ -50,12 +50,13 @@ protected: private: static RefPtr ProcessTabBarBuilderFunction( - RefPtr& tabContent, JSRef builderFunc); + RefPtr& tabContent, JSRef builderFunc); static RefPtr ProcessTabBarTextIconPair( - RefPtr& tabContent, JSRef text, JSRef icon); + RefPtr& tabContent, JSRef text, JSRef icon); static RefPtr CreateTabBarLabelComponent( - RefPtr& tabContent, const std::string& labelStr); - static RefPtr ProcessTabBarLabel(RefPtr& tabContent, JSRef labelVal); + RefPtr& tabContent, const std::string& labelStr); + static RefPtr ProcessTabBarLabel( + RefPtr& tabContent, JSRef labelVal); }; } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp b/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp index 5764a37e..5106cb66 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -17,7 +17,7 @@ #include "core/components/tab_bar/tab_bar_component.h" #include "core/components/tab_bar/tab_content_component.h" -#include "core/components/tab_bar/tabs_component.h" +#include "core/components_v2/tabs/tabs_component.h" #include "frameworks/bridge/declarative_frontend/jsview/js_tabs_controller.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" @@ -50,7 +50,7 @@ void JSTabs::SetOnChange(const JSCallbackInfo& args) ACE_SCORING_EVENT("Tabs.onChange"); func->Execute(*TabsInfo); }); - auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (component) { auto tabContent = component->GetTabContentChild(); if (tabContent) { @@ -86,12 +86,11 @@ void JSTabs::Create(const JSCallbackInfo& info) if (!tabController) { tabController = JSTabsController::CreateController(); } - tabController->SetIndex(index->ToNumber()); + tabController->SetInitialIndex(index->ToNumber()); } } std::list> children; - RefPtr tabsComponent = - AceType::MakeRefPtr(children, barVal, tabController); + auto tabsComponent = AceType::MakeRefPtr(children, barVal, tabController); auto tabBar = tabsComponent->GetTabBarChild(); if (tabBar) { auto theme = GetTheme(); @@ -113,7 +112,7 @@ void JSTabs::Pop() void JSTabs::SetVertical(const std::string& value) { - auto tabsComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto tabsComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!tabsComponent) { return; } @@ -135,7 +134,7 @@ void JSTabs::SetVertical(const std::string& value) void JSTabs::SetScrollable(const std::string& value) { - auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!component) { return; } @@ -147,7 +146,7 @@ void JSTabs::SetScrollable(const std::string& value) void JSTabs::SetBarMode(const std::string& value) { - auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!component) { return; } @@ -159,7 +158,7 @@ void JSTabs::SetBarMode(const std::string& value) void JSTabs::SetBarWidth(const JSCallbackInfo& info) { - auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!component) { return; } @@ -187,7 +186,7 @@ void JSTabs::SetBarWidth(const JSCallbackInfo& info) void JSTabs::SetBarHeight(const JSCallbackInfo& info) { - auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!component) { return; } @@ -213,9 +212,24 @@ void JSTabs::SetBarHeight(const JSCallbackInfo& info) } } +void JSTabs::SetIndex(int32_t index) +{ + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (!component) { + LOGE("can not find tabs component"); + return; + } + auto controller = component->GetTabsController(); + if (controller) { + controller->SetPendingIndex(index); + } else { + LOGE("can not find controller"); + } +} + void JSTabs::SetAnimationDuration(float value) { - auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (!component) { return; } @@ -236,6 +250,7 @@ void JSTabs::JSBind(BindingTarget globalObj) JSClass::StaticMethod("barMode", &JSTabs::SetBarMode); JSClass::StaticMethod("barWidth", &JSTabs::SetBarWidth); JSClass::StaticMethod("barHeight", &JSTabs::SetBarHeight); + JSClass::StaticMethod("index", &JSTabs::SetIndex); JSClass::StaticMethod("animationDuration", &JSTabs::SetAnimationDuration); JSClass::StaticMethod("onChange", &JSTabs::SetOnChange); JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_tabs.h b/frameworks/bridge/declarative_frontend/jsview/js_tabs.h index 4db9e4e3..e340d2df 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_tabs.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_tabs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -27,6 +27,7 @@ public: static void Pop(); protected: + static void SetIndex(int32_t number); static void SetVertical(const std::string& value); static void SetScrollable(const std::string& value); static void SetBarMode(const std::string& value); diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index fc1cff9c..83609f7f 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -326,6 +326,7 @@ template("ace_core_source_set") { "$ace_root/frameworks/core/components_v2/list:ace_core_components_list_v2_$platform", "$ace_root/frameworks/core/components_v2/pattern_lock:ace_core_components_pattern_lock_$platform", "$ace_root/frameworks/core/components_v2/swiper:ace_core_components_swiper_v2_$platform", + "$ace_root/frameworks/core/components_v2/tabs:ace_core_components_tabs_v2_$platform", ] if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { diff --git a/frameworks/core/components/tab_bar/BUILD.gn b/frameworks/core/components/tab_bar/BUILD.gn index ae2f0404..f08b62f3 100644 --- a/frameworks/core/components/tab_bar/BUILD.gn +++ b/frameworks/core/components/tab_bar/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -31,10 +31,7 @@ build_component("tab_bar") { "tab_bar_size_animation.cpp", "tab_content_component.cpp", "tab_content_element.cpp", - "tab_content_item_component.cpp", - "tab_content_item_element.cpp", "tab_controller.cpp", - "tabs_component.cpp", ] rosen_sources = [ "rosen_render_tab_bar.cpp", diff --git a/frameworks/core/components/tab_bar/render_tab_bar.cpp b/frameworks/core/components/tab_bar/render_tab_bar.cpp index f42f29eb..43fe7786 100644 --- a/frameworks/core/components/tab_bar/render_tab_bar.cpp +++ b/frameworks/core/components/tab_bar/render_tab_bar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -43,10 +43,7 @@ void RenderTabBar::Update(const RefPtr& component) } tabsSize_ = static_cast(tabBar->GetChildren().size()); auto tabController = tabBar->GetController(); - if (tabController) { - auto index = tabController->GetIndex(); - index_ = (index >= 0 && index < tabsSize_) ? index : 0; - } + FlushIndex(tabController); if (initialUpdate_) { auto barIndicator = tabBar->GetIndicator(); if (barIndicator) { @@ -76,6 +73,27 @@ void RenderTabBar::Update(const RefPtr& component) MarkNeedLayout(); } +void RenderTabBar::FlushIndex(const RefPtr& controller) +{ + if (!controller) { + return; + } + int32_t index = 0; + if (controller->IsIndexDefined()) { + index = controller->GetIndex(); + } else { + auto initialIndex = controller->GetInitialIndex(); + auto pendingIndex = controller->GetPendingIndex(); + if (initialUpdate_ && pendingIndex < 0) { + index = initialIndex < 0 ? 0 : initialIndex; + } else { + index = pendingIndex < 0 ? 0 : pendingIndex; + } + } + index_ = index < tabsSize_ ? index : tabsSize_ - 1; + controller->SetIndexWithoutChangeContent(index_); +} + void RenderTabBar::PerformLayout() { tabsSize_ = 0; @@ -96,8 +114,9 @@ void RenderTabBar::PerformLayout() index_ = std::clamp(index_, 0, std::max(0, tabsSize_ - 1)); if (!IsRightToLeft()) { if (tabBarWidth_ > 0 && !NearEqual(tabBarWidth_, GetLayoutParam().GetMaxSize().Width())) { - if (!isVertical_ && actualWidth_ > GetLayoutSize().Width() && GreatNotEqual( - GetLayoutParam().GetMaxSize().Width(), actualWidth_ - std::abs(scrollableOffset_.GetX()))) { + if (!isVertical_ && actualWidth_ > GetLayoutSize().Width() && + GreatNotEqual( + GetLayoutParam().GetMaxSize().Width(), actualWidth_ - std::abs(scrollableOffset_.GetX()))) { scrollableOffset_.SetX(scrollableOffset_.GetX() + GetLayoutParam().GetMaxSize().Width() - tabBarWidth_); } } @@ -244,7 +263,7 @@ void RenderTabBar::SetIndex(int32_t index, bool force) { if (index < 0 || index >= tabsSize_) { LOGW("illegal index = %{public}d", index); - index = 0; + return; } if (index_ != index || force) { @@ -635,8 +654,8 @@ void RenderTabBar::OnPaintFinish() double offsetForFocus = NormalizeToPx(OFFSET_FOR_FOCUS); Offset offset = Offset(offsetForFocus, offsetForFocus); layoutSize -= Size(offsetForFocus * 2.0, offsetForFocus * 2.0); - context->ShowFocusAnimation(RRect::MakeRRect(Rect(offset, layoutSize), - Radius(NormalizeToPx(focusRadiusDimension_))), + context->ShowFocusAnimation( + RRect::MakeRRect(Rect(offset, layoutSize), Radius(NormalizeToPx(focusRadiusDimension_))), focusAnimationColor_, position + offset); } } diff --git a/frameworks/core/components/tab_bar/render_tab_bar.h b/frameworks/core/components/tab_bar/render_tab_bar.h index 0cea4d03..963a64ee 100644 --- a/frameworks/core/components/tab_bar/render_tab_bar.h +++ b/frameworks/core/components/tab_bar/render_tab_bar.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -132,6 +132,8 @@ private: } RefPtr GetChildByIndex(int32_t index) const; + void FlushIndex(const RefPtr& controller); + RefPtr clickRecognizer_; RefPtr scrollable_; diff --git a/frameworks/core/components/tab_bar/render_tab_content.cpp b/frameworks/core/components/tab_bar/render_tab_content.cpp index 7e3dfa0a..10fddfd5 100644 --- a/frameworks/core/components/tab_bar/render_tab_content.cpp +++ b/frameworks/core/components/tab_bar/render_tab_content.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -35,15 +35,19 @@ void RenderTabContent::Update(const RefPtr& component) LOGW("tabContent is null"); return; } - auto tabController = tabContent->GetController(); - int32_t count = static_cast(tabContent->GetChildren().size()); - int32_t tabIndex = tabController ? tabController->GetIndex() : 0; - if (count != contentCount_ && tabIndex >= count && tabController) { - tabController->ValidateIndex(count - 1); - tabIndex = tabController->GetIndex(); + controller_ = tabContent->GetController(); + ACE_DCHECK(controller_); + auto context = context_.Upgrade(); + if (context && !context->GetIsDeclarative()) { + contentCount_ = (controller_->GetTotalCount() > 0) ? controller_->GetTotalCount() : 0; + int32_t tabIndex = controller_ ? controller_->GetIndex() : 0; + if (tabIndex >= contentCount_) { + controller_->ValidateIndex((contentCount_ - 1 < 0) ? 0 : (contentCount_ - 1)); + tabIndex = controller_->GetIndex(); + } + currentIndex_ = tabIndex; } - currentIndex_ = tabIndex; - contentCount_ = count; + if (scrollable_ != tabContent->IsScrollable()) { if (animator_ && animator_->IsRunning()) { animator_->Finish(); @@ -53,7 +57,6 @@ void RenderTabContent::Update(const RefPtr& component) scrollDuration_ = tabContent->GetScrollDuration(); isVertical_ = tabContent->IsVertical(); SetTextDirection(tabContent->GetTextDirection()); - auto context = context_.Upgrade(); if (context && context->GetIsDeclarative()) { onChangeEvent_ = AceAsyncEvent&)>::Create( tabContent->GetChangeEventId(), context_); @@ -66,6 +69,31 @@ void RenderTabContent::Update(const RefPtr& component) Initialize(GetContext()); } +void RenderTabContent::FlushIndex() +{ + contentCount_ = controller_->GetTotalCount() > 0 ? controller_->GetTotalCount() : 0; + if (contentCount_ <= 0) { + currentIndex_ = 0; + return; + } + do { + if (controller_->IsIndexDefined()) { + currentIndex_ = controller_->GetIndex(); + break; + } + auto initialIndex = controller_->GetInitialIndex(); + auto pendingIndex = controller_->GetPendingIndex(); + if (useInitialIndex_ && pendingIndex < 0) { + currentIndex_ = initialIndex < 0 ? 0 : initialIndex; + break; + } + currentIndex_ = pendingIndex < 0 ? 0 : pendingIndex; + } while (false); + currentIndex_ = currentIndex_ < contentCount_ ? currentIndex_ : (contentCount_ - 1); + controller_->SetIndexWithoutChangeContent(currentIndex_); + useInitialIndex_ = false; +} + void RenderTabContent::Initialize(const WeakPtr& context) { if (!animator_) { @@ -117,8 +145,7 @@ void RenderTabContent::FireContentChangeEvent() const } if (changeEvent_) { LOGI("FireChangeEvent, index = %{public}d.", currentIndex_); - std::string param = - std::string(R"("change",{"index":)").append(std::to_string(currentIndex_).append("},null")); + std::string param = std::string(R"("change",{"index":)").append(std::to_string(currentIndex_).append("},null")); changeEvent_(param); } } @@ -237,7 +264,7 @@ void RenderTabContent::ScrollContents(int32_t newIndex, bool isLinkBar, bool fro tabContent->HandleStartListener(newIndex, needChange, isLinkBar); } }); - animator_->SetDuration(scrollDuration_); + animator_->SetDuration(static_cast(scrollDuration_)); animator_->AddInterpolator(translate_); animator_->Play(); MarkNeedRender(); @@ -355,7 +382,7 @@ void RenderTabContent::UpdateChildPosition(double offset, int32_t currentIndex, LOGD("UpdateChildPosition start offset = %{public}lf, from = %{public}d, to = %{public}d", offset, currentIndex, newIndex); if (currentIndex < 0 || currentIndex >= contentCount_) { - LOGE("currentIndex out of range, currentIndex is %{public}d", currentIndex); + LOGE("currentIndex out of range, currentIndex is %{public}d, %{public}d", currentIndex, contentCount_); return; } const auto& fromItem = contentMap_[currentIndex]; @@ -438,7 +465,7 @@ void RenderTabContent::PerformLayout() } int32_t index = item.first; // make sure the new requested tab start with right position, when in animation - if ((!isDragging_ && !isInAnimation_) || (index == requestedIndex_)) { + if ((!isDragging_ && !isInAnimation_) || (index == requestedIndex_) || forceUpdate_) { if (index < currentIndex_) { childItem->SetPosition(prevPosition); childItem->SetHidden(true); @@ -451,6 +478,7 @@ void RenderTabContent::PerformLayout() } } } + forceUpdate_ = false; requestedIndex_ = -1; } } diff --git a/frameworks/core/components/tab_bar/render_tab_content.h b/frameworks/core/components/tab_bar/render_tab_content.h index 4750f78e..c36a7c45 100644 --- a/frameworks/core/components/tab_bar/render_tab_content.h +++ b/frameworks/core/components/tab_bar/render_tab_content.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -58,15 +58,50 @@ public: void AddChildContent(int32_t index, const RefPtr& child) { + LOGI("AddChildContent: %{public}d", index); + auto iter = contentMap_.begin(); + while (iter != contentMap_.end()) { + if (iter->second == child) { + if (iter->first != index) { + // index has changed, clear map. + contentMap_.clear(); + } + break; + } + iter++; + } contentMap_[index] = child; requestedIndex_ = index; + forceUpdate_ = true; } void RemoveChildContent(int32_t index) { - contentMap_.erase(index); + LOGI("RemoveChildContent: %{public}d", index); + if (contentMap_.find(index) != contentMap_.end()) { + contentMap_.clear(); + forceUpdate_ = true; + } } + void RemoveChildContent(const RefPtr& child) + { + LOGI("RemoveChildContent by content"); + auto iter = contentMap_.begin(); + while (iter != contentMap_.end()) { + if (iter->second == child) { + iter->second->SetHidden(true); + contentMap_.clear(); + forceUpdate_ = true; + break; + } + iter++; + } + } + + // Used by declarative element to flush index after performBuild. + void FlushIndex(); + int32_t GetCurrentIndex() const { return currentIndex_; @@ -141,6 +176,7 @@ private: bool isDragging_ = false; // whether it is dragging bool isInitialized_ = false; bool isVertical_ = false; // whether the tab is vertical + bool forceUpdate_ = false; int32_t contentCount_ = 0; // the count of content int32_t currentIndex_ = 0; // the index of current tab @@ -156,6 +192,9 @@ private: // callbacks when updating the index UpdateIndexFunc callback_; UpdateIndexFunc requireCallback_; + + RefPtr controller_; + bool useInitialIndex_ = true; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/tab_bar/tab_bar_component.h b/frameworks/core/components/tab_bar/tab_bar_component.h index 7f2cf16e..b0356f04 100644 --- a/frameworks/core/components/tab_bar/tab_bar_component.h +++ b/frameworks/core/components/tab_bar/tab_bar_component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -62,11 +62,11 @@ public: void SetIndex(int32_t index) { if (controller_) { - int32_t size = static_cast(GetChildren().size()); + auto size = static_cast(GetChildren().size()); if (index < 0 || index >= size) { index = 0; } - controller_->SetIndex(index); + controller_->SetIndexWithoutChangeContent(index); } } diff --git a/frameworks/core/components/tab_bar/tab_bar_element.cpp b/frameworks/core/components/tab_bar/tab_bar_element.cpp index d23d3074..22d82351 100644 --- a/frameworks/core/components/tab_bar/tab_bar_element.cpp +++ b/frameworks/core/components/tab_bar/tab_bar_element.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -69,7 +69,7 @@ void TabBarElement::Update() if (controller && (controller_ != controller)) { // Get index from old controller before replace. if (!controller->IsIndexDefined() && controller_) { - controller->SetIndex(controller_->GetIndex()); + controller->SetIndexWithoutChangeContent(controller_->GetIndex()); } controller_ = controller; } diff --git a/frameworks/core/components/tab_bar/tab_content_component.cpp b/frameworks/core/components/tab_bar/tab_content_component.cpp index a462e2e9..a6d9437e 100644 --- a/frameworks/core/components/tab_bar/tab_content_component.cpp +++ b/frameworks/core/components/tab_bar/tab_content_component.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -17,6 +17,7 @@ #include "core/components/tab_bar/render_tab_content.h" #include "core/components/tab_bar/tab_content_element.h" +#include "core/components_v2/tabs/tab_content_proxy_element.h" namespace OHOS::Ace { @@ -29,6 +30,9 @@ TabContentComponent::TabContentComponent( RefPtr TabContentComponent::CreateElement() { + if (useProxy_) { + return AceType::MakeRefPtr(GetChildren()); + } return AceType::MakeRefPtr(GetChildren()); } diff --git a/frameworks/core/components/tab_bar/tab_content_component.h b/frameworks/core/components/tab_bar/tab_content_component.h index f4ef24dd..f4f90fd4 100644 --- a/frameworks/core/components/tab_bar/tab_content_component.h +++ b/frameworks/core/components/tab_bar/tab_content_component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -114,11 +114,17 @@ public: return domChangeEventId_; } + void SetUseProxy(bool useProxy) + { + useProxy_ = useProxy; + } + private: RefPtr controller_; bool scrollable_ = true; // the default value is true bool vertical_ = false; // the tab is vertical or not, default value is false + bool useProxy_ = false; float scrollDuration_ = DEFAULT_TABCONTENT_ANIMATION_DURATION; EventMarker changeEventId_; diff --git a/frameworks/core/components/tab_bar/tab_content_element.cpp b/frameworks/core/components/tab_bar/tab_content_element.cpp index 5e2ef128..3cb7f791 100644 --- a/frameworks/core/components/tab_bar/tab_content_element.cpp +++ b/frameworks/core/components/tab_bar/tab_content_element.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -103,13 +103,12 @@ void TabContentElement::Update() LOGE("Get tabContent failed"); return; } - tabContent->SetUpdateType(UpdateType::REBUILD); contents_ = tabContent->GetChildren(); auto controller = tabContent->GetController(); if (controller && (controller_ != controller)) { // Get index from old controller before replace. if (!controller->IsIndexDefined() && controller_) { - controller->SetIndex(controller_->GetIndex()); + controller->SetIndexWithoutChangeContent(controller_->GetIndex()); } controller_ = controller; } @@ -119,8 +118,9 @@ void TabContentElement::Update() } controller_->SetContentElement(AceType::Claim(this)); if (controller_->GetIndex() >= static_cast(contents_.size())) { - controller_->SetIndex(contents_.size() - 1); + controller_->SetIndexWithoutChangeContent(static_cast(contents_.size()) - 1); } + controller_->SetTotalCount(static_cast(contents_.size())); newComponentBuild_ = true; } ComponentGroupElement::Update(); @@ -133,11 +133,6 @@ void TabContentElement::PerformBuild() ComponentGroupElement::PerformBuild(); return; } - auto context = context_.Upgrade(); - if (context && context->GetIsDeclarative()) { - PerformBuildForDeclarative(); - return; - } RefPtr tabContent = AceType::DynamicCast(renderNode_); if (!tabContent || !controller_ || !renderNode_) { LOGW("tabContent or controller is null."); @@ -182,56 +177,6 @@ void TabContentElement::PerformBuild() fromController_ = false; } -void TabContentElement::PerformBuildForDeclarative() -{ - RefPtr tabContent = AceType::DynamicCast(renderNode_); - if (!tabContent || !controller_ || !renderNode_) { - LOGW("tabContent or controller is null."); - return; - } - if (newComponentBuild_) { - newComponentBuild_ = false; - ComponentGroupElement::PerformBuild(); - int32_t index = 0; - for (const auto& element : children_) { - focusIndexMap_.emplace(index); - childMap_[index] = element; - auto renderChild = element->GetRenderNode(); - if (renderChild) { - tabContent->AddChildContent(index, renderChild); - } - index++; - } - if (!childMap_.empty()) { - auto maxValue = childMap_.cbegin()->first; - for (int32_t remove = index; remove < maxValue; remove++) { - focusIndexMap_.erase(remove); - childMap_.erase(remove); - tabContent->RemoveChildContent(remove); - } - } - } - // Do index change. - if (newIndex_ >= static_cast(contents_.size())) { - newIndex_ = contents_.size() - 1; - } - int32_t target = newIndex_ >= 0 ? newIndex_ : controller_->GetIndex(); - LOGD("change to target: %{public}d", target); - // process for new content requested by drag - if (target == newIndex_) { - tabContent->UpdateDragPosition(newIndex_); - newIndex_ = -1; - } - // process for new content requested by tab bar - if (target == newBarIndex_) { - tabContent->ChangeScroll(newBarIndex_, fromController_); - UpdateLastFocusNode(); - newBarIndex_ = -1; - } - lastIndex_ = target; - fromController_ = false; -} - void TabContentElement::OnFocus() { // invoke callback diff --git a/frameworks/core/components/tab_bar/tab_content_element.h b/frameworks/core/components/tab_bar/tab_content_element.h index c3f03ca3..d65e4eb4 100644 --- a/frameworks/core/components/tab_bar/tab_content_element.h +++ b/frameworks/core/components/tab_bar/tab_content_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -35,8 +35,8 @@ public: void PerformBuild() override; void Update() override; void ChangeByContent(int32_t index); - void ChangeByBar(int32_t index, bool isFromController = false); - void PrepareContent(int32_t index); + virtual void ChangeByBar(int32_t index, bool isFromController = false); + virtual void PrepareContent(int32_t index); void ChangeDispatch(int32_t index); RefPtr GetTabContentChild(int32_t index) const; @@ -44,8 +44,7 @@ public: bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override; bool IsFocusable() const override; -private: - void PerformBuildForDeclarative(); +protected: RefPtr CreateRenderNode() override; void UpdateLastFocusNode(); RefPtr GetCurrentFocusNode() const; diff --git a/frameworks/core/components/tab_bar/tab_controller.cpp b/frameworks/core/components/tab_bar/tab_controller.cpp index d46e3161..38dcd768 100644 --- a/frameworks/core/components/tab_bar/tab_controller.cpp +++ b/frameworks/core/components/tab_bar/tab_controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -52,7 +52,7 @@ void TabController::SetPageReady(bool ready) void TabController::SetIndex(int32_t index) { if (index_ == index || index < 0) { - LOGW("Input index is not valid."); + LOGI("SetIndex: Input index is not valid, %{public}d, %{public}d", index_, index); return; } indexDefined_ = true; @@ -66,10 +66,44 @@ void TabController::SetIndex(int32_t index) } } +void TabController::SetInitialIndex(int32_t index) +{ + if (initialIndex_ == index || index < 0) { + LOGI("SetInitialIndex: Input index is not valid, %{public}d, %{public}d", initialIndex_, index); + return; + } + initialIndex_ = index; +} + +void TabController::SetIndexWithoutChangeContent(int32_t index) +{ + if (index_ == index || index < 0) { + LOGI("SetIndexWithoutChangeContent: Input index is not valid, %{public}d, %{public}d", index_, index); + return; + } + indexDefined_ = true; + index_ = index; +} + +void TabController::SetPendingIndex(int32_t index) +{ + if (pendingIndex_ == index || index < 0) { + LOGI("SetPendingIndex: Input index is not valid, %{public}d, %{public}d", pendingIndex_, index); + return; + } + pendingIndex_ = index; +} + void TabController::SetIndexByController(int32_t index, bool blockEvent) { if (index_ == index || index < 0) { - LOGW("Input index is not valid."); + LOGI("SetIndexByController: Input index is not valid, %{public}d, %{public}d", index_, index); + return; + } + if (index >= totalCount_) { + LOGI("index is large than total, %{public}d, %{public}d", index, totalCount_); + SetPendingIndex(index); + indexDefined_ = false; return; } indexDefined_ = true; @@ -108,7 +142,7 @@ void TabController::ChangeDispatch(int32_t index) void TabController::SetIndexByScrollContent(int32_t index) { if (index_ == index || index < 0) { - LOGW("Input index is not valid."); + LOGI("SetIndexByScrollContent: Input index is not valid, %{public}d, %{public}d", index_, index); return; } indexDefined_ = true; diff --git a/frameworks/core/components/tab_bar/tab_controller.h b/frameworks/core/components/tab_bar/tab_controller.h index 55be86d6..d6d6d228 100644 --- a/frameworks/core/components/tab_bar/tab_controller.h +++ b/frameworks/core/components/tab_bar/tab_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -37,9 +37,31 @@ public: int32_t GetId() const; int32_t GetIndex() const; + void SetTotalCount(int32_t totalCount) + { + totalCount_ = totalCount; + } + int32_t GetTotalCount() const + { + return totalCount_; + } + + int32_t GetInitialIndex() const + { + return initialIndex_; + } + + int32_t GetPendingIndex() const + { + return pendingIndex_; + } + void ValidateIndex(int32_t maxIndex); void SetPageReady(bool ready); void SetIndex(int32_t index); + void SetInitialIndex(int32_t index); + void SetPendingIndex(int32_t index); + void SetIndexWithoutChangeContent(int32_t index); void SetIndexByController(int32_t index, bool blockEvent = true); void SetIndexByScrollContent(int32_t index); void SetContentElement(const RefPtr& contentElement); @@ -61,6 +83,9 @@ public: private: int32_t id_ = -1; int32_t index_ = 0; + int32_t initialIndex_ = -1; + int32_t pendingIndex_ = -1; + int32_t totalCount_ = 0; bool pageReady_ = false; bool indexDefined_ = false; WeakPtr contentElement_; diff --git a/frameworks/core/components_v2/common/element_proxy.cpp b/frameworks/core/components_v2/common/element_proxy.cpp index 952ee24c..972c0c79 100644 --- a/frameworks/core/components_v2/common/element_proxy.cpp +++ b/frameworks/core/components_v2/common/element_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -481,7 +481,7 @@ public: private: class LazyForEachCache final { public: - explicit LazyForEachCache(const RefPtr component) + explicit LazyForEachCache(const RefPtr& component) : lazyForEachComponent_(component), count_(component->TotalCount()) {} ~LazyForEachCache() = default; @@ -534,7 +534,7 @@ private: class LinearElementProxy : public ElementProxy { public: explicit LinearElementProxy(const WeakPtr& host) : ElementProxy(host) {} - virtual ~LinearElementProxy() override = default; + ~LinearElementProxy() override = default; void UpdateIndex(size_t startIndex) override { @@ -708,7 +708,7 @@ public: class MultiComposedElementProxy : public LinearElementProxy { public: explicit MultiComposedElementProxy(const WeakPtr& host) : LinearElementProxy(host) {} - virtual ~MultiComposedElementProxy() override = default; + ~MultiComposedElementProxy() override = default; void Update(const RefPtr& component, size_t startIndex) override { diff --git a/frameworks/core/components_v2/grid/grid_element.h b/frameworks/core/components_v2/grid/grid_element.h index 018c6013..7ff41e24 100644 --- a/frameworks/core/components_v2/grid/grid_element.h +++ b/frameworks/core/components_v2/grid/grid_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -24,7 +24,7 @@ namespace OHOS::Ace::V2 { class GridElement : public RenderElement, public FocusGroup, public FlushEvent, private V2::ElementProxyHost { - DECLARE_ACE_TYPE(GridElement, RenderElement, FocusGroup); + DECLARE_ACE_TYPE(GridElement, RenderElement, FocusGroup, FlushEvent); public: void Update() override; diff --git a/frameworks/core/components_v2/inspector/tab_content_composed_element.h b/frameworks/core/components_v2/inspector/tab_content_composed_element.h index 5761e85c..64bed52c 100644 --- a/frameworks/core/components_v2/inspector/tab_content_composed_element.h +++ b/frameworks/core/components_v2/inspector/tab_content_composed_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -17,8 +17,8 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INSPECTOR_TAB_CONTENT_COMPOSED_ELEMENT_H #include "core/components/tab_bar/render_tab_content.h" -#include "core/components/tab_bar/tab_content_item_element.h" #include "core/components_v2/inspector/inspector_composed_element.h" +#include "core/components_v2/tabs/tab_content_item_element.h" #include "core/pipeline/base/composed_element.h" namespace OHOS::Ace::V2 { diff --git a/frameworks/core/components_v2/inspector/tabs_composed_element.h b/frameworks/core/components_v2/inspector/tabs_composed_element.h index ab397bf9..89fc7a8d 100644 --- a/frameworks/core/components_v2/inspector/tabs_composed_element.h +++ b/frameworks/core/components_v2/inspector/tabs_composed_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -20,8 +20,8 @@ #include "core/components/flex/render_flex.h" #include "core/components/tab_bar/render_tab_bar.h" #include "core/components/tab_bar/render_tab_content.h" -#include "core/components/tab_bar/tabs_element.h" #include "core/components_v2/inspector/inspector_composed_element.h" +#include "core/components_v2/tabs/tabs_element.h" #include "core/pipeline/base/composed_element.h" namespace OHOS::Ace::V2 { diff --git a/frameworks/core/components_v2/list/list_element.h b/frameworks/core/components_v2/list/list_element.h index 972d476c..00fd5e84 100644 --- a/frameworks/core/components_v2/list/list_element.h +++ b/frameworks/core/components_v2/list/list_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -29,7 +29,7 @@ class ListElement : public RenderElement, public FlushEvent, private ListItemGenerator, private ElementProxyHost { - DECLARE_ACE_TYPE(V2::ListElement, RenderElement, FocusGroup); + DECLARE_ACE_TYPE(V2::ListElement, RenderElement, FocusGroup, FlushEvent); public: ListElement(); diff --git a/frameworks/core/components_v2/swiper/swiper_element.h b/frameworks/core/components_v2/swiper/swiper_element.h index a6548eee..dfbdd459 100644 --- a/frameworks/core/components_v2/swiper/swiper_element.h +++ b/frameworks/core/components_v2/swiper/swiper_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -22,8 +22,8 @@ namespace OHOS::Ace::V2 { -class SwiperElement : public RenderElement, public FocusGroup, private V2::ElementProxyHost, public FlushEvent { - DECLARE_ACE_TYPE(SwiperElement, RenderElement, FocusGroup); +class SwiperElement : public RenderElement, public FocusGroup, public FlushEvent, private V2::ElementProxyHost { + DECLARE_ACE_TYPE(SwiperElement, RenderElement, FocusGroup, FlushEvent); public: void PerformBuild() override; diff --git a/frameworks/core/components_v2/tabs/BUILD.gn b/frameworks/core/components_v2/tabs/BUILD.gn new file mode 100644 index 00000000..2abbea3d --- /dev/null +++ b/frameworks/core/components_v2/tabs/BUILD.gn @@ -0,0 +1,23 @@ +# 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. + +import("//foundation/ace/ace_engine/frameworks/core/components/components.gni") + +build_component("tabs_v2") { + sources = [ + "tab_content_item_component.cpp", + "tab_content_item_element.cpp", + "tab_content_proxy_element.cpp", + "tabs_component.cpp", + ] +} diff --git a/frameworks/core/components/tab_bar/tab_content_item_component.cpp b/frameworks/core/components_v2/tabs/tab_content_item_component.cpp similarity index 63% rename from frameworks/core/components/tab_bar/tab_content_item_component.cpp rename to frameworks/core/components_v2/tabs/tab_content_item_component.cpp index ac47700d..7b67828f 100644 --- a/frameworks/core/components/tab_bar/tab_content_item_component.cpp +++ b/frameworks/core/components_v2/tabs/tab_content_item_component.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -13,18 +13,19 @@ * limitations under the License. */ -#include "core/components/tab_bar/tab_content_item_component.h" +#include "core/components_v2/tabs/tab_content_item_component.h" -#include "core/components/tab_bar/tab_content_item_element.h" +#include "core/components_v2/tabs/tab_content_item_element.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { -TabContentItemComponent::TabContentItemComponent( - std::list>& children) : ColumnComponent(FlexAlign::FLEX_START, FlexAlign::FLEX_START, children) {} +TabContentItemComponent::TabContentItemComponent(std::list>& children) + : ColumnComponent(FlexAlign::FLEX_START, FlexAlign::FLEX_START, children) +{} RefPtr TabContentItemComponent::CreateElement() { return AceType::MakeRefPtr(); } -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace::V2 \ No newline at end of file diff --git a/frameworks/core/components/tab_bar/tab_content_item_component.h b/frameworks/core/components_v2/tabs/tab_content_item_component.h similarity index 80% rename from frameworks/core/components/tab_bar/tab_content_item_component.h rename to frameworks/core/components_v2/tabs/tab_content_item_component.h index 89c01111..fbde18fd 100644 --- a/frameworks/core/components/tab_bar/tab_content_item_component.h +++ b/frameworks/core/components_v2/tabs/tab_content_item_component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_CONTENT_ITEM_COMPONENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_CONTENT_ITEM_COMPONENT_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H -#include "core/components/tab_bar/tabs_component.h" +#include "core/components_v2/tabs/tabs_component.h" #include "core/pipeline/base/element.h" #include "frameworks/core/components/flex/flex_component.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { class ACE_EXPORT TabContentItemComponent : public ColumnComponent { DECLARE_ACE_TYPE(TabContentItemComponent, ColumnComponent); @@ -31,7 +31,7 @@ public: RefPtr CreateElement() override; - WeakPtr GetTabsComponent() const + WeakPtr GetTabsComponent() const { return tabsComponent_; } @@ -67,6 +67,6 @@ private: std::string barText_; }; -} // namespace OHOS::Ace +} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_CONTENT_ITEM_COMPONENT_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H diff --git a/frameworks/core/components/tab_bar/tab_content_item_element.cpp b/frameworks/core/components_v2/tabs/tab_content_item_element.cpp similarity index 75% rename from frameworks/core/components/tab_bar/tab_content_item_element.cpp rename to frameworks/core/components_v2/tabs/tab_content_item_element.cpp index 348ac5f9..ec09cbae 100644 --- a/frameworks/core/components/tab_bar/tab_content_item_element.cpp +++ b/frameworks/core/components_v2/tabs/tab_content_item_element.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -13,17 +13,18 @@ * limitations under the License. */ -#include "core/components/tab_bar/tab_content_item_element.h" +#include "core/components_v2/tabs/tab_content_item_element.h" #include "core/components/flex/flex_element.h" -#include "core/components/tab_bar/tab_content_item_component.h" +#include "core/components_v2/tabs/tab_content_item_component.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { void TabContentItemElement::Update() { auto component = AceType::DynamicCast(component_); if (!component) { + LOGE("TabContentItemComponent is null"); return; } barIcon_ = component->GetBarIcon(); @@ -31,4 +32,4 @@ void TabContentItemElement::Update() FlexElement::Update(); } -} // namespace OHOS::Ace +} // namespace OHOS::Ace::v2 diff --git a/frameworks/core/components/tab_bar/tab_content_item_element.h b/frameworks/core/components_v2/tabs/tab_content_item_element.h similarity index 74% rename from frameworks/core/components/tab_bar/tab_content_item_element.h rename to frameworks/core/components_v2/tabs/tab_content_item_element.h index 06c38131..1c4c4bba 100644 --- a/frameworks/core/components/tab_bar/tab_content_item_element.h +++ b/frameworks/core/components_v2/tabs/tab_content_item_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -13,12 +13,12 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_CONTENT_ITEM_ELEMENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_CONTENT_ITEM_ELEMENT_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_ELEMENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_ELEMENT_H -#include "core/components/tab_bar/tabs_component.h" +#include "core/components_v2/tabs/tabs_component.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { class TabContentItemElement : public ColumnElement { DECLARE_ACE_TYPE(TabContentItemElement, ColumnElement); @@ -41,6 +41,6 @@ private: std::string barText_; }; -} // namespace OHOS::Ace +} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_CONTENT_ITEM_ELEMENT_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_ELEMENT_H diff --git a/frameworks/core/components_v2/tabs/tab_content_proxy_element.cpp b/frameworks/core/components_v2/tabs/tab_content_proxy_element.cpp new file mode 100644 index 00000000..d61c9fc0 --- /dev/null +++ b/frameworks/core/components_v2/tabs/tab_content_proxy_element.cpp @@ -0,0 +1,158 @@ +/* + * 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. + */ + +#include "core/components_v2/tabs/tab_content_proxy_element.h" + +#include "core/components/tab_bar/render_tab_content.h" + +namespace OHOS::Ace::V2 { + +void TabContentProxyElement::Update() +{ + if (!component_) { + return; + } + RefPtr tabContent = AceType::DynamicCast(component_); + if (!tabContent) { + LOGE("Get tabContent failed"); + return; + } + contents_ = tabContent->GetChildren(); + auto controller = tabContent->GetController(); + if (controller && (controller_ != controller)) { + // Get index from old controller before replace. + if (controller_) { + if (!controller->IsIndexDefined()) { + controller->SetIndexWithoutChangeContent(controller_->GetIndex()); + } + controller->SetTotalCount(controller_->GetTotalCount()); + } + controller_ = controller; + } + if (!controller_) { + LOGE("Get controller failed"); + return; + } + controller_->SetContentElement(AceType::Claim(this)); + RenderElement::Update(); +} + +void TabContentProxyElement::PerformBuild() +{ + if (component_) { + auto tabsContentComponent = AceType::DynamicCast(component_); + if (!tabsContentComponent) { + return; + } + ElementProxyHost::UpdateChildren(tabsContentComponent->GetChildren()); + } + auto tabContent = AceType::DynamicCast(renderNode_); + if (!tabContent || !controller_) { + LOGW("tabContent or controller is null."); + return; + } + auto totalCount = static_cast(TotalCount()); + if (newIndex_ < 0 && newBarIndex_ < 0) { + // verify controller index first build and flush index for render. + auto maxIndex = totalCount - 1; + if (controller_->GetIndex() >= totalCount) { + controller_->SetIndexWithoutChangeContent(maxIndex < 0 ? 0 : maxIndex); + } + if (controller_->GetInitialIndex() >= totalCount) { + controller_->SetInitialIndex(maxIndex < 0 ? 0 : maxIndex); + } + if (controller_->GetPendingIndex() >= totalCount) { + controller_->SetPendingIndex(maxIndex < 0 ? 0 : maxIndex); + } + controller_->SetTotalCount(totalCount < 1 ? 0 : totalCount); + tabContent->FlushIndex(); + } + int32_t target = newIndex_ >= 0 ? newIndex_ : controller_->GetIndex(); + auto element = GetElementByIndex(target); + if (!element) { + LOGE("GetElementByIndex failed index=[%{public}d]", target); + return; + } + auto renderNode = element->GetRenderNode(); + if (!renderNode) { + LOGE("GetRenderNode failed"); + return; + } + tabContent->AddChildContent(target, renderNode); + focusIndexMap_.emplace(target); + renderNode_->MarkNeedLayout(); + + // process for new content requested by drag + if (target == newIndex_) { + tabContent->UpdateDragPosition(newIndex_); + newIndex_ = -1; + } + // process for new content requested by tab bar + if (target == newBarIndex_) { + tabContent->ChangeScroll(newBarIndex_, fromController_); + UpdateLastFocusNode(); + newBarIndex_ = -1; + } + lastIndex_ = target; + fromController_ = false; +} + +// In ChangeByBar function the controller has already set index. +void TabContentProxyElement::ChangeByBar(int32_t index, bool isFromController) +{ + LOGD("change content by tab bar index: %{public}d", index); + newBarIndex_ = index; + fromController_ = isFromController; + PerformBuild(); +} + +void TabContentProxyElement::PrepareContent(int32_t index) +{ + LOGD("request prepareContent new index: %{public}d", index); + newIndex_ = index; + PerformBuild(); +} + +RefPtr TabContentProxyElement::OnUpdateElement( + const RefPtr& element, const RefPtr& component) +{ + if (element && !component) { + auto tabContent = AceType::DynamicCast(renderNode_); + if (!tabContent) { + LOGE("tabContent is null."); + } else { + auto renderNode = element->GetRenderNode(); + if (!renderNode) { + LOGW("delete render child is null."); + } else { + tabContent->RemoveChildContent(renderNode); + } + } + } + return UpdateChild(element, component); +} + +RefPtr TabContentProxyElement::OnMakeEmptyComponent() +{ + LOGI("tab content does not support lazyForEach yet"); + return nullptr; +} + +void TabContentProxyElement::OnDataSourceUpdated(size_t startIndex) +{ + LOGI("tab content does not support lazyForEach yet"); +} + +} // namespace OHOS::Ace::V2 \ No newline at end of file diff --git a/frameworks/core/components_v2/tabs/tab_content_proxy_element.h b/frameworks/core/components_v2/tabs/tab_content_proxy_element.h new file mode 100644 index 00000000..1f1089b1 --- /dev/null +++ b/frameworks/core/components_v2/tabs/tab_content_proxy_element.h @@ -0,0 +1,50 @@ +/* + * 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_V2_TABS__TAB_CONTENT_PROXY_ELEMENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS__TAB_CONTENT_PROXY_ELEMENT_H + +#include +#include + +#include "core/components/tab_bar/tab_content_element.h" +#include "core/components/tab_bar/tab_controller.h" +#include "core/components_v2/common/element_proxy.h" +#include "core/focus/focus_node.h" + +namespace OHOS::Ace::V2 { + +class TabContentProxyElement : public TabContentElement, private ElementProxyHost { + DECLARE_ACE_TYPE(TabContentElement, TabContentElement); + +public: + explicit TabContentProxyElement(const std::list>& contents) : TabContentElement(contents) {}; + ~TabContentProxyElement() override = default; + + void PerformBuild() override; + void Update() override; + + void ChangeByBar(int32_t index, bool isFromController = false) override; + void PrepareContent(int32_t index) override; + +private: + RefPtr OnUpdateElement(const RefPtr& element, const RefPtr& component) override; + RefPtr OnMakeEmptyComponent() override; + void OnDataSourceUpdated(size_t startIndex) override; +}; + +} // namespace OHOS::Ace::V2 + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS__TAB_CONTENT_PROXY_ELEMENT_H diff --git a/frameworks/core/components/tab_bar/tabs_component.cpp b/frameworks/core/components_v2/tabs/tabs_component.cpp similarity index 73% rename from frameworks/core/components/tab_bar/tabs_component.cpp rename to frameworks/core/components_v2/tabs/tabs_component.cpp index 43e15187..a5187afe 100644 --- a/frameworks/core/components/tab_bar/tabs_component.cpp +++ b/frameworks/core/components_v2/tabs/tabs_component.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -13,13 +13,13 @@ * limitations under the License. */ -#include "core/components/tab_bar/tabs_component.h" +#include "core/components_v2/tabs/tabs_component.h" #include "core/components/clip/clip_component.h" #include "core/components/foreach/for_each_component.h" -#include "core/components/tab_bar/tabs_element.h" +#include "core/components_v2/tabs/tabs_element.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { namespace { int32_t g_tabControllerId = 0; @@ -40,6 +40,7 @@ TabsComponent::TabsComponent( tabBar_ = AceType::MakeRefPtr(tabBarChildren_, controller_, tabBarIndicator_); tabBar_->SetBarPosition(barPosition); tabContent_ = AceType::MakeRefPtr(tabContentChildren_, controller_); + tabContent_->SetUseProxy(true); flexItem_ = AceType::MakeRefPtr(0, 1, 0); flexItem_->SetChild(tabContent_); auto box = AceType::MakeRefPtr(); @@ -62,24 +63,12 @@ RefPtr TabsComponent::CreateElement() void TabsComponent::AppendChild(const RefPtr& child) { - if (AceType::InstanceOf(child)) { - auto children = DynamicCast(child)->GetChildren(); - for (auto&& item : children) { - auto clip = AceType::MakeRefPtr(item); - clip->SetFollowChild(false); - tabContent_->AppendChildDirectly(clip); - } - return; - } - auto clip = AceType::MakeRefPtr(child); - clip->SetFollowChild(false); - tabContent_->AppendChildDirectly(clip); + tabContent_->AppendChildDirectly(child); } void TabsComponent::RemoveChild(const RefPtr& child) { - auto clip = AceType::DynamicCast(child); - tabContent_->RemoveChildDirectly(clip); + tabContent_->RemoveChildDirectly(child); } -} // namespace OHOS::Ace +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components/tab_bar/tabs_component.h b/frameworks/core/components_v2/tabs/tabs_component.h similarity index 88% rename from frameworks/core/components/tab_bar/tabs_component.h rename to frameworks/core/components_v2/tabs/tabs_component.h index 17bb6aa3..836657d7 100644 --- a/frameworks/core/components/tab_bar/tabs_component.h +++ b/frameworks/core/components_v2/tabs/tabs_component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TABS_COMPONENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TABS_COMPONENT_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TABS_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TABS_COMPONENT_H #include "core/components/tab_bar/tab_controller.h" #include "core/pipeline/base/component_group.h" @@ -22,10 +22,10 @@ #include "core/pipeline/base/render_node.h" #include "frameworks/core/components/flex/flex_component.h" #include "frameworks/core/components/flex/flex_item_component.h" -#include "frameworks/core/components/tab_bar/tab_content_component.h" #include "frameworks/core/components/tab_bar/tab_bar_component.h" +#include "frameworks/core/components/tab_bar/tab_content_component.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { class ACE_EXPORT TabsComponent : public FlexComponent { DECLARE_ACE_TYPE(TabsComponent, FlexComponent); @@ -71,6 +71,6 @@ private: RefPtr flexItem_; }; -} // namespace OHOS::Ace +} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TABS_COMPONENT_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TABS_COMPONENT_H diff --git a/frameworks/core/components/tab_bar/tabs_element.h b/frameworks/core/components_v2/tabs/tabs_element.h similarity index 68% rename from frameworks/core/components/tab_bar/tabs_element.h rename to frameworks/core/components_v2/tabs/tabs_element.h index 4103014a..049d9918 100644 --- a/frameworks/core/components/tab_bar/tabs_element.h +++ b/frameworks/core/components_v2/tabs/tabs_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -12,18 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TABS_ELEMENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TABS_ELEMENT_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TABS_ELEMENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TABS_ELEMENT_H -#include "core/components/tab_bar/tabs_component.h" +#include "core/components_v2/tabs/tabs_component.h" #include "core/pipeline/base/component_group_element.h" -namespace OHOS::Ace { +namespace OHOS::Ace::V2 { class TabsElement : public ComponentGroupElement { DECLARE_ACE_TYPE(TabsElement, ComponentGroupElement); }; -} // namespace OHOS::Ace +} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TABS_ELEMENT_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TABS_ELEMENT_H