• 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 struct TransitionUnitInfo {
39     const RefPtr<FrameNode>& transitionNode;
40     bool isUseCustomTransition = false;
41     int32_t animationId = -1;
42 
TransitionUnitInfoTransitionUnitInfo43     TransitionUnitInfo(const RefPtr<FrameNode>& node, bool isUseCustomTransition, int32_t animationId)
44         : transitionNode(node), isUseCustomTransition(isUseCustomTransition), animationId(animationId)
45     {}
46 };
47 
48 class ACE_FORCE_EXPORT NavigationGroupNode : public GroupNode {
DECLARE_ACE_TYPE(NavigationGroupNode,GroupNode)49     DECLARE_ACE_TYPE(NavigationGroupNode, GroupNode)
50 public:
51     NavigationGroupNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
52         : GroupNode(tag, nodeId, pattern)
53     {}
54 
55     ~NavigationGroupNode() override;
56 
57     using AnimationFinishCallback = std::function<void()>;
58 
59     void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override;
60 
61     // remain child needs to keep to use pop animation
62     void UpdateNavDestinationNodeWithoutMarkDirty(const RefPtr<UINode>& remainChild, bool modeChange = false);
63     static RefPtr<NavigationGroupNode> GetOrCreateGroupNode(
64         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
65 
IsAtomicNode()66     bool IsAtomicNode() const override
67     {
68         return false;
69     }
70 
SetNavBarNode(const RefPtr<UINode> & navBarNode)71     void SetNavBarNode(const RefPtr<UINode>& navBarNode)
72     {
73         navBarNode_ = navBarNode;
74     }
75 
GetNavBarNode()76     const RefPtr<UINode>& GetNavBarNode() const
77     {
78         return navBarNode_;
79     }
80 
SetContentNode(const RefPtr<UINode> & contentNode)81     void SetContentNode(const RefPtr<UINode>& contentNode)
82     {
83         contentNode_ = contentNode;
84     }
85 
GetContentNode()86     const RefPtr<UINode>& GetContentNode() const
87     {
88         return contentNode_;
89     }
90 
SetDividerNode(const RefPtr<UINode> & dividerNode)91     void SetDividerNode(const RefPtr<UINode>& dividerNode)
92     {
93         dividerNode_ = dividerNode;
94     }
95 
GetDividerNode()96     const RefPtr<UINode>& GetDividerNode() const
97     {
98         return dividerNode_;
99     }
100 
GetCurId()101     const std::string& GetCurId() const
102     {
103         return curId_;
104     }
105 
GetIsModeChange()106     bool GetIsModeChange() const
107     {
108         return isModeChange_;
109     }
110 
SetIsModeChange(bool isModeChange)111     void SetIsModeChange(bool isModeChange)
112     {
113         isModeChange_ = isModeChange;
114     }
115 
GetNeedSetInvisible()116     bool GetNeedSetInvisible() const
117     {
118         return needSetInvisible_;
119     }
120 
SetNeedSetInvisible(bool needSetInvisible)121     void SetNeedSetInvisible(bool needSetInvisible)
122     {
123         needSetInvisible_ = needSetInvisible;
124     }
125 
IsOnModeSwitchAnimation()126     bool IsOnModeSwitchAnimation()
127     {
128         return isOnModeSwitchAnimation_;
129     }
130 
SetDoingModeSwitchAnimationFlag(bool isOnAnimation)131     void SetDoingModeSwitchAnimationFlag(bool isOnAnimation)
132     {
133         isOnModeSwitchAnimation_ = isOnAnimation;
134     }
135 
GetPushAnimations()136     std::list<std::shared_ptr<AnimationUtils::Animation>>& GetPushAnimations()
137     {
138         return pushAnimations_;
139     }
140 
GetPopAnimations()141     std::list<std::shared_ptr<AnimationUtils::Animation>>& GetPopAnimations()
142     {
143         return popAnimations_;
144     }
145 
CleanPushAnimations()146     void CleanPushAnimations()
147     {
148         pushAnimations_.clear();
149     }
150 
CleanPopAnimations()151     void CleanPopAnimations()
152     {
153         popAnimations_.clear();
154     }
155 
156     bool CheckCanHandleBack(bool& isEntry);
157 
158     void CheckIsNeedForceExitWindow(bool result);
159 
160     void OnInspectorIdUpdate(const std::string& id) override;
161 
162     bool HandleBack(const RefPtr<FrameNode>& node, bool isLastChild, bool isOverride);
163 
164     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
165     static RefPtr<UINode> GetNavDestinationNode(RefPtr<UINode> uiNode);
166     void SetBackButtonEvent(const RefPtr<NavDestinationGroupNode>& navDestination);
167 
168     void ConfigureNavigationWithAnimation(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode);
169     void ResetTransitionAnimationNodeState(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode);
170     RefPtr<NavigationManager> FetchNavigationManager();
171     void TransitionWithPop(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode, bool isNavBar = false);
172     void TransitionWithPush(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode, bool isNavBar = false);
173     virtual void CreateAnimationWithPop(const TransitionUnitInfo& preInfo, const TransitionUnitInfo& curInfo,
174         const AnimationFinishCallback finishCallback, bool isNavBar = false);
175     virtual void CreateAnimationWithPush(const TransitionUnitInfo& preInfo, const TransitionUnitInfo& curInfo,
176         const AnimationFinishCallback finishCallback, bool isNavBar = false);
177     virtual void ResetSystemAnimationProperties(const RefPtr<FrameNode>& navDestinationNode);
178 
179     std::shared_ptr<AnimationUtils::Animation> BackButtonAnimation(
180         const RefPtr<FrameNode>& backButtonNode, bool isTransitionIn);
181     std::shared_ptr<AnimationUtils::Animation> MaskAnimation(const RefPtr<FrameNode>& curNode, bool isTransitionIn);
182     std::shared_ptr<AnimationUtils::Animation> TitleOpacityAnimation(
183         const RefPtr<FrameNode>& node, bool isTransitionOut);
184     void TransitionWithReplace(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode, bool isNavBar);
185     void DealNavigationExit(const RefPtr<FrameNode>& preNode, bool isNavBar, bool isAnimated = true);
186     void NotifyPageHide();
187     void UpdateLastStandardIndex();
188 
GetPreLastStandardIndex()189     int32_t GetPreLastStandardIndex() const
190     {
191         return preLastStandardIndex_;
192     }
193 
194     void PreNodeFinishCallback(const RefPtr<FrameNode>& preNode);
195     void CreateAnimationWithDialogPop(const AnimationFinishCallback callback,
196     const std::vector<WeakPtr<FrameNode>> prevNavList, const std::vector<WeakPtr<FrameNode>> curNavList);
197     void CreateAnimationWithDialogPush(const AnimationFinishCallback callback,
198     const std::vector<WeakPtr<FrameNode>> prevNavList, const std::vector<WeakPtr<FrameNode>> curNavList);
199     void TransitionWithDialogPush(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
200         bool isNavBar = false);
201     void TransitionWithDialogPop(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
202         bool isNavBar = false);
203     void StartDialogtransition(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
204         bool isTransitionIn);
205 
206     void InitPopPreList(const RefPtr<FrameNode>& preNode, std::vector<WeakPtr<FrameNode>>& preNavList);
207     void InitPopCurList(const RefPtr<FrameNode>& curNode, std::vector<WeakPtr<FrameNode>>& curNavList,
208         bool isNavbarNeedAnimation);
209     void InitPushPreList(const RefPtr<FrameNode>& preNode, std::vector<WeakPtr<FrameNode>>& prevNavList,
210         bool isNavbarNeedAnimation);
211     void InitPushCurList(const RefPtr<FrameNode>& curNode, std::vector<WeakPtr<FrameNode>>& curNavList);
212 
213     std::vector<WeakPtr<NavDestinationGroupNode>> FindNodesPoped(const RefPtr<FrameNode>& preNode,
214         const RefPtr<FrameNode>& curNode);
215     void DialogTransitionPopAnimation(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
216         AnimationOption option);
217     void DialogTransitionPushAnimation(const RefPtr<FrameNode>& preNode, const RefPtr<FrameNode>& curNode,
218         AnimationOption option);
219 
GetLastStandardIndex()220     int32_t GetLastStandardIndex() const
221     {
222         return lastStandardIndex_;
223     }
224 
225     AnimationOption CreateAnimationOption(const RefPtr<Curve>& curve, FillMode mode,
226         int32_t duration, const NavigationGroupNode::AnimationFinishCallback& callback);
227 
228     NavigationMode GetNavigationMode();
229 
SetIsOnAnimation(bool isOnAnimation)230     void SetIsOnAnimation(bool isOnAnimation)
231     {
232         isOnAnimation_ = isOnAnimation;
233     }
234     RefPtr<FrameNode> GetTopDestination();
235     void OnDetachFromMainTree(bool recursive, PipelineContext* context = nullptr) override;
236     void OnAttachToMainTree(bool recursive) override;
237 
238     void FireHideNodeChange(NavDestinationLifecycle lifecycle);
239 
ReduceModeSwitchAnimationCnt()240     void ReduceModeSwitchAnimationCnt()
241     {
242         --modeSwitchAnimationCnt_;
243     }
244 
IncreaseModeSwitchAnimationCnt()245     void IncreaseModeSwitchAnimationCnt()
246     {
247         ++modeSwitchAnimationCnt_;
248     }
249 
GetModeSwitchAnimationCnt()250     int32_t GetModeSwitchAnimationCnt()
251     {
252         return modeSwitchAnimationCnt_;
253     }
254 
255     float CheckLanguageDirection();
256 
257     void RemoveDialogDestination(bool isReplace = false, bool isTriggerByInteractiveCancel = false);
258     void AddDestinationNode(const RefPtr<UINode>& parent);
GetParentDestinationNode()259     WeakPtr<NavDestinationGroupNode> GetParentDestinationNode() const
260     {
261         return parentDestinationNode_;
262     }
SetNavigationPathInfo(const std::string & moduleName,const std::string & pagePath)263     void SetNavigationPathInfo(const std::string& moduleName, const std::string& pagePath)
264     {
265         navigationPathInfo_ = pagePath;
266         navigationModuleName_ = moduleName;
267     }
268 
GetNavigationPathInfo()269     const std::string& GetNavigationPathInfo() const
270     {
271         return navigationPathInfo_;
272     }
273 
CleanHideNodes()274     void CleanHideNodes()
275     {
276         hideNodes_.clear();
277     }
278 
GetHideNodes()279     std::vector<std::pair<RefPtr<NavDestinationGroupNode>, bool>> GetHideNodes() const
280     {
281         return hideNodes_;
282     }
283 
SetRecoverable(bool recoverable)284     void SetRecoverable(bool recoverable)
285     {
286         recoverable_ = recoverable;
287     }
288 
CanRecovery()289     bool CanRecovery() const
290     {
291         return recoverable_ && !curId_.empty();
292     }
293 
SetDragBarNode(const RefPtr<UINode> & dragNode)294     void SetDragBarNode(const RefPtr<UINode>& dragNode)
295     {
296         dragBarNode_ = dragNode;
297     }
298 
GetDragBarNode()299     const RefPtr<UINode>& GetDragBarNode() const
300     {
301         return dragBarNode_;
302     }
303 
MakeUniqueAnimationId()304     int32_t MakeUniqueAnimationId()
305     {
306         return ++animationId_;
307     }
308 
GetAnimationId()309     int32_t GetAnimationId() const
310     {
311         return animationId_;
312     }
313 
314     bool CheckAnimationIdValid(const RefPtr<FrameNode>& curNode, const int32_t animationId);
315 
316     std::string ToDumpString();
317 protected:
318     std::list<std::shared_ptr<AnimationUtils::Animation>> pushAnimations_;
319     std::list<std::shared_ptr<AnimationUtils::Animation>> popAnimations_;
320 private:
321     bool UpdateNavDestinationVisibility(const RefPtr<NavDestinationGroupNode>& navDestination,
322         const RefPtr<UINode>& remainChild, int32_t index, size_t destinationSize,
323         const RefPtr<UINode>& preLastStandardNode);
324     bool ReorderNavDestination(
325         const std::vector<std::pair<std::string, RefPtr<UINode>>>& navDestinationNodes,
326         RefPtr<FrameNode>& navigationContentNode, int32_t& slot, bool& hasChanged);
327     void RemoveRedundantNavDestination(RefPtr<FrameNode>& navigationContentNode,
328         const RefPtr<UINode>& remainChild, int32_t slot, bool& hasChanged,
329         const RefPtr<NavDestinationGroupNode>& preLastStandardNode);
330     void ReorderAnimatingDestination(RefPtr<FrameNode>& navigationContentNode, RefPtr<UINode>& maxAnimatingDestination,
331         RefPtr<UINode>& remainDestination, RefPtr<UINode>& curTopDestination);
332     bool FindNavigationParent(const std::string& parentName);
333     void DealRemoveDestination(const RefPtr<NavDestinationGroupNode>& destination);
334     RefPtr<FrameNode> TransitionAnimationIsValid(
335         const RefPtr<FrameNode>& node, bool isNavBar, bool isUseNavDestCustomTransition);
336     bool CheckNeedUpdateParentNode(const RefPtr<UINode>& node);
337     void RemoveJsChildImmediately(const RefPtr<FrameNode>& preNode, bool preUseCustomTransition,
338         int32_t preAnimationId);
339 
340     RefPtr<UINode> navBarNode_;
341     RefPtr<UINode> contentNode_;
342     RefPtr<UINode> dividerNode_;
343     RefPtr<UINode> dragBarNode_;
344     WeakPtr<NavDestinationGroupNode> parentDestinationNode_;
345     // dialog hideNodes, if is true, nodes need remove
346     std::vector<std::pair<RefPtr<NavDestinationGroupNode>, bool>> hideNodes_;
347     std::vector<RefPtr<NavDestinationGroupNode>> showNodes_;
348     int32_t lastStandardIndex_ = -1;
349     std::atomic_int32_t animationId_ = 0;
350     std::atomic_int32_t modeSwitchAnimationCnt_ = 0;
351     bool isOnAnimation_ { false };
352     bool isModeChange_ { false };
353     bool needSetInvisible_ { false };
354     bool isOnModeSwitchAnimation_ { false };
355     bool recoverable_ { false };
356     std::string curId_;
357     std::string navigationPathInfo_;
358     std::string navigationModuleName_;
359     int32_t preLastStandardIndex_ = -1;
360 };
361 } // namespace OHOS::Ace::NG
362 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_GROUP_NODE_H
363