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_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_PATTERN_H 18 19 #include "base/memory/referenced.h" 20 #include "base/utils/utils.h" 21 #include "core/components_ng/base/ui_node.h" 22 #include "core/components_ng/pattern/navigation/navigation_event_hub.h" 23 #include "core/components_ng/pattern/navigation/navigation_stack.h" 24 #include "core/components_ng/pattern/navrouter/navdestination_context.h" 25 #include "core/components_ng/pattern/navrouter/navdestination_event_hub.h" 26 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h" 27 #include "core/components_ng/pattern/navrouter/navdestination_layout_algorithm.h" 28 #include "core/components_ng/pattern/navrouter/navdestination_layout_property.h" 29 #include "core/components_ng/pattern/pattern.h" 30 #include "core/components_ng/syntax/shallow_builder.h" 31 32 namespace OHOS::Ace::NG { 33 34 class NavDestinationPattern : public Pattern { 35 DECLARE_ACE_TYPE(NavDestinationPattern, Pattern); 36 37 public: NavDestinationPattern(const RefPtr<ShallowBuilder> & shallowBuilder)38 explicit NavDestinationPattern(const RefPtr<ShallowBuilder>& shallowBuilder) : shallowBuilder_(shallowBuilder) {} 39 NavDestinationPattern() = default; 40 ~NavDestinationPattern() override; 41 IsAtomicNode()42 bool IsAtomicNode() const override 43 { 44 return false; 45 } 46 CreateLayoutProperty()47 RefPtr<LayoutProperty> CreateLayoutProperty() override 48 { 49 return MakeRefPtr<NavDestinationLayoutProperty>(); 50 } 51 CreateLayoutAlgorithm()52 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 53 { 54 auto layout = MakeRefPtr<NavDestinationLayoutAlgorithm>(); 55 layout->SetIsShown(isOnShow_); 56 return layout; 57 } 58 CreateEventHub()59 RefPtr<EventHub> CreateEventHub() override 60 { 61 return MakeRefPtr<NavDestinationEventHub>(); 62 } 63 64 void OnActive() override; 65 66 void OnModifyDone() override; 67 GetShallowBuilder()68 const RefPtr<ShallowBuilder>& GetShallowBuilder() const 69 { 70 return shallowBuilder_; 71 } 72 SetName(const std::string & name)73 void SetName(const std::string& name) 74 { 75 name_ = name; 76 } 77 GetName()78 const std::string& GetName() 79 { 80 return name_; 81 } 82 SetNavPathInfo(const RefPtr<NavPathInfo> & pathInfo)83 void SetNavPathInfo(const RefPtr<NavPathInfo>& pathInfo) 84 { 85 if (navDestinationContext_) { 86 navDestinationContext_->SetNavPathInfo(pathInfo); 87 } 88 } 89 GetNavPathInfo()90 RefPtr<NavPathInfo> GetNavPathInfo() const 91 { 92 return navDestinationContext_ ? navDestinationContext_->GetNavPathInfo() : nullptr; 93 } 94 SetNavigationStack(const WeakPtr<NavigationStack> & stack)95 void SetNavigationStack(const WeakPtr<NavigationStack>& stack) 96 { 97 if (navDestinationContext_) { 98 navDestinationContext_->SetNavigationStack(stack); 99 } 100 } 101 GetNavigationStack()102 WeakPtr<NavigationStack> GetNavigationStack() const 103 { 104 return navDestinationContext_ ? navDestinationContext_->GetNavigationStack() : nullptr; 105 } 106 SetNavDestinationContext(const RefPtr<NavDestinationContext> & context)107 void SetNavDestinationContext(const RefPtr<NavDestinationContext>& context) 108 { 109 navDestinationContext_ = context; 110 } 111 GetNavDestinationContext()112 RefPtr<NavDestinationContext> GetNavDestinationContext() const 113 { 114 return navDestinationContext_; 115 } 116 SetCustomNode(const RefPtr<UINode> & customNode)117 void SetCustomNode(const RefPtr<UINode>& customNode) 118 { 119 customNode_ = customNode; 120 } 121 GetCustomNode()122 RefPtr<UINode> GetCustomNode() 123 { 124 return customNode_; 125 } 126 GetFocusPattern()127 FocusPattern GetFocusPattern() const override 128 { 129 return { FocusType::SCOPE, true }; 130 } 131 SetIsOnShow(bool isOnShow)132 void SetIsOnShow(bool isOnShow) 133 { 134 isOnShow_ = isOnShow; 135 } 136 GetIsOnShow()137 bool GetIsOnShow() 138 { 139 return isOnShow_; 140 } 141 142 bool GetBackButtonState(); 143 GetNavigationNode()144 RefPtr<UINode> GetNavigationNode() 145 { 146 return navigationNode_.Upgrade(); 147 } 148 149 void OnAttachToMainTree() override; 150 151 void DumpInfo() override; 152 153 private: 154 void UpdateNameIfNeeded(RefPtr<NavDestinationGroupNode>& hostNode); 155 void UpdateBackgroundColorIfNeeded(RefPtr<NavDestinationGroupNode>& hostNode); 156 void UpdateTitlebarVisibility(RefPtr<NavDestinationGroupNode>& hostNode); 157 158 RefPtr<ShallowBuilder> shallowBuilder_; 159 std::string name_; 160 RefPtr<NavDestinationContext> navDestinationContext_; 161 RefPtr<UINode> customNode_; 162 WeakPtr<UINode> navigationNode_; 163 bool isOnShow_ = false; 164 void OnAttachToFrameNode() override; 165 }; 166 167 } // namespace OHOS::Ace::NG 168 169 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_PATTERN_H 170