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 auto toolbarLayoutAlgorithm = MakeRefPtr<ToolbarLayoutAlgorithm>(); 40 return toolbarLayoutAlgorithm; 41 } 42 IsAtomicNode()43 bool IsAtomicNode() const override 44 { 45 return false; 46 } 47 OnAttachToFrameNode()48 void OnAttachToFrameNode() override 49 { 50 auto host = GetHost(); 51 CHECK_NULL_VOID(host); 52 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { 53 SafeAreaExpandOpts opts = { .type = SAFE_AREA_TYPE_SYSTEM | SAFE_AREA_TYPE_CUTOUT, 54 .edges = SAFE_AREA_EDGE_BOTTOM }; 55 host->GetLayoutProperty()->UpdateSafeAreaExpandOpts(opts); 56 } 57 58 SetDefaultBackgroundColorIfNeeded(host); 59 } 60 61 void OnColorConfigurationUpdate() override; 62 63 void SetToolbarOptions(NavigationToolbarOptions&& opt); 64 GetDialogNode()65 RefPtr<FrameNode> GetDialogNode() 66 { 67 return dialogNode_; 68 } 69 70 private: 71 void OnModifyDone() override; 72 void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub); 73 void InitDragEvent(const RefPtr<GestureEventHub>& gestureHub); 74 void HandleLongPressEvent(const GestureEvent& info); 75 void HandleLongPressActionEnd(); 76 void ShowDialogWithNode(const RefPtr<BarItemNode>& barItemNode); 77 78 void SetDefaultBackgroundColorIfNeeded(RefPtr<FrameNode>& host); 79 void UpdateBackgroundStyle(RefPtr<FrameNode>& host); 80 81 NavigationToolbarOptions options_; 82 RefPtr<FrameNode> dialogNode_; 83 std::optional<int32_t> moveIndex_; 84 }; 85 } // namespace OHOS::Ace::NG 86 87 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TOOL_BAR_PATTERN_H 88