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_TAB_TAB_CONTENT_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TAB_TAB_CONTENT_NODE_H 18 19 #include "core/components_ng/base/frame_node.h" 20 #include "core/components_ng/pattern/tabs/tab_content_model.h" 21 22 namespace OHOS::Ace::NG { 23 class InspectorFilter; 24 25 class ACE_EXPORT TabContentNode : public FrameNode { 26 DECLARE_ACE_TYPE(TabContentNode, FrameNode); 27 28 public: 29 TabContentNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false) 30 : FrameNode(tag, nodeId, pattern, isRoot) 31 {} 32 ~TabContentNode() = default; 33 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 34 void OnAttachToMainTree(bool recursive) override; 35 void OnDetachFromMainTree(bool recursive, PipelineContext* context = nullptr) override; 36 37 void OnOffscreenProcess(bool recursive) override; 38 39 static RefPtr<TabContentNode> GetOrCreateTabContentNode( 40 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 41 ResetTabBarItemId()42 void ResetTabBarItemId() 43 { 44 tabBarItemId_.reset(); 45 } 46 HasTabBarItemId()47 bool HasTabBarItemId() const 48 { 49 return tabBarItemId_.has_value(); 50 } 51 GetTabBarItemId()52 int32_t GetTabBarItemId() 53 { 54 if (!tabBarItemId_.has_value()) { 55 tabBarItemId_ = ElementRegister::GetInstance()->MakeUniqueId(); 56 } 57 return tabBarItemId_.value(); 58 } 59 60 private: 61 void ProcessTabBarItem(); 62 Axis GetTabBarAxis() const; 63 std::string ConvertFlexAlignToString(FlexAlign verticalAlign) const; 64 std::string ConvertLayoutModeToString(LayoutMode layoutMode) const; 65 66 std::optional<int32_t> tabBarItemId_; 67 ACE_DISALLOW_COPY_AND_MOVE(TabContentNode); 68 }; 69 70 } // namespace OHOS::Ace::NG 71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TAB_TAB_CONTENT_NODE_H 72