• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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_NAVIGATION_GROUP_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_GROUP_NODE_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <list>
22 
23 #include "base/memory/referenced.h"
24 #include "core/animation/page_transition_common.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/base/group_node.h"
27 #include "core/components_ng/pattern/navigation/bar_item_node.h"
28 #include "core/components_ng/pattern/navigation/navigation_declaration.h"
29 #include "core/components_ng/pattern/navigation/navigation_stack.h"
30 #include "core/components_ng/pattern/navigation/title_bar_node.h"
31 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h"
32 #include "core/components_ng/pattern/navrouter/navrouter_pattern.h"
33 #include "core/components_ng/property/property.h"
34 
35 namespace OHOS::Ace::NG {
36 class InspectorFilter;
37 
38 class ACE_EXPORT NavigationGroupNode : public GroupNode {
DECLARE_ACE_TYPE(NavigationGroupNode,GroupNode)39     DECLARE_ACE_TYPE(NavigationGroupNode, GroupNode)
40 public:
41     NavigationGroupNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
42         : GroupNode(tag, nodeId, pattern)
43     {}
44 
45     ~NavigationGroupNode() override;
46 
47     using AnimationFinishCallback = std::function<void()>;
48 
49     void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override;
50 
51     // remain child needs to keep to use pop animation
52     void UpdateNavDestinationNodeWithoutMarkDirty(const RefPtr<UINode>& remainChild, bool modeChange = false);
53     static RefPtr<NavigationGroupNode> GetOrCreateGroupNode(
54         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
55 
IsAtomicNode()56     bool IsAtomicNode() const override
57     {
58         return false;
59     }
60 
SetNavBarNode(const RefPtr<UINode> & navBarNode)61     void SetNavBarNode(const RefPtr<UINode>& navBarNode)
62     {
63         navBarNode_ = navBarNode;
64     }
65 
GetNavBarNode()66     const RefPtr<UINode>& GetNavBarNode() const
67     {
68         return navBarNode_;
69     }
70 
SetContentNode(const RefPtr<UINode> & contentNode)71     void SetContentNode(const RefPtr<UINode>& contentNode)
72     {
73         contentNode_ = contentNode;
74     }
75 
GetContentNode()76     const RefPtr<UINode>& GetContentNode() const
77     {
78         return contentNode_;
79     }
80 
SetDividerNode(const RefPtr<UINode> & dividerNode)81     void SetDividerNode(const RefPtr<UINode>& dividerNode)
82     {
83         dividerNode_ = dividerNode;
84     }
85 
GetDividerNode()86     const RefPtr<UINode>& GetDividerNode() const
87     {
88         return dividerNode_;
89     }
90 
GetCurId()91     const std::string& GetCurId() const
92     {
93         return curId_;
94     }
95 
GetIsModeChange()96     bool GetIsModeChange() const
97     {
98         return isModeChange_;
99     }
100 
SetIsModeChange(bool isModeChange)101     void SetIsModeChange(bool isModeChange)
102     {
103         isModeChange_ = isModeChange;
104     }
105 
GetNeedSetInvisible()106     bool GetNeedSetInvisible() const
107     {
108         return needSetInvisible_;
109     }
110 
SetNeedSetInvisible(bool needSetInvisible)111     void SetNeedSetInvisible(bool needSetInvisible)
112     {
113         needSetInvisible_ = needSetInvisible;
114     }
115 
IsOnModeSwitchAnimation()116     bool IsOnModeSwitchAnimation()
117     {
118         return isOnModeSwitchAnimation_;
119     }
120 
SetDoingModeSwitchAnimationFlag(bool isOnAnimation)121     void SetDoingModeSwitchAnimationFlag(bool isOnAnimation)
122     {
123         isOnModeSwitchAnimation_ = isOnAnimation;
124     }
125 
GetPushAnimations()126     std::list<std::shared_ptr<AnimationUtils::Animation>>& GetPushAnimations()
127     {
128         return pushAnimations_;
129     }
130 
GetPopAnimations()131     std::list<std::shared_ptr<AnimationUtils::Animation>>& GetPopAnimations()
132     {
133         return popAnimations_;
134     }
135 
CleanPushAnimations()136     void CleanPushAnimations()
137     {
138         pushAnimations_.clear();
139     }
140 
CleanPopAnimations()141     void CleanPopAnimations()
142     {
143         popAnimations_.clear();
144     }
145 
146     bool CheckCanHandleBack(bool& isEntry);
147 
148     void OnInspectorIdUpdate(const std::string& id) override;
149 
150     bool HandleBack(const RefPtr<FrameNode>& node, bool isLastChild, bool isOverride);
151 
152     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
153     static RefPtr<UINode> GetNavDestinationNode(RefPtr<UINode> uiNode);
154     void SetBackButtonEvent(const RefPtr<NavDestinationGroupNode>& navDestination);
155 
156     void TransitionWithPop(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode, bool isNavBar = false);
157     void TransitionWithPush(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode, bool isNavBar = false);
158 
159     std::shared_ptr<AnimationUtils::Animation> BackButtonAnimation(
160         const RefPtr<FrameNode>& backButtonNode, bool isTransitionIn);
161     std::shared_ptr<AnimationUtils::Animation> MaskAnimation(const RefPtr<RenderContext>& transitionOutNodeContext);
162     std::shared_ptr<AnimationUtils::Animation> TitleOpacityAnimation(
163         const RefPtr<FrameNode>& node, bool isTransitionOut);
164     void TransitionWithReplace(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode, bool isNavBar);
165     void DealNavigationExit(const RefPtr<FrameNode>& preNode, bool isNavBar, bool isAnimated = true);
166     void NotifyPageHide();
167     void UpdateLastStandardIndex();
168 
GetPreLastStandardIndex()169     int32_t GetPreLastStandardIndex() const
170     {
171         return preLastStandardIndex_;
172     }
173 
174     void PreNodeFinishCallback(const RefPtr<FrameNode>& preNode);
175     void CreateAnimationWithDialogPop(const AnimationFinishCallback callback,
176     const std::vector<WeakPtr<FrameNode>> prevNavList, const std::vector<WeakPtr<FrameNode>> curNavList);
177     void CreateAnimationWithDialogPush(const AnimationFinishCallback callback,
178     const std::vector<WeakPtr<FrameNode>> prevNavList, const std::vector<WeakPtr<FrameNode>> curNavList);
179     void TransitionWithDialogPush(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
180         bool isNavBar = false);
181     void TransitionWithDialogPop(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
182         bool isNavBar = false);
183     void StartDialogtransition(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
184         bool isTransitionIn);
185 
186     void InitPopPreList(const RefPtr<FrameNode>& preNode, std::vector<WeakPtr<FrameNode>>& preNavList);
187     void InitPopCurList(const RefPtr<FrameNode>& curNode, std::vector<WeakPtr<FrameNode>>& curNavList,
188         bool isNavbarNeedAnimation);
189     void InitPushPreList(const RefPtr<FrameNode>& preNode, std::vector<WeakPtr<FrameNode>>& prevNavList,
190         bool isNavbarNeedAnimation);
191     void InitPushCurList(const RefPtr<FrameNode>& curNode, std::vector<WeakPtr<FrameNode>>& curNavList);
192 
193     std::vector<WeakPtr<NavDestinationGroupNode>> FindNodesPoped(const RefPtr<FrameNode>& preNode,
194         const RefPtr<FrameNode>& curNode);
195     void DialogTransitionPopAnimation(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
196         AnimationOption option);
197     void DialogTransitionPushAnimation(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
198         AnimationOption option);
199     void InitDialogTransition(const RefPtr<NavDestinationGroupNode>& node, bool isZeroY);
200 
GetLastStandardIndex()201     int32_t GetLastStandardIndex() const
202     {
203         return lastStandardIndex_;
204     }
205     AnimationOption CreateAnimationOption(const RefPtr<Curve>& curve, FillMode mode,
206         int32_t duration, const AnimationFinishCallback& callback);
207     NavigationMode GetNavigationMode();
208 
SetIsOnAnimation(bool isOnAnimation)209     void SetIsOnAnimation(bool isOnAnimation)
210     {
211         isOnAnimation_ = isOnAnimation;
212     }
213     RefPtr<FrameNode> GetTopDestination();
214     void OnDetachFromMainTree(bool recursive, PipelineContext* context = nullptr) override;
215     void OnAttachToMainTree(bool recursive) override;
216 
217     void FireHideNodeChange(NavDestinationLifecycle lifecycle);
218 
ReduceModeSwitchAnimationCnt()219     void ReduceModeSwitchAnimationCnt()
220     {
221         --modeSwitchAnimationCnt_;
222     }
223 
IncreaseModeSwitchAnimationCnt()224     void IncreaseModeSwitchAnimationCnt()
225     {
226         ++modeSwitchAnimationCnt_;
227     }
228 
GetModeSwitchAnimationCnt()229     int32_t GetModeSwitchAnimationCnt()
230     {
231         return modeSwitchAnimationCnt_;
232     }
233 
234     float CheckLanguageDirection();
235 
236     void RemoveDialogDestination(bool isReplace = false);
237     void AddDestinationNode(const RefPtr<UINode>& parent);
GetParentDestinationNode()238     WeakPtr<NavDestinationGroupNode> GetParentDestinationNode() const
239     {
240         return parentDestinationNode_;
241     }
SetNavigationPathInfo(const std::string & moduleName,const std::string & pagePath)242     void SetNavigationPathInfo(const std::string& moduleName, const std::string& pagePath)
243     {
244         navigationPathInfo_ = pagePath;
245         navigationModuleName_ = moduleName;
246     }
247 
GetNavigationPathInfo()248     const std::string& GetNavigationPathInfo() const
249     {
250         return navigationPathInfo_;
251     }
252 
CleanHideNodes()253     void CleanHideNodes()
254     {
255         hideNodes_.clear();
256     }
257 
GetHideNodes()258     std::vector<std::pair<RefPtr<NavDestinationGroupNode>, bool>> GetHideNodes() const
259     {
260         return hideNodes_;
261     }
262 
263 private:
264     bool UpdateNavDestinationVisibility(const RefPtr<NavDestinationGroupNode>& navDestination,
265         const RefPtr<UINode>& remainChild, int32_t index, size_t destinationSize,
266         const RefPtr<UINode>& preLastStandardNode);
267     bool ReorderNavDestination(
268         const std::vector<std::pair<std::string, RefPtr<UINode>>>& navDestinationNodes,
269         RefPtr<FrameNode>& navigationContentNode, int32_t& slot, bool& hasChanged);
270     void RemoveRedundantNavDestination(RefPtr<FrameNode>& navigationContentNode,
271         const RefPtr<UINode>& remainChild, int32_t slot, bool& hasChanged,
272         const RefPtr<NavDestinationGroupNode>& preLastStandardNode);
273     void ReorderAnimatingDestination(RefPtr<FrameNode>& navigationContentNode, RefPtr<UINode>& maxAnimatingDestination,
274         RefPtr<UINode>& remainDestination, RefPtr<UINode>& curTopDestination);
275     bool FindNavigationParent(const std::string& parentName);
276     bool GetCurTitleBarNode(RefPtr<TitleBarNode>& curTitleBarNode, const RefPtr<FrameNode>& curNode,
277         bool isNavBar);
278 
279     void DealRemoveDestination(const RefPtr<NavDestinationGroupNode>& destination);
280 
281     RefPtr<UINode> navBarNode_;
282     RefPtr<UINode> contentNode_;
283     RefPtr<UINode> dividerNode_;
284     WeakPtr<NavDestinationGroupNode> parentDestinationNode_;
285     // dialog hideNodes, if is true, nodes need remove
286     std::vector<std::pair<RefPtr<NavDestinationGroupNode>, bool>> hideNodes_;
287     std::vector<RefPtr<NavDestinationGroupNode>> showNodes_;
288     int32_t lastStandardIndex_ = -1;
289     std::atomic_int32_t modeSwitchAnimationCnt_ = 0;
290     bool isOnAnimation_ { false };
291     bool isModeChange_ { false };
292     bool needSetInvisible_ { false };
293     bool isOnModeSwitchAnimation_ { false };
294     std::string curId_;
295     std::list<std::shared_ptr<AnimationUtils::Animation>> pushAnimations_;
296     std::list<std::shared_ptr<AnimationUtils::Animation>> popAnimations_;
297     std::string navigationPathInfo_;
298     std::string navigationModuleName_;
299     int32_t preLastStandardIndex_ = -1;
300 };
301 } // namespace OHOS::Ace::NG
302 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_GROUP_NODE_H
303