1 /*
2  * Copyright (c) 2022-2023 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_NG_PATTERNS_TABS_TAB_CONTENT_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_CONTENT_MODEL_NG_H
18 
19 #include "base/geometry/axis.h"
20 #include "base/geometry/dimension.h"
21 #include "base/memory/referenced.h"
22 #include "base/utils/macros.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components_ng/pattern/tabs/tab_bar_layout_property.h"
25 #include "core/components_ng/pattern/tabs/tab_content_model.h"
26 #include "core/components_ng/pattern/tabs/tab_content_node.h"
27 #include "core/components_ng/pattern/tabs/tabs_node.h"
28 #include "core/components_ng/pattern/text/text_layout_property.h"
29 
30 namespace OHOS::Ace::NG {
31 
32 using TabBarBuilderFunc = std::function<void()>;
33 
34 class ACE_EXPORT TabContentModelNG : public OHOS::Ace::TabContentModel {
35 public:
36     void Create(std::function<void()>&& deepRenderFunc) override;
37     void Create() override;
38     void Pop() override;
39     void SetTabBar(const std::optional<std::string> &text, const std::optional<std::string> &icon,
40         const std::optional<TabBarSymbol> &tabBarSymbol, TabBarBuilderFunc &&builder, bool useContentOnly) override;
41     void SetTabBarStyle(TabBarStyle tabBarStyle) override;
42     void SetIndicator(const IndicatorStyle& indicator) override;
43     void SetBoard(const BoardStyle& board) override;
44     void SetSelectedMode(SelectedMode selectedMode) override;
45     void SetLabelStyle(const LabelStyle& labelStyle) override;
46     void SetIconStyle(const IconStyle& iconStyle) override;
47     void SetPadding(const NG::PaddingProperty& padding) override;
48     void SetUseLocalizedPadding(bool useLocalizedPadding) override;
49     void SetLayoutMode(LayoutMode layoutMode) override;
50     void SetVerticalAlign(FlexAlign verticalAlign) override;
51     void SetSymmetricExtensible(bool isExtensible) override;
52     void SetId(const std::string& id) override;
53     static void AddTabBarItem(
54         const RefPtr<UINode>& tabContent, int32_t position = DEFAULT_NODE_SLOT, bool update = false);
55     static void RemoveTabBarItem(const RefPtr<TabContentNode>& tabContentNode);
56     static RefPtr<TabsNode> FindTabsNode(const RefPtr<UINode>& tabContent);
57     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId);
58     static void SetTabBarBuilder(FrameNode* node, TabBarBuilderFunc&& builder);
59     static void SetTabBarLabel(FrameNode* node, const std::string& label);
60     void SetOnWillShow(std::function<void()>&& onWillShow) override;
61     void SetOnWillHide(std::function<void()>&& onWillHide) override;
62     void SetCustomStyleNode(const RefPtr<NG::FrameNode>& customStyleNode) override;
63     static void SetCustomTabBar(FrameNode* node, FrameNode* tabBar);
64     static void UpdateDefaultSymbol(RefPtr<TabTheme>& tabTheme, RefPtr<TextLayoutProperty> symbolProperty);
65     static void UpdateSymbolEffect(RefPtr<TextLayoutProperty> symbolProperty, bool isActive);
66 
67 private:
68     static void UpdateLabelStyle(const LabelStyle& labelStyle, RefPtr<TextLayoutProperty> textLayoutProperty);
69 };
70 
71 } // namespace OHOS::Ace::NG
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_CONTENT_MODEL_NG_H
73