• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             LOGD("No builder function for tab.");
80             return nullptr;
81         }
82     }
83 
SetBuilder(std::function<RefPtr<Component> ()> && builder)84     void SetBuilder(std::function<RefPtr<Component>()>&& builder)
85     {
86         if (builder) {
87             builder_ = std::make_unique<std::function<RefPtr<Component>()>>(std::move(builder));
88         } else {
89             builder_.reset();
90         }
91     }
92 
HasBuilder()93     bool HasBuilder()
94     {
95         return builder_ != nullptr;
96     }
97 
ExecuteBarBuilder()98     RefPtr<Component> ExecuteBarBuilder() const
99     {
100         if (barBuilder_) {
101             return (*barBuilder_)();
102         }
103         LOGD("No builder function for tab.");
104         return nullptr;
105     }
106 
SetBarBuilder(std::function<RefPtr<Component> ()> && barBuilder)107     void SetBarBuilder(std::function<RefPtr<Component>()>&& barBuilder)
108     {
109         if (barBuilder) {
110             barBuilder_ = std::make_unique<std::function<RefPtr<Component>()>>(std::move(barBuilder));
111         } else {
112             barBuilder_.reset();
113         }
114     }
115 
HasBarBuilder()116     bool HasBarBuilder()
117     {
118         return barBuilder_ != nullptr;
119     }
120 
121 private:
122     WeakPtr<TabsComponent> tabsComponent_;
123     std::string barIcon_;
124     std::string barText_;
125     std::unique_ptr<std::function<RefPtr<Component>()>> builder_ = nullptr;
126     std::unique_ptr<std::function<RefPtr<Component>()>> barBuilder_ = nullptr;
127     ElementIdType tabBarItemElementId_ = ElementRegister::UndefinedElementId;
128 };
129 
130 } // namespace OHOS::Ace::V2
131 
132 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS_TAB_CONTENT_ITEM_COMPONENT_H
133