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 SetInCurrentStack(bool inStack)131 void SetInCurrentStack(bool inStack) 132 { 133 inCurrentStack_ = inStack; 134 } 135 GetInCurrentStack()136 bool GetInCurrentStack() const 137 { 138 return inCurrentStack_; 139 } 140 SetNavDestinationPathInfo(const std::string & moduleName,const std::string & pagePath)141 void SetNavDestinationPathInfo(const std::string& moduleName, const std::string& pagePath) 142 { 143 navDestinationPathInfo_ = pagePath; 144 navDestinationModuleName_ = moduleName; 145 } 146 GetNavDestinationPathInfo()147 const std::string& GetNavDestinationPathInfo() const 148 { 149 return navDestinationPathInfo_; 150 } 151 152 int32_t GetNavigationNodeId() const; 153 SetNeedRemoveInPush(bool need)154 void SetNeedRemoveInPush(bool need) 155 { 156 needRemoveInPush_ = need; 157 } 158 NeedRemoveInPush()159 bool NeedRemoveInPush() const 160 { 161 return needRemoveInPush_; 162 } 163 SetSystemTransitionType(NavigationSystemTransitionType type)164 void SetSystemTransitionType(NavigationSystemTransitionType type) 165 { 166 systemTransitionType_ = type; 167 if (navDestinationTransitionDelegate_) { 168 TAG_LOGI(AceLogTag::ACE_NAVIGATION, 169 "reset customTransition delegate of navDestination cause by setting systemTransition"); 170 navDestinationTransitionDelegate_ = nullptr; 171 } 172 } 173 GetSystemTransitionType()174 NavigationSystemTransitionType GetSystemTransitionType() const 175 { 176 return systemTransitionType_; 177 } 178 179 std::shared_ptr<AnimationUtils::Animation> BackButtonAnimation(bool isTransitionIn); 180 std::shared_ptr<AnimationUtils::Animation> TitleOpacityAnimation(bool isTransitionOut); 181 182 void InitSystemTransitionPush(bool transitionIn); 183 void StartSystemTransitionPush(bool transitionIn); 184 void SystemTransitionPushCallback(bool transitionIn, const int32_t animationId); 185 void InitSystemTransitionPop(bool isTransitionIn); 186 void StartSystemTransitionPop(bool transitionIn); 187 bool CheckTransitionPop(const int32_t animationId); 188 bool SystemTransitionPopCallback(const int32_t animationId, bool isNeedCleanContent = true); 189 void InitDialogTransition(bool isZeroY); 190 bool IsNodeInvisible(const RefPtr<FrameNode>& node) override; 191 SetRecoverable(bool recoverable)192 void SetRecoverable(bool recoverable) 193 { 194 recoverable_ = recoverable; 195 } 196 SetFromNavrouterAndNoRouteInfo(bool fromNavrouterAndNoRouteInfo)197 void SetFromNavrouterAndNoRouteInfo(bool fromNavrouterAndNoRouteInfo) 198 { 199 fromNavrouterAndNoRouteInfo_ = fromNavrouterAndNoRouteInfo; 200 } 201 CanRecovery()202 bool CanRecovery() const 203 { 204 return recoverable_ && !fromNavrouterAndNoRouteInfo_; 205 } 206 SetNeedAppearFromRecovery(bool needAppear)207 void SetNeedAppearFromRecovery(bool needAppear) 208 { 209 needAppearFromRecovery_ = needAppear; 210 } 211 NeedAppearFromRecovery()212 bool NeedAppearFromRecovery() const 213 { 214 return needAppearFromRecovery_; 215 } 216 217 void UpdateTextNodeListAsRenderGroup(bool isPopPage, const RefPtr<NavigationTransitionProxy>& proxy); 218 void ReleaseTextNodeList(); 219 void CollectTextNodeAsRenderGroup(bool isPopPage); 220 221 void CleanContent(bool cleanDirectly = false, bool allowTransition = false); 222 bool IsNeedContentTransition(); 223 bool TransitionContentInValid(); 224 bool IsNeedTitleTransition(); 225 226 std::string ToDumpString(); 227 SetNeedForceMeasure(bool need)228 void SetNeedForceMeasure(bool need) 229 { 230 needForceMeasure_ = need; 231 } NeedForceMeasure()232 bool NeedForceMeasure() const 233 { 234 return needForceMeasure_; 235 } 236 SetNavDestinationTransitionDelegate(NavDestinationTransitionDelegate && delegate)237 void SetNavDestinationTransitionDelegate(NavDestinationTransitionDelegate&& delegate) 238 { 239 navDestinationTransitionDelegate_ = std::move(delegate); 240 } 241 242 int32_t DoTransition(NavigationOperation operation, bool isEnter); 243 bool HasStandardBefore() const; 244 UpdateUserSetOpacity(float opacity)245 void UpdateUserSetOpacity(float opacity) 246 { 247 userSetOpacity_ = opacity; 248 } 249 250 RefPtr<UINode> GetNavigationNode() override; 251 252 private: 253 int32_t DoCustomTransition(NavigationOperation operation, bool isEnter); 254 int32_t DoSystemTransition(NavigationOperation operation, bool isEnter); 255 int32_t DoSystemFadeTransition(bool isEnter); 256 int32_t DoSystemSlideTransition(NavigationOperation operation, bool isEnter); 257 int32_t DoSystemExplodeTransition(NavigationOperation operation, bool isEnter); 258 int32_t DoSystemEnterExplodeTransition(NavigationOperation operation); 259 int32_t DoSystemExitExplodeTransition(NavigationOperation operation); 260 void DoMaskAnimation(const AnimationOption& option, Color begin, Color end); 261 void StartCustomTransitionAnimation(NavDestinationTransition& transition, 262 bool isEnter, bool& hasResetProperties, int32_t longestAnimationDuration); 263 int32_t MakeUniqueAnimationId(); 264 void ResetCustomTransitionAnimationProperties(); 265 266 std::optional<AnimationOption> GetTransitionAnimationOption(NavigationOperation operation, bool isEnter) const; 267 std::function<void()> BuildTransitionFinishCallback( 268 bool isSystemTransition = true, std::function<void()>&& extraOption = nullptr); 269 270 WeakPtr<CustomNodeBase> customNode_; // nearest parent customNode 271 NavDestinationBackButtonEvent backButtonEvent_; 272 bool isOnAnimation_ = false; 273 int32_t index_ = -1; 274 NavDestinationMode mode_ = NavDestinationMode::STANDARD; 275 bool isCacheNode_ = false; 276 bool isAnimated_ = true; 277 bool canReused_ = true; 278 bool inCurrentStack_ = true; 279 bool recoverable_ = true; 280 bool fromNavrouterAndNoRouteInfo_ = false; 281 bool needAppearFromRecovery_ = false; 282 std::string navDestinationPathInfo_; 283 std::string navDestinationModuleName_; 284 bool needRemoveInPush_ = false; 285 std::list<WeakPtr<UINode>> textNodeList_; 286 NavigationSystemTransitionType systemTransitionType_ = NavigationSystemTransitionType::DEFAULT; 287 bool needForceMeasure_ = false; 288 float userSetOpacity_ = 1.0f; 289 290 NavDestinationTransitionDelegate navDestinationTransitionDelegate_; 291 }; 292 293 } // namespace OHOS::Ace::NG 294 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_GROUP_NODE_H 295