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