• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_NAVDESTINATION_PATTERN_BASE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVDESTINATION_PATTERN_BASE_H
18 
19 #include <vector>
20 #include <optional>
21 #include <unordered_map>
22 
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "core/components_ng/manager/focus/focus_view.h"
26 #include "core/components_ng/pattern/navigation/nav_bar_layout_property.h"
27 #include "core/components_ng/pattern/navigation/nav_bar_node.h"
28 #include "core/components_ng/pattern/navigation/navdestination_layout_property_base.h"
29 #include "core/components_ng/pattern/navigation/navigation_declaration.h"
30 #include "core/components_ng/pattern/navigation/navigation_options.h"
31 #include "core/components_ng/pattern/navigation/tool_bar_node.h"
32 #include "core/components_ng/pattern/pattern.h"
33 #include "core/pipeline/base/element_register.h"
34 
35 namespace OHOS::Ace::NG {
36 
37 class NavDestinationPatternBase : public Pattern, public FocusView {
38     DECLARE_ACE_TYPE(NavDestinationPatternBase, Pattern, FocusView);
39 public:
40     NavDestinationPatternBase() = default;
41     ~NavDestinationPatternBase() override = default;
42 
IsAtomicNode()43     bool IsAtomicNode() const override
44     {
45         return false;
46     }
47 
CheckCustomAvoidKeyboard()48     bool CheckCustomAvoidKeyboard() const override
49     {
50         return !NearZero(avoidKeyboardOffset_);
51     }
SetAvoidKeyboardOffset(float avoidKeyboardOffset)52     void SetAvoidKeyboardOffset(float avoidKeyboardOffset)
53     {
54         avoidKeyboardOffset_ = avoidKeyboardOffset;
55     }
GetAvoidKeyboardOffset()56     float GetAvoidKeyboardOffset()
57     {
58         return avoidKeyboardOffset_;
59     }
60 
GetFocusPattern()61     FocusPattern GetFocusPattern() const override
62     {
63         return { FocusType::SCOPE, true };
64     }
65 
GetRouteOfFirstScope()66     std::list<int32_t> GetRouteOfFirstScope() override
67     {
68         return {};
69     }
70 
IsEntryFocusView()71     bool IsEntryFocusView() override
72     {
73         return false;
74     }
75 
SetTitleBarMenuItems(const std::vector<BarItem> & menuItems)76     void SetTitleBarMenuItems(const std::vector<BarItem>& menuItems)
77     {
78         titleBarMenuItems_ = menuItems;
79     }
80 
GetTitleBarMenuItems()81     const std::vector<BarItem>& GetTitleBarMenuItems() const
82     {
83         return titleBarMenuItems_;
84     }
85 
SetToolBarMenuItems(const std::vector<BarItem> & menuItems)86     void SetToolBarMenuItems(const std::vector<BarItem>& menuItems)
87     {
88         toolBarMenuItems_ = menuItems;
89     }
90 
GetToolBarMenuItems()91     const std::vector<BarItem>& GetToolBarMenuItems() const
92     {
93         return toolBarMenuItems_;
94     }
95 
GetMenuNodeId()96     int32_t GetMenuNodeId() const
97     {
98         return menuNodeId_.value();
99     }
100 
GetLandscapeMenuNodeId()101     int32_t GetLandscapeMenuNodeId()
102     {
103         if (!landscapeMenuNodeId_.has_value()) {
104             landscapeMenuNodeId_ = ElementRegister::GetInstance()->MakeUniqueId();
105         }
106         return landscapeMenuNodeId_.value();
107     }
108 
SetMenuNodeId(const int32_t menuNodeId)109     void SetMenuNodeId(const int32_t menuNodeId)
110     {
111         menuNodeId_ = menuNodeId;
112     }
113 
SetLandscapeMenuNodeId(const int32_t landscapeMenuNodeId)114     void SetLandscapeMenuNodeId(const int32_t landscapeMenuNodeId)
115     {
116         landscapeMenuNodeId_ = landscapeMenuNodeId;
117     }
118 
HasMenuNodeId()119     bool HasMenuNodeId() const
120     {
121         return menuNodeId_.has_value();
122     }
123 
HasLandscapeMenuNodeId()124     bool HasLandscapeMenuNodeId() const
125     {
126         return landscapeMenuNodeId_.has_value();
127     }
128 
GetToolbarHideStatus()129     bool GetToolbarHideStatus()
130     {
131         return isHideToolbar_;
132     }
133 
GetMaxMenuNum()134     int32_t GetMaxMenuNum() const
135     {
136         return maxMenuNums_;
137     }
138 
SetMaxMenuNum(int32_t maxMenu)139     void SetMaxMenuNum(int32_t maxMenu)
140     {
141         maxMenuNums_ = maxMenu;
142     }
143 
GetTitleBarHeight()144     float GetTitleBarHeight() const
145     {
146         return titleBarHeight_;
147     }
SetTitleBarHeight(float height)148     void SetTitleBarHeight(float height)
149     {
150         titleBarHeight_ = height;
151     }
152 
GetToolBarHeight()153     float GetToolBarHeight() const
154     {
155         return toolBarHeight_;
156     }
SetToolBarHeight(float height)157     void SetToolBarHeight(float height)
158     {
159         toolBarHeight_ = height;
160     }
161 
GetToolBarDividerHeight()162     float GetToolBarDividerHeight() const
163     {
164         return toolBarDividerHeight_;
165     }
SetToolBarDividerHeight(float height)166     void SetToolBarDividerHeight(float height)
167     {
168         toolBarDividerHeight_ = height;
169     }
170 
GetTitleBarAnimationCount()171     int32_t GetTitleBarAnimationCount() const
172     {
173         return titleBarAnimationCount_;
174     }
OnTitleBarAnimationStart()175     void OnTitleBarAnimationStart()
176     {
177         titleBarAnimationCount_++;
178     }
179 
GetToolBarAnimationCount()180     int32_t GetToolBarAnimationCount() const
181     {
182         return toolBarAnimationCount_;
183     }
OnToolBarAnimationStart()184     void OnToolBarAnimationStart()
185     {
186         toolBarAnimationCount_++;
187     }
188 
SetCurrHideToolBar(bool currHideToolBar)189     void SetCurrHideToolBar(bool currHideToolBar)
190     {
191         currHideToolBar_ = currHideToolBar;
192     }
193 
GetCurrHideToolBar()194     std::optional<bool> GetCurrHideToolBar()
195     {
196         return currHideToolBar_;
197     }
198     void HideOrShowToolBarImmediately(const RefPtr<NavDestinationNodeBase>& hostNode, bool hide);
199     void OnToolBarAnimationFinish();
200     void OnTitleBarAnimationFinish();
201     void UpdateToolBarAndDividerProperty(const RefPtr<LayoutProperty>& navBarLayoutProperty, bool hide,
202         const RefPtr<NavDestinationNodeBase>& hostNode);
203     void UpdateToolBarAndDividerTranslateAndOpacity(bool hide, const RefPtr<NavToolbarNode>& toolBarNode,
204         float toolBarHeight, const RefPtr<FrameNode>& toolbarDividerNode, float toolBarDividerHeight);
205     void UpdateTitleBarProperty(const RefPtr<LayoutProperty>& navBarLayoutProperty, bool hide,
206         const RefPtr<NavDestinationNodeBase>& hostNode);
207     void UpdateTitleBarTranslateAndOpacity(bool hide, const RefPtr<TitleBarNode>& titleBarNode, float titleBarHeight);
208     void HideOrShowTitleBarImmediately(const RefPtr<NavDestinationNodeBase>& hostNode, bool hide);
209     void HandleTitleBarAndToolBarAnimation(const RefPtr<NavDestinationNodeBase>& navNodeBase,
210         bool needRunTitleBarAnimation, bool needRunToolBarAnimation);
211     void StartAnimation(bool needRunTitleBarAnimation, bool hideTitle, bool needRunToolBarAnimation, bool hideTool);
212 
IsNeedHideToolBarForNavWidth()213     bool IsNeedHideToolBarForNavWidth() const
214     {
215         return needHideToolBarForNavWidth_;
216     }
217 
SetIsNeedHideToolBarForNavWidth(bool hide)218     void SetIsNeedHideToolBarForNavWidth(bool hide)
219     {
220         needHideToolBarForNavWidth_ = hide;
221     }
222 
223 protected:
224     void AbortBarAnimation();
225     void RemoveAnimation(int32_t id);
226     void BarAnimationPropertyCallback(
227         bool needRunTitleBarAnimation, bool hideTitle, bool needRunToolBarAnimation, bool hideTool);
228     void BarAnimationFinishCallback(bool needRunTitleBarAnimation, bool needRunToolBarAnimation, int32_t animationId);
229     void UpdateLayoutPropertyBeforeAnimation(const RefPtr<NavDestinationNodeBase>& navNodeBase,
230         bool needRunTitleBarAnimation, bool needRunToolBarAnimation, bool hideTitleBar, bool hideToolBar);
231 
232     bool isHideToolbar_ = false;
233     bool isHideTitlebar_ = false;
234     float avoidKeyboardOffset_ = 0.0f;
235     std::vector<BarItem> titleBarMenuItems_;
236     std::vector<BarItem> toolBarMenuItems_;
237     std::optional<int32_t> menuNodeId_;
238     std::optional<int32_t> landscapeMenuNodeId_;
239     int32_t maxMenuNums_ = -1;
240     float titleBarHeight_ = 0.0f;
241     float toolBarHeight_ = 0.0f;
242     float toolBarDividerHeight_ = 0.0f;
243     int32_t titleBarAnimationCount_ = 0;
244     int32_t toolBarAnimationCount_ = 0;
245     std::optional<bool> currHideTitleBar_;
246     std::optional<bool> currHideToolBar_;
247     bool needHideToolBarForNavWidth_ = false;
248     int32_t nextBarAnimationId_ = 0;
249     std::unordered_map<int32_t, std::shared_ptr<AnimationUtils::Animation>> barAnimations_;
250     std::optional<int32_t> preWidth_;
251 };
252 } // namespace OHOS::Ace::NG
253 
254 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVDESTINATION_PATTERN_BASE_H