1 /* 2 * Copyright (c) 2022-2025 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_TABS_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_NODE_H 18 19 #include <optional> 20 21 #include "base/geometry/dimension.h" 22 #include "core/components_ng/base/group_node.h" 23 #include "core/components_ng/pattern/tabs/tabs_model.h" 24 25 namespace OHOS::Ace::NG { 26 namespace { 27 constexpr int32_t SWIPER_INDEX = 0; 28 constexpr int32_t DIVIDER_INDEX = 1; 29 constexpr int32_t TAB_BAR_INDEX = 2; 30 constexpr int32_t EFFECT_INDEX = 3; 31 } // namespace 32 class InspectorFilter; 33 34 class ACE_EXPORT TabsNode : public GroupNode { 35 DECLARE_ACE_TYPE(TabsNode, GroupNode); 36 37 public: 38 TabsNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false) GroupNode(tag,nodeId,pattern,isRoot)39 : GroupNode(tag, nodeId, pattern, isRoot) 40 {} 41 ~TabsNode() override = default; 42 void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override; 43 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 44 HasSwiperNode()45 bool HasSwiperNode() const 46 { 47 return swiperId_.has_value(); 48 } 49 HasTabBarNode()50 bool HasTabBarNode() const 51 { 52 return tabBarId_.has_value(); 53 } 54 HasDividerNode()55 bool HasDividerNode() const 56 { 57 return dividerId_.has_value(); 58 } 59 HasSelectedMaskNode()60 bool HasSelectedMaskNode() const 61 { 62 return selectedMaskId_.has_value(); 63 } 64 HasUnselectedMaskNode()65 bool HasUnselectedMaskNode() const 66 { 67 return unselectedMaskId_.has_value(); 68 } 69 GetSwiperId()70 int32_t GetSwiperId() 71 { 72 if (!swiperId_.has_value()) { 73 swiperId_ = ElementRegister::GetInstance()->MakeUniqueId(); 74 } 75 return swiperId_.value(); 76 } 77 GetDividerId()78 int32_t GetDividerId() 79 { 80 if (!dividerId_.has_value()) { 81 dividerId_ = ElementRegister::GetInstance()->MakeUniqueId(); 82 } 83 return dividerId_.value(); 84 } 85 GetEffectId()86 int32_t GetEffectId() 87 { 88 if (!effectId_.has_value()) { 89 effectId_ = ElementRegister::GetInstance()->MakeUniqueId(); 90 } 91 return effectId_.value(); 92 } 93 GetTabBarId()94 int32_t GetTabBarId() 95 { 96 if (!tabBarId_.has_value()) { 97 tabBarId_ = ElementRegister::GetInstance()->MakeUniqueId(); 98 } 99 return tabBarId_.value(); 100 } 101 GetSelectedMaskId()102 int32_t GetSelectedMaskId() 103 { 104 if (!selectedMaskId_.has_value()) { 105 selectedMaskId_ = ElementRegister::GetInstance()->MakeUniqueId(); 106 } 107 return selectedMaskId_.value(); 108 } 109 GetUnselectedMaskId()110 int32_t GetUnselectedMaskId() 111 { 112 if (!unselectedMaskId_.has_value()) { 113 unselectedMaskId_ = ElementRegister::GetInstance()->MakeUniqueId(); 114 } 115 return unselectedMaskId_.value(); 116 } 117 GetBuilderByContentId(int32_t tabContentId,const RefPtr<UINode> & builderNode)118 RefPtr<UINode> GetBuilderByContentId(int32_t tabContentId, const RefPtr<UINode>& builderNode) 119 { 120 auto iter = builderNode_.find(tabContentId); 121 if (iter == builderNode_.end()) { 122 builderNode_.try_emplace(tabContentId, builderNode); 123 return nullptr; 124 } 125 auto result = iter->second; 126 iter->second = builderNode; 127 return result; 128 } 129 RemoveBuilderByContentId(int32_t tabContentId)130 void RemoveBuilderByContentId(int32_t tabContentId) 131 { 132 builderNode_.erase(tabContentId); 133 } 134 GetTabBar()135 RefPtr<UINode> GetTabBar() 136 { 137 return GetChildAtIndex(TAB_BAR_INDEX); 138 } 139 GetTabs()140 RefPtr<UINode> GetTabs() 141 { 142 return GetChildAtIndex(SWIPER_INDEX); 143 } 144 GetDivider()145 RefPtr<UINode> GetDivider() 146 { 147 return GetChildAtIndex(DIVIDER_INDEX); 148 } 149 GetEffectNode()150 RefPtr<UINode> GetEffectNode() 151 { 152 return GetChildAtIndex(EFFECT_INDEX); 153 } 154 155 private: 156 bool Scrollable() const; 157 const RefPtr<Curve> GetAnimationCurve(const RefPtr<Curve>& defaultCurve) const; 158 std::string GetAnimationCurveStr(const RefPtr<Curve>& defaultCurve) const; 159 int32_t GetAnimationDuration() const; 160 TabBarMode GetTabBarMode() const; 161 Dimension GetBarWidth() const; 162 Dimension GetBarHeight() const; 163 bool GetBarAdaptiveHeight() const; 164 Color GetBarBackgroundColor() const; 165 BlurStyle GetBarBackgroundBlurStyle() const; 166 std::unique_ptr<JsonValue> GetBarBackgroundBlurStyleOptions() const; 167 int32_t GetIndex() const; 168 bool GetFadingEdge() const; 169 BarGridColumnOptions GetBarGridAlign() const; 170 ScrollableBarModeOptions GetScrollableBarModeOptions() const; 171 std::string GetAnimationMode() const; 172 std::string GetEdgeEffect() const; 173 std::unique_ptr<JsonValue> GetBarBackgroundEffect() const; 174 175 std::optional<int32_t> swiperId_; 176 std::optional<int32_t> tabBarId_; 177 std::optional<int32_t> dividerId_; 178 std::optional<int32_t> effectId_; 179 std::optional<int32_t> selectedMaskId_; 180 std::optional<int32_t> unselectedMaskId_; 181 std::set<int32_t> swiperChildren_; 182 std::map<int32_t, RefPtr<UINode>> builderNode_; // Key is id of TabContent, value is id of builder of TabBar. 183 }; 184 185 } // namespace OHOS::Ace::NG 186 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_NODE_H 187