1 /*
2 * Copyright (c) 2022-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_DECLARATION_NAVIGATION_NAVIGATION_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_NAVIGATION_NAVIGATION_DECLARATION_H
18
19 #include <string>
20
21 #include "base/geometry/dimension.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/declaration/common/declaration.h"
24 #include "core/components/navigation_bar/navigation_bar_theme.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26
27 namespace OHOS::Ace::NG {
28
NavigationGetTheme()29 inline RefPtr<NavigationBarTheme> NavigationGetTheme()
30 {
31 auto pipeline = PipelineBase::GetCurrentContext();
32 CHECK_NULL_RETURN(pipeline, nullptr);
33 return pipeline->GetTheme<NavigationBarTheme>();
34 }
35
36 // TODO:move some items to theme
37 // title bar back button
38 constexpr const char* BACK_BUTTON = "Back";
39 constexpr InternalResource::ResourceId BACK_ICON = InternalResource::ResourceId::IC_BACK;
40 constexpr InternalResource::ResourceId MORE_ICON = InternalResource::ResourceId::IC_MORE;
41 // title bar and tool bar, bar item
42 constexpr float BAR_ITEM_WIDTH = 40.0f;
43 constexpr float BAR_ITEM_HEIGHT = 60.0f;
44 constexpr float BAR_TEXT_FONT_SIZE = 18.0f;
45 // title bar title and subtitle
46 constexpr float TITLE_WIDTH = 100.0f;
47 // single page maximum width
48 constexpr float SINGLE_PAGE_MAXIMUM_WIDTH = 720.0f;
49
50 // title
51 constexpr Dimension MAX_TITLE_FONT_SIZE = 30.0_vp;
52 constexpr Dimension MIN_TITLE_FONT_SIZE = 20.0_vp;
53 constexpr Dimension MIN_ADAPT_TITLE_FONT_SIZE = 14.0_vp;
54 constexpr const char* TITLE_MAIN = "MainOnly";
55 constexpr const char* TITLE_MAIN_WITH_SUB = "MainWithSub";
56
57 // subtitle
58 constexpr Dimension SUBTITLE_FONT_SIZE = 14.0_vp; // ohos_id_text_size_sub_title3
59 constexpr Dimension SUBTITLE_HEIGHT = 26.0_vp;
60 constexpr Dimension MIN_ADAPT_SUBTITLE_FONT_SIZE = 10.0_vp;
61 // back button
62 constexpr Dimension BACK_BUTTON_SIZE = 48.0_vp;
63 constexpr Dimension BACK_BUTTON_ICON_SIZE = 24.0_vp;
64 // title bar
65 constexpr Dimension TITLEBAR_HEIGHT_MINI = 56.0_vp;
66 constexpr Dimension TITLEBAR_HEIGHT_WITH_SUBTITLE = 137.0_vp;
67 constexpr Dimension TITLEBAR_HEIGHT_WITHOUT_SUBTITLE = 112.0_vp;
68 constexpr uint32_t TITLEBAR_MAX_LINES = 2;
69 // toolbar item
70 constexpr Dimension TEXT_FONT_SIZE = 10.0_vp;
71 constexpr Color TEXT_COLOR = Color(0xE6000000);
72 constexpr Color ICON_COLOR = Color(0xE6000000);
73 // toolbar
74 constexpr Dimension ICON_PADDING = 10.0_vp;
75 constexpr Dimension TEXT_TOP_PADDING = 2.0_vp;
76
77 // divider
78 constexpr Dimension DIVIDER_WIDTH = 1.0_px;
79 constexpr Dimension DEFAULT_DIVIDER_START_MARGIN = 0.0_vp;
80 constexpr Dimension DEFAULT_DIVIDER_HOT_ZONE_HORIZONTAL_PADDING = 2.0_vp;
81 constexpr int32_t DIVIDER_HOT_ZONE_HORIZONTAL_PADDING_NUM = 2;
82
83 // navigation content
84 constexpr Dimension SINGLE_LINE_TITLEBAR_HEIGHT = 56.0_vp;
85 constexpr Dimension DOUBLE_LINE_TITLEBAR_HEIGHT = 82.0_vp;
86 constexpr Dimension DEFAULT_MIN_CONTENT_WIDTH = 360.0_vp;
87
88 // navBar
89 constexpr Dimension FULL_SINGLE_LINE_TITLEBAR_HEIGHT = 112.0_vp;
90 constexpr Dimension FULL_DOUBLE_LINE_TITLEBAR_HEIGHT = 138.0_vp;
91 constexpr Dimension NAV_HORIZONTAL_MARGIN_L = 16.0_vp; // ohos_id_elements_margin_horizontal_l
92 constexpr Dimension NAV_HORIZONTAL_MARGIN_M = 8.0_vp; // ohos_id_elements_margin_horizontal_m
93 constexpr Dimension MENU_ITEM_PADDING = 24.0_vp;
94 constexpr Dimension MENU_ITEM_SIZE = 48.0_vp;
95 constexpr Dimension BUTTON_PADDING = 12.0_vp;
96 constexpr Dimension MENU_BUTTON_PADDING = 8.0_vp;
97 constexpr Dimension BACK_BUTTON_SYMBOL_PADDING = 14.0_vp;
98 constexpr Dimension BUTTON_RADIUS_SIZE = 5.0_vp;
99 constexpr Dimension MAX_OVER_DRAG_OFFSET = 180.0_vp;
100 constexpr Dimension DEFAULT_MIN_NAV_BAR_WIDTH = 240.0_vp;
101 constexpr Dimension DEFAULT_MAX_NAV_BAR_WIDTH = 432.0_vp;
102 constexpr Dimension MAX_MENU_CHANGE_SIZE = 600.0_vp;
103 constexpr int8_t MAX_MENU_NUM_SMALL = 3;
104 const int8_t MAX_MENU_NUM_LARGE = 5;
105 constexpr float MAX_NAV_BAR_WIDTH_SCALE = 0.4f;
106
107 // more button
108 constexpr Dimension MORE_BUTTON_CORNER_RADIUS = 8.0_vp;
109
110 // maximum number of toolbar items
111 constexpr uint32_t MAXIMUM_TOOLBAR_ITEMS_IN_BAR = 5;
112 constexpr uint32_t ONE_TOOLBAR_ITEM = 1;
113
114 // navigation page info
115 constexpr char NAVIGATION_MODULE_NAME[] = "moduleName";
116 constexpr char NAVIGATION_PAGE_PATH[] = "pagePath";
117 constexpr char IS_USER_CREATE_STACK[] = "isUserCreateStack";
118
119 // navigation/navdestination Field
120 constexpr const char* NAV_FIELD = "__NavigationField__";
121 constexpr const char* DES_FIELD = "__NavdestinationField__";
122
123 // font scale
124 constexpr float STANDARD_FONT_SCALE = 1.0f;
125
126 enum class NavToolbarItemStatus {
127 NORMAL = 0,
128 DISABLED,
129 ACTIVE,
130 };
131
132 // appbar menu item and toolbar item configuration
133 struct BarItem {
134 std::optional<std::string> text;
135 std::optional<std::string> icon;
136 std::optional<std::function<void(WeakPtr<NG::FrameNode>)>> iconSymbol;
137 std::optional<bool> isEnabled;
138 std::function<void()> action;
139 NavToolbarItemStatus status;
140 std::optional<std::string> activeIcon;
141 std::optional<std::function<void(WeakPtr<NG::FrameNode>)>> activeIconSymbol;
ToStringBarItem142 std::string ToString() const
143 {
144 std::string result;
145 result.append("text: ");
146 result.append(text.value_or("na"));
147 result.append(", icon: ");
148 result.append(icon.value_or("na"));
149 return result;
150 }
151 };
152
153 struct NavigationTitleInfo {
154 bool hasSubTitle;
155 bool hasMainTitle;
156 std::string subtitle;
157 std::string title;
158 };
159
160 enum class ToolbarIconStatus {
161 INITIAL = 0,
162 ACTIVE,
163 };
164
165 enum class TitleBarChildType {
166 TITLE = 0,
167 SUBTITLE,
168 MENU,
169 };
170
171 enum class NavigationTitleMode {
172 FREE = 0,
173 FULL,
174 MINI,
175 };
176
177 enum class NavigationMode {
178 STACK = 0,
179 SPLIT,
180 AUTO,
181 };
182
183 enum class NavBarPosition {
184 START = 0,
185 END,
186 };
187
188 enum class NavDestinationMode {
189 STANDARD = 0,
190 DIALOG,
191 };
192
193 enum class ChildNodeOperation {
194 ADD,
195 // remove case only used for back button
196 REMOVE,
197 REPLACE,
198 NONE
199 };
200
201 enum class BarStyle {
202 STANDARD = 0,
203 STACK,
204 SAFE_AREA_PADDING,
205 };
206
207 enum class TitleBarParentType { NAVBAR, NAV_DESTINATION };
208
209 enum class NavRouteMode {
210 PUSH_WITH_RECREATE = 0,
211 PUSH,
212 REPLACE,
213 };
214
215 enum class NavigationOperation {
216 PUSH = 1,
217 POP,
218 REPLACE,
219 };
220
221 enum NavDestinationLifecycle {
222 ON_WILL_APPEAR,
223 ON_APPEAR,
224 ON_WILL_SHOW,
225 ON_SHOW,
226 ON_WILL_HIDE,
227 ON_HIDE,
228 ON_WILL_DISAPPEAR,
229 ON_DISAPPEAR
230 };
231
232 enum class NavigationSystemTransitionType {
233 NONE = 0,
234 TITLE = 1,
235 CONTENT = 1 << 1,
236 DEFAULT = 1 | (1 << 1),
237 };
238 inline NavigationSystemTransitionType operator& (NavigationSystemTransitionType lv, NavigationSystemTransitionType rv)
239 {
240 return static_cast<NavigationSystemTransitionType>(static_cast<uint32_t>(lv) & static_cast<uint32_t>(rv));
241 }
242 struct NavSafeArea {
243 float top = 0.0f;
244 float bottom = 0.0f;
245 };
246
247 } // namespace OHOS::Ace::NG
248 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_NAVIGATION_NAVIGATION_DECLARATION_H
249