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 if (navDestinationTransitionDelegate_) { 156 TAG_LOGI(AceLogTag::ACE_NAVIGATION, 157 "reset customTransition delegate of navDestination cause by setting systemTransition"); 158 navDestinationTransitionDelegate_ = nullptr; 159 } 160 } 161 GetSystemTransitionType()162 NavigationSystemTransitionType GetSystemTransitionType() const 163 { 164 return systemTransitionType_; 165 } 166 167 std::shared_ptr<AnimationUtils::Animation> BackButtonAnimation(bool isTransitionIn); 168 std::shared_ptr<AnimationUtils::Animation> TitleOpacityAnimation(bool isTransitionOut); 169 170 void InitSystemTransitionPush(bool transitionIn); 171 void StartSystemTransitionPush(bool transitionIn); 172 void SystemTransitionPushCallback(bool transitionIn, const int32_t animationId); 173 void InitSystemTransitionPop(bool isTransitionIn); 174 void StartSystemTransitionPop(bool transitionIn); 175 bool SystemTransitionPopCallback(const int32_t animationId); 176 void InitDialogTransition(bool isZeroY); 177 bool IsNodeInvisible(const RefPtr<FrameNode>& node) override; 178 179 void UpdateTextNodeListAsRenderGroup(bool isPopPage, const RefPtr<NavigationTransitionProxy>& proxy); 180 void ReleaseTextNodeList(); 181 void CollectTextNodeAsRenderGroup(bool isPopPage); 182 183 void CleanContent(); 184 bool IsNeedContentTransition(); 185 bool TransitionContentInValid(); 186 bool IsNeedTitleTransition(); 187 SetRecoverable(bool recoverable)188 void SetRecoverable(bool recoverable) 189 { 190 recoverable_ = recoverable; 191 } 192 SetFromNavrouterAndNoRouteInfo(bool fromNavrouterAndNoRouteInfo)193 void SetFromNavrouterAndNoRouteInfo(bool fromNavrouterAndNoRouteInfo) 194 { 195 fromNavrouterAndNoRouteInfo_ = fromNavrouterAndNoRouteInfo; 196 } 197 CanRecovery()198 bool CanRecovery() const 199 { 200 return recoverable_ && !fromNavrouterAndNoRouteInfo_; 201 } 202 SetNeedAppearFromRecovery(bool needAppear)203 void SetNeedAppearFromRecovery(bool needAppear) 204 { 205 needAppearFromRecovery_ = needAppear; 206 } 207 NeedAppearFromRecovery()208 bool NeedAppearFromRecovery() const 209 { 210 return needAppearFromRecovery_; 211 } 212 SetNavDestinationTransitionDelegate(NavDestinationTransitionDelegate && delegate)213 void SetNavDestinationTransitionDelegate(NavDestinationTransitionDelegate&& delegate) 214 { 215 navDestinationTransitionDelegate_ = std::move(delegate); 216 } 217 218 int32_t DoTransition(NavigationOperation operation, bool isEnter); 219 bool HasStandardBefore() const; 220 UpdateUserSetOpacity(float opacity)221 void UpdateUserSetOpacity(float opacity) 222 { 223 userSetOpacity_ = opacity; 224 } 225 226 private: 227 int32_t DoCustomTransition(NavigationOperation operation, bool isEnter); 228 int32_t DoSystemTransition(NavigationOperation operation, bool isEnter); 229 int32_t DoSystemFadeTransition(bool isEnter); 230 int32_t DoSystemSlideTransition(NavigationOperation operation, bool isEnter); 231 int32_t DoSystemExplodeTransition(NavigationOperation operation, bool isEnter); 232 int32_t DoSystemEnterExplodeTransition(NavigationOperation operation); 233 int32_t DoSystemExitExplodeTransition(NavigationOperation operation); 234 void DoMaskAnimation(const AnimationOption& option, Color begin, Color end); 235 void StartCustomTransitionAnimation(NavDestinationTransition& transition, 236 bool isEnter, bool& hasResetProperties, int32_t longestAnimationDuration); 237 int32_t MakeUniqueAnimationId(); 238 void ResetCustomTransitionAnimationProperties(); 239 240 std::optional<AnimationOption> GetTransitionAnimationOption(NavigationOperation operation, bool isEnter) const; 241 std::function<void()> BuildTransitionFinishCallback( 242 bool isSystemTransition = true, std::function<void()>&& extraOption = nullptr); 243 244 WeakPtr<CustomNodeBase> customNode_; // nearest parent customNode 245 NavDestinationBackButtonEvent backButtonEvent_; 246 bool isOnAnimation_ = false; 247 int32_t index_ = -1; 248 NavDestinationMode mode_ = NavDestinationMode::STANDARD; 249 bool isCacheNode_ = false; 250 bool isAnimated_ = true; 251 bool canReused_ = true; 252 bool recoverable_ = true; 253 bool fromNavrouterAndNoRouteInfo_ = false; 254 bool needAppearFromRecovery_ = false; 255 std::string navDestinationPathInfo_; 256 std::string navDestinationModuleName_; 257 bool needRemoveInPush_ = false; 258 std::list<WeakPtr<UINode>> textNodeList_; 259 NavigationSystemTransitionType systemTransitionType_ = NavigationSystemTransitionType::DEFAULT; 260 float userSetOpacity_ = 1.0f; 261 262 NavDestinationTransitionDelegate navDestinationTransitionDelegate_; 263 }; 264 265 } // namespace OHOS::Ace::NG 266 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_GROUP_NODE_H 267