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_NAVDESTINATION_GROUP_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_GROUP_NODE_H
18 
19 #include <cstdint>
20 #include <list>
21 
22 #include "core/components_ng/base/frame_node.h"
23 #include "core/components_ng/base/group_node.h"
24 #include "core/components_ng/pattern/navigation/navdestination_node_base.h"
25 #include "core/components_ng/pattern/navigation/navigation_declaration.h"
26 #include "core/components_ng/property/property.h"
27 #include "core/pipeline/base/element_register.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 class CustomNodeBase;
32 class NavigationTransitionProxy;
33 
34 using NavDestinationBackButtonEvent = std::function<bool(GestureEvent&)>;
35 
36 class ACE_EXPORT NavDestinationGroupNode : public NavDestinationNodeBase {
DECLARE_ACE_TYPE(NavDestinationGroupNode,NavDestinationNodeBase)37     DECLARE_ACE_TYPE(NavDestinationGroupNode, NavDestinationNodeBase)
38 public:
39     NavDestinationGroupNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
40         : NavDestinationNodeBase(tag, nodeId, pattern)
41     {
42         isNewToolbar_ = true;
43     }
44     ~NavDestinationGroupNode() override;
45     void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override;
46     void DeleteChildFromGroup(int32_t slot = DEFAULT_NODE_SLOT) override;
47     static RefPtr<NavDestinationGroupNode> GetOrCreateGroupNode(
48         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
49     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
50 
SetNavDestinationBackButtonEvent(const NavDestinationBackButtonEvent & backButtonEvent)51     void SetNavDestinationBackButtonEvent(const NavDestinationBackButtonEvent& backButtonEvent)
52     {
53         backButtonEvent_ = backButtonEvent;
54     }
55 
GetNavDestinationBackButtonEvent()56     NavDestinationBackButtonEvent GetNavDestinationBackButtonEvent() const
57     {
58         return backButtonEvent_;
59     }
60 
61     void OnAttachToMainTree(bool recursive) override;
62 
63     void OnOffscreenProcess(bool recursive) override;
64 
65     void ProcessShallowBuilder();
66 
SetIsOnAnimation(bool isOnAnimation)67     void SetIsOnAnimation(bool isOnAnimation)
68     {
69         isOnAnimation_ = isOnAnimation;
70     }
71 
IsOnAnimation()72     bool IsOnAnimation() const
73     {
74         return isOnAnimation_;
75     }
76 
77     RefPtr<CustomNodeBase> GetNavDestinationCustomNode();
78 
SetNavDestinationCustomNode(WeakPtr<CustomNodeBase> customNode)79     void SetNavDestinationCustomNode(WeakPtr<CustomNodeBase> customNode)
80     {
81         customNode_ = customNode;
82     }
83 
84     void SetNavDestinationMode(NavDestinationMode mode);
85 
GetNavDestinationMode()86     NavDestinationMode GetNavDestinationMode() const
87     {
88         return mode_;
89     }
90 
SetIndex(int32_t index)91     void SetIndex(int32_t index)
92     {
93         index_ = index;
94     }
95 
GetIndex()96     int32_t GetIndex() const
97     {
98         return index_;
99     }
100 
SetIsCacheNode(bool cache)101     void SetIsCacheNode(bool cache)
102     {
103         isCacheNode_ = cache;
104     }
105 
IsCacheNode()106     bool IsCacheNode() const
107     {
108         return isCacheNode_;
109     }
110 
SetIsAnimated(const bool isAnimated)111     void SetIsAnimated(const bool isAnimated)
112     {
113         isAnimated_ = isAnimated;
114     }
115 
GetIsAnimated()116     bool GetIsAnimated() const
117     {
118         return isAnimated_;
119     }
120 
SetCanReused(bool canReused)121     void SetCanReused(bool canReused)
122     {
123         canReused_ = canReused;
124     }
125 
GetCanReused()126     bool GetCanReused() const
127     {
128         return canReused_;
129     }
130 
SetNavDestinationPathInfo(const std::string & moduleName,const std::string & pagePath)131     void SetNavDestinationPathInfo(const std::string& moduleName, const std::string& pagePath)
132     {
133         navDestinationPathInfo_ = pagePath;
134         navDestinationModuleName_ = moduleName;
135     }
136 
GetNavDestinationPathInfo()137     const std::string& GetNavDestinationPathInfo() const
138     {
139         return navDestinationPathInfo_;
140     }
141 
SetNeedRemoveInPush(bool need)142     void SetNeedRemoveInPush(bool need)
143     {
144         needRemoveInPush_ = need;
145     }
146 
NeedRemoveInPush()147     bool NeedRemoveInPush() const
148     {
149         return needRemoveInPush_;
150     }
151 
SetSystemTransitionType(NavigationSystemTransitionType type)152     void SetSystemTransitionType(NavigationSystemTransitionType type)
153     {
154         systemTransitionType_ = type;
155     }
156 
GetSystemTransitionType()157     NavigationSystemTransitionType GetSystemTransitionType() const
158     {
159         return systemTransitionType_;
160     }
161 
162     std::shared_ptr<AnimationUtils::Animation> BackButtonAnimation(bool isTransitionIn);
163     std::shared_ptr<AnimationUtils::Animation> TitleOpacityAnimation(bool isTransitionOut);
164 
165     void InitSystemTransitionPush(bool transitionIn);
166     void StartSystemTransitionPush(bool transitionIn);
167     void SystemTransitionPushCallback(bool transitionIn);
168     void InitSystemTransitionPop(bool isTransitionIn);
169     void StartSystemTransitionPop(bool transitionIn);
170     bool SystemTransitionPopCallback();
171     void InitDialogTransition(bool isZeroY);
172     bool IsNodeInvisible(const RefPtr<FrameNode>& node) override;
173 
174     void UpdateTextNodeListAsRenderGroup(bool isPopPage, const RefPtr<NavigationTransitionProxy>& proxy);
175     void ReleaseTextNodeList();
176     void CollectTextNodeAsRenderGroup(bool isPopPage);
177 
178     void CleanContent();
179     bool IsNeedContentTransition();
180     bool TransitionContentInValid();
181     bool IsNeedTitleTransition();
182 
SetRecoverable(bool recoverable)183     void SetRecoverable(bool recoverable)
184     {
185         recoverable_ = recoverable;
186     }
187 
SetFromNavrouterAndNoRouteInfo(bool fromNavrouterAndNoRouteInfo)188     void SetFromNavrouterAndNoRouteInfo(bool fromNavrouterAndNoRouteInfo)
189     {
190         fromNavrouterAndNoRouteInfo_ = fromNavrouterAndNoRouteInfo;
191     }
192 
CanRecovery()193     bool CanRecovery() const
194     {
195         return recoverable_ && !fromNavrouterAndNoRouteInfo_;
196     }
197 
SetNeedAppearFromRecovery(bool needAppear)198     void SetNeedAppearFromRecovery(bool needAppear)
199     {
200         needAppearFromRecovery_ = needAppear;
201     }
202 
NeedAppearFromRecovery()203     bool NeedAppearFromRecovery() const
204     {
205         return needAppearFromRecovery_;
206     }
207 private:
208     WeakPtr<CustomNodeBase> customNode_; // nearest parent customNode
209     NavDestinationBackButtonEvent backButtonEvent_;
210     bool isOnAnimation_ = false;
211     int32_t index_ = -1;
212     NavDestinationMode mode_ = NavDestinationMode::STANDARD;
213     bool isCacheNode_ = false;
214     bool isAnimated_ = true;
215     bool canReused_ = true;
216     bool recoverable_ = true;
217     bool fromNavrouterAndNoRouteInfo_ = false;
218     bool needAppearFromRecovery_ = false;
219     std::string navDestinationPathInfo_;
220     std::string navDestinationModuleName_;
221     bool needRemoveInPush_ = false;
222     std::list<WeakPtr<UINode>> textNodeList_;
223     NavigationSystemTransitionType systemTransitionType_ = NavigationSystemTransitionType::DEFAULT;
224 };
225 
226 } // namespace OHOS::Ace::NG
227 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_GROUP_NODE_H
228