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 "core/components_ng/base/ui_node.h" 21 #include "core/components_ng/pattern/navigation/navigation_event_hub.h" 22 #include "core/components_ng/pattern/navigation/navigation_stack.h" 23 #include "core/components_ng/pattern/navrouter/navdestination_event_hub.h" 24 #include "core/components_ng/pattern/navrouter/navdestination_group_node.h" 25 #include "core/components_ng/pattern/navrouter/navdestination_layout_algorithm.h" 26 #include "core/components_ng/pattern/navrouter/navdestination_layout_property.h" 27 #include "core/components_ng/pattern/pattern.h" 28 #include "core/components_ng/syntax/shallow_builder.h" 29 30 namespace OHOS::Ace::NG { 31 32 class NavDestinationPattern : public Pattern { 33 DECLARE_ACE_TYPE(NavDestinationPattern, Pattern); 34 35 public: NavDestinationPattern(const RefPtr<ShallowBuilder> & shallowBuilder)36 explicit NavDestinationPattern(const RefPtr<ShallowBuilder>& shallowBuilder) : shallowBuilder_(shallowBuilder) {} 37 NavDestinationPattern() = default; 38 ~NavDestinationPattern() override = default; 39 IsAtomicNode()40 bool IsAtomicNode() const override 41 { 42 return false; 43 } 44 CreateLayoutProperty()45 RefPtr<LayoutProperty> CreateLayoutProperty() override 46 { 47 return MakeRefPtr<NavDestinationLayoutProperty>(); 48 } 49 CreateLayoutAlgorithm()50 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 51 { 52 auto layout = MakeRefPtr<NavDestinationLayoutAlgorithm>(); 53 layout->SetIsShown(isOnShow_); 54 return layout; 55 } 56 CreateEventHub()57 RefPtr<EventHub> CreateEventHub() override 58 { 59 return MakeRefPtr<NavDestinationEventHub>(); 60 } 61 62 void OnActive() override; 63 64 void OnModifyDone() override; 65 GetShallowBuilder()66 const RefPtr<ShallowBuilder>& GetShallowBuilder() const 67 { 68 return shallowBuilder_; 69 } 70 SetName(const std::string & name)71 void SetName(const std::string& name) 72 { 73 name_ = name; 74 } 75 GetName()76 const std::string& GetName() 77 { 78 return name_; 79 } 80 SetNavDestinationNode(const RefPtr<UINode> & navDestinationNode)81 void SetNavDestinationNode(const RefPtr<UINode>& navDestinationNode) 82 { 83 navDestinationNode_ = navDestinationNode; 84 } 85 GetNavDestinationNode()86 RefPtr<UINode> GetNavDestinationNode() 87 { 88 return navDestinationNode_.Upgrade(); 89 } 90 GetFocusPattern()91 FocusPattern GetFocusPattern() const override 92 { 93 return { FocusType::SCOPE, true }; 94 } 95 SetIsOnShow(bool isOnShow)96 void SetIsOnShow(bool isOnShow) 97 { 98 isOnShow_ = isOnShow; 99 } 100 GetIsOnShow()101 bool GetIsOnShow() 102 { 103 return isOnShow_; 104 } 105 106 private: 107 RefPtr<ShallowBuilder> shallowBuilder_; 108 std::string name_; 109 WeakPtr<UINode> navDestinationNode_; 110 bool isOnShow_ = false; 111 }; 112 113 } // namespace OHOS::Ace::NG 114 115 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_PATTERN_H 116