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