1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_CONTAINER_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_CONTAINER_COMPONENT_H 18 19 #include "core/components/tab_bar/tab_controller.h" 20 #include "core/pipeline/base/component_group.h" 21 22 namespace OHOS::Ace { 23 24 struct ToolBarItem : public virtual AceType { 25 DECLARE_ACE_TYPE(ToolBarItem, AceType); 26 27 public: 28 ToolBarItem() = default; ToolBarItemToolBarItem29 ToolBarItem(const std::string& value, const std::string& icon, const EventMarker& action) 30 : value(value), icon(icon), action(action) 31 {} 32 ~ToolBarItem() = default; 33 34 std::string value; 35 std::string icon; 36 EventMarker action; 37 EventMarker actionWithParam; 38 }; 39 40 enum class NavigationTitleMode { 41 FREE = 0, 42 FULL, 43 MINI, 44 }; 45 46 struct ACE_EXPORT NavigationDeclaration : public virtual AceType { 47 DECLARE_ACE_TYPE(NavigationDeclaration, AceType); 48 49 public: HasToolBarNavigationDeclaration50 bool HasToolBar() 51 { 52 return (!hideToolbar && !toolbarItems.empty()) || (!hideToolbar && toolBarBuilder); 53 } 54 55 RefPtr<Component> customTitle; 56 std::string title; 57 std::string subTitle; 58 bool hideBarBackButton = false; 59 RefPtr<Component> customMenus; 60 std::list<RefPtr<ToolBarItem>> menuItems; 61 NavigationTitleMode titleMode = NavigationTitleMode::MINI; 62 bool hideBar = false; 63 EventMarker titleModeChangedEvent; 64 65 std::list<RefPtr<ToolBarItem>> toolbarItems; 66 RefPtr<Component> toolBarBuilder; 67 bool hideToolbar = false; 68 AnimationOption animationOption; 69 }; 70 71 class ACE_EXPORT NavigationContainerComponent : public ComponentGroup { 72 DECLARE_ACE_TYPE(NavigationContainerComponent, ComponentGroup); 73 74 public: NavigationContainerComponent()75 NavigationContainerComponent() : declaration_(AceType::MakeRefPtr<NavigationDeclaration>()) {} NavigationContainerComponent(const RefPtr<Component> & navigationbar,const RefPtr<Component> & content)76 NavigationContainerComponent(const RefPtr<Component>& navigationbar, const RefPtr<Component>& content) 77 : ComponentGroup() 78 { 79 ComponentGroup::AppendChild(navigationbar); 80 ComponentGroup::AppendChild(content); 81 } 82 ~NavigationContainerComponent() override = default; 83 84 RefPtr<RenderNode> CreateRenderNode() override; 85 RefPtr<Element> CreateElement() override; 86 87 static uint32_t GetGlobalTabControllerId(); 88 static RefPtr<ComposedComponent> BuildToolBar( 89 const RefPtr<NavigationDeclaration>& declaration, const RefPtr<TabController>& controller); 90 GetTabController()91 RefPtr<TabController> GetTabController() 92 { 93 return tabController_; 94 } GetDeclaration()95 RefPtr<NavigationDeclaration> GetDeclaration() 96 { 97 return declaration_; 98 } 99 void Build(const WeakPtr<PipelineContext>& context, int32_t menuCount); 100 SetMenuCount(int32_t menuCount)101 void SetMenuCount(int32_t menuCount) 102 { 103 menuCount_ = menuCount; 104 } 105 GetMenuCount()106 int32_t GetMenuCount() const 107 { 108 return menuCount_; 109 } 110 111 private: 112 bool NeedSection() const; 113 114 RefPtr<NavigationDeclaration> declaration_; 115 RefPtr<TabController> tabController_; 116 int32_t menuCount_ = 0; 117 }; 118 119 } // namespace OHOS::Ace 120 121 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_CONTAINER_COMPONENT_H 122