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_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H 18 19 #include "core/components_v2/tabs/tabs_component.h" 20 #include "core/pipeline/base/element.h" 21 #include "frameworks/core/components/flex/flex_component.h" 22 23 namespace OHOS::Ace::V2 { 24 25 class ACE_EXPORT TabContentItemComponent : public ColumnComponent { 26 DECLARE_ACE_TYPE(TabContentItemComponent, ColumnComponent); 27 28 public: 29 explicit TabContentItemComponent(std::list<RefPtr<Component>>& children); 30 ~TabContentItemComponent() override = default; 31 32 RefPtr<Element> CreateElement() override; 33 GetTabsComponent()34 WeakPtr<V2::TabsComponent> GetTabsComponent() const 35 { 36 return tabsComponent_; 37 } 38 SetTabsComponent(const WeakPtr<TabsComponent> & tabsComponent)39 void SetTabsComponent(const WeakPtr<TabsComponent>& tabsComponent) 40 { 41 tabsComponent_ = tabsComponent; 42 } 43 SetBarIcon(const std::string & barIcon)44 void SetBarIcon(const std::string& barIcon) 45 { 46 barIcon_ = barIcon; 47 } 48 GetBarIcon()49 const std::string& GetBarIcon() const 50 { 51 return barIcon_; 52 } 53 SetBarText(const std::string & barText)54 void SetBarText(const std::string& barText) 55 { 56 barText_ = barText; 57 } 58 GetBarText()59 const std::string& GetBarText() const 60 { 61 return barText_; 62 } 63 SetBarElementId(ElementIdType id)64 void SetBarElementId(ElementIdType id) 65 { 66 tabBarItemElementId_ = id; 67 } 68 GetBarElementId()69 ElementIdType GetBarElementId() const 70 { 71 return tabBarItemElementId_; 72 } 73 ExecuteBuilder()74 RefPtr<Component> ExecuteBuilder() const 75 { 76 if (builder_) { 77 return (*builder_)(); 78 } else { 79 return nullptr; 80 } 81 } 82 SetBuilder(std::function<RefPtr<Component> ()> && builder)83 void SetBuilder(std::function<RefPtr<Component>()>&& builder) 84 { 85 if (builder) { 86 builder_ = std::make_unique<std::function<RefPtr<Component>()>>(std::move(builder)); 87 } else { 88 builder_.reset(); 89 } 90 } 91 HasBuilder()92 bool HasBuilder() 93 { 94 return builder_ != nullptr; 95 } 96 ExecuteBarBuilder()97 RefPtr<Component> ExecuteBarBuilder() const 98 { 99 if (barBuilder_) { 100 return (*barBuilder_)(); 101 } 102 return nullptr; 103 } 104 SetBarBuilder(std::function<RefPtr<Component> ()> && barBuilder)105 void SetBarBuilder(std::function<RefPtr<Component>()>&& barBuilder) 106 { 107 if (barBuilder) { 108 barBuilder_ = std::make_unique<std::function<RefPtr<Component>()>>(std::move(barBuilder)); 109 } else { 110 barBuilder_.reset(); 111 } 112 } 113 HasBarBuilder()114 bool HasBarBuilder() 115 { 116 return barBuilder_ != nullptr; 117 } 118 119 private: 120 WeakPtr<TabsComponent> tabsComponent_; 121 std::string barIcon_; 122 std::string barText_; 123 std::unique_ptr<std::function<RefPtr<Component>()>> builder_ = nullptr; 124 std::unique_ptr<std::function<RefPtr<Component>()>> barBuilder_ = nullptr; 125 ElementIdType tabBarItemElementId_ = ElementRegister::UndefinedElementId; 126 }; 127 128 } // namespace OHOS::Ace::V2 129 130 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H 131