1 /* 2 * Copyright (c) 2023 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_TOOL_BAR_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TOOL_BAR_PATTERN_H 18 19 #include "base/memory/referenced.h" 20 #include "core/common/container.h" 21 #include "core/components_ng/base/ui_node.h" 22 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" 23 #include "core/components_ng/pattern/navigation/bar_item_node.h" 24 #include "core/components_ng/pattern/navigation/navigation_declaration.h" 25 #include "core/components_ng/pattern/navigation/navigation_options.h" 26 #include "core/components_ng/pattern/navigation/tool_bar_layout_algorithm.h" 27 #include "core/components_ng/pattern/pattern.h" 28 29 namespace OHOS::Ace::NG { 30 class NavToolbarPattern : public LinearLayoutPattern { 31 DECLARE_ACE_TYPE(NavToolbarPattern, LinearLayoutPattern); 32 33 public: NavToolbarPattern()34 NavToolbarPattern() : LinearLayoutPattern(false) {}; 35 ~NavToolbarPattern() override = default; 36 CreateLayoutAlgorithm()37 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 38 { 39 return MakeRefPtr<ToolbarLayoutAlgorithm>(); 40 } 41 IsAtomicNode()42 bool IsAtomicNode() const override 43 { 44 return false; 45 } 46 OnAttachToFrameNode()47 void OnAttachToFrameNode() override 48 { 49 auto host = GetHost(); 50 CHECK_NULL_VOID(host); 51 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { 52 SafeAreaExpandOpts opts = { .type = SAFE_AREA_TYPE_SYSTEM | SAFE_AREA_TYPE_CUTOUT, 53 .edges = SAFE_AREA_EDGE_BOTTOM }; 54 host->GetLayoutProperty()->UpdateSafeAreaExpandOpts(opts); 55 } 56 57 SetDefaultBackgroundColorIfNeeded(host); 58 } 59 60 void OnColorConfigurationUpdate() override; 61 62 bool OnThemeScopeUpdate(int32_t themeScopeId) override; 63 64 void SetToolbarOptions(NavigationToolbarOptions&& opt); 65 void SetToolbarMoreButtonOptions(MoreButtonOptions&& opt); 66 GetToolbarMoreButtonOptions()67 MoreButtonOptions GetToolbarMoreButtonOptions() const 68 { 69 return moreButtonOptions_; 70 } 71 GetDialogNode()72 RefPtr<FrameNode> GetDialogNode() 73 { 74 return dialogNode_; 75 } 76 SetToolBarItemDialogNode(const RefPtr<FrameNode> & dialogNode)77 void SetToolBarItemDialogNode(const RefPtr<FrameNode>& dialogNode) 78 { 79 dialogNode_ = dialogNode; 80 } 81 82 private: 83 void OnModifyDone() override; 84 void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub); 85 void InitDragEvent(const RefPtr<GestureEventHub>& gestureHub); 86 void HandleLongPressEvent(const GestureEvent& info); 87 void HandleLongPressActionEnd(); 88 void ShowDialogWithNode(const RefPtr<BarItemNode>& barItemNode); 89 90 void SetDefaultBackgroundColorIfNeeded(RefPtr<FrameNode>& host); 91 void UpdateBackgroundStyle(); 92 93 NavigationToolbarOptions options_; 94 MoreButtonOptions moreButtonOptions_; 95 RefPtr<FrameNode> dialogNode_; 96 std::optional<int32_t> moveIndex_; 97 }; 98 } // namespace OHOS::Ace::NG 99 100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TOOL_BAR_PATTERN_H 101