1 /* 2 * Copyright (c) 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_NG_PATTERNS_NAVROUTER_NAVROUTER_GROUP_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVROUTER_GROUP_NODE_H 18 19 #include <cstdint> 20 21 #include "core/components_ng/base/frame_node.h" 22 #include "core/components_ng/base/group_node.h" 23 #include "core/components_ng/pattern/navigation/navigation_declaration.h" 24 #include "core/components_ng/property/property.h" 25 26 namespace OHOS::Ace::NG { 27 28 class ACE_EXPORT NavRouterGroupNode : public GroupNode { DECLARE_ACE_TYPE(NavRouterGroupNode,GroupNode)29 DECLARE_ACE_TYPE(NavRouterGroupNode, GroupNode) 30 public: 31 NavRouterGroupNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern) 32 : GroupNode(tag, nodeId, pattern) 33 {} 34 ~NavRouterGroupNode() override = default; 35 void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override; 36 void DeleteChildFromGroup(int32_t slot = DEFAULT_NODE_SLOT) override; 37 static RefPtr<NavRouterGroupNode> GetOrCreateGroupNode( 38 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 39 IsAtomicNode()40 bool IsAtomicNode() const override 41 { 42 return false; 43 } 44 SetNavDestinationNode(const RefPtr<UINode> & navDestinationNode)45 void SetNavDestinationNode(const RefPtr<UINode>& navDestinationNode) 46 { 47 navDestinationNode_ = navDestinationNode; 48 } 49 GetNavDestinationNode()50 const RefPtr<UINode>& GetNavDestinationNode() const 51 { 52 // get the NavDestinationNode which is the child of the NavRouter 53 return navDestinationNode_; 54 } 55 56 void OnDetachFromMainTree(bool recursive) override; 57 void OnAttachToMainTree(bool recursive) override; 58 59 void OnOffscreenProcess(bool recursive) override; 60 61 private: 62 void AddNavDestinationToNavigation(const RefPtr<UINode>& parent); 63 void SetDestinationChangeEvent(const RefPtr<UINode>& parent); 64 bool CleanNodeInNavigation(const RefPtr<UINode>& parent); 65 66 void ProcessDestinationChangeEvent(); 67 68 RefPtr<UINode> navDestinationNode_; 69 }; 70 71 } // namespace OHOS::Ace::NG 72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVROUTER_GROUP_NODE_H 73