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_NAVIGATION_GROUP_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_GROUP_NODE_H 18 19 #include <cstdint> 20 #include <list> 21 22 #include "base/memory/referenced.h" 23 #include "core/animation/page_transition_common.h" 24 #include "core/components_ng/base/frame_node.h" 25 #include "core/components_ng/base/group_node.h" 26 #include "core/components_ng/pattern/navigation/bar_item_node.h" 27 #include "core/components_ng/pattern/navigation/navigation_declaration.h" 28 #include "core/components_ng/pattern/navigation/navigation_stack.h" 29 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h" 30 #include "core/components_ng/pattern/navrouter/navrouter_pattern.h" 31 #include "core/components_ng/property/property.h" 32 33 namespace OHOS::Ace::NG { 34 35 class ACE_EXPORT NavigationGroupNode : public GroupNode { DECLARE_ACE_TYPE(NavigationGroupNode,GroupNode)36 DECLARE_ACE_TYPE(NavigationGroupNode, GroupNode) 37 public: 38 NavigationGroupNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern) 39 : GroupNode(tag, nodeId, pattern) 40 {} 41 ~NavigationGroupNode() override = default; 42 void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override; 43 44 // remain child needs to keep to use pop animation 45 void UpdateNavDestinationNodeWithoutMarkDirty(const RefPtr<UINode>& remainChild); 46 static RefPtr<NavigationGroupNode> GetOrCreateGroupNode( 47 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 48 IsAtomicNode()49 bool IsAtomicNode() const override 50 { 51 return false; 52 } 53 SetNavBarNode(const RefPtr<UINode> & navBarNode)54 void SetNavBarNode(const RefPtr<UINode>& navBarNode) 55 { 56 navBarNode_ = navBarNode; 57 } 58 GetNavBarNode()59 const RefPtr<UINode>& GetNavBarNode() const 60 { 61 return navBarNode_; 62 } 63 SetContentNode(const RefPtr<UINode> & contentNode)64 void SetContentNode(const RefPtr<UINode>& contentNode) 65 { 66 contentNode_ = contentNode; 67 } 68 GetContentNode()69 const RefPtr<UINode>& GetContentNode() const 70 { 71 return contentNode_; 72 } 73 SetDividerNode(const RefPtr<UINode> & dividerNode)74 void SetDividerNode(const RefPtr<UINode>& dividerNode) 75 { 76 dividerNode_ = dividerNode; 77 } 78 GetDividerNode()79 const RefPtr<UINode>& GetDividerNode() const 80 { 81 return dividerNode_; 82 } 83 GetIsModeChange()84 bool GetIsModeChange() const 85 { 86 return isModeChange_; 87 } 88 SetIsModeChange(bool isModeChange)89 void SetIsModeChange(bool isModeChange) 90 { 91 isModeChange_ = isModeChange; 92 } 93 GetNeedSetInvisible()94 bool GetNeedSetInvisible() const 95 { 96 return needSetInvisible_; 97 } 98 SetNeedSetInvisible(bool needSetInvisible)99 void SetNeedSetInvisible(bool needSetInvisible) 100 { 101 needSetInvisible_ = needSetInvisible; 102 } 103 104 bool CheckCanHandleBack(); 105 106 bool HandleBack(const RefPtr<FrameNode>& node, bool isLastChild, bool isOverride); 107 108 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override; 109 static RefPtr<UINode> GetNavDestinationNode(RefPtr<UINode> uiNode); 110 void SetBackButtonEvent(const RefPtr<NavDestinationGroupNode>& navDestination, 111 const RefPtr<NavRouterPattern>& navRouterPattern = nullptr); 112 void AddBackButtonIconToNavDestination(const RefPtr<UINode>& navDestinationNode); 113 void SetBackButtonVisible(const RefPtr<UINode>& navDestinationNode, bool isVisible = true); 114 115 void ExitTransitionWithPop(const RefPtr<FrameNode>& node); 116 void ExitTransitionWithPush(const RefPtr<FrameNode>& node, bool isNavBar = false); 117 void EnterTransitionWithPop(const RefPtr<FrameNode>& node, bool isNavBar = false); 118 void EnterTransitionWithPush(const RefPtr<FrameNode>& node, bool isNavBar = false); 119 void BackButtonAnimation(const RefPtr<FrameNode>& backButtonNode, bool isTransitionIn); 120 void MaskAnimation(const RefPtr<RenderContext>& transitionOutNodeContext); 121 void TitleOpacityAnimationOut(const RefPtr<RenderContext>& transitionOutNodeContext); 122 123 private: 124 RefPtr<UINode> navBarNode_; 125 RefPtr<UINode> contentNode_; 126 RefPtr<UINode> dividerNode_; 127 bool isOnAnimation_ { false }; 128 bool isModeChange_ { false }; 129 bool needSetInvisible_ { false }; 130 }; 131 } // namespace OHOS::Ace::NG 132 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_GROUP_NODE_H 133