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 #include "bridge/declarative_frontend/jsview/models/navigation_model_impl.h"
17
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19
20 namespace OHOS::Ace::Framework {
Create(bool useHomeDestination)21 void NavigationModelImpl::Create(bool useHomeDestination)
22 {
23 auto navigationContainer = AceType::MakeRefPtr<NavigationContainerComponent>();
24 ViewStackProcessor::GetInstance()->Push(navigationContainer);
25 }
26
SetTitle(const std::string & title,bool hasSubTitle)27 void NavigationModelImpl::SetTitle(const std::string& title, bool hasSubTitle)
28 {
29 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
30 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
31 CHECK_NULL_VOID(navigationContainer);
32 navigationContainer->GetDeclaration()->title = title;
33 }
34
SetCustomTitle(const RefPtr<AceType> & customTitle)35 void NavigationModelImpl::SetCustomTitle(const RefPtr<AceType>& customTitle)
36 {
37 auto customTile = AceType::DynamicCast<Component>(customTitle);
38 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
39 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
40 if (!navigationContainer) {
41 LOGI("component is not navigationContainer.");
42 return;
43 }
44 #if defined(PREVIEW)
45 auto composedComponent =
46 ViewStackProcessor::GetInstance()->CreateInspectorWrapper("NavigationTitle");
47 composedComponent->SetChild(customTile);
48 navigationContainer->GetDeclaration()->customTitle = composedComponent;
49 #else
50 navigationContainer->GetDeclaration()->customTitle = customTile;
51 #endif
52 }
53
SetTitleHeight(const Dimension & height,bool isValid)54 void NavigationModelImpl::SetTitleHeight(const Dimension& height, bool isValid)
55 {
56 return;
57 }
58
SetTitleMode(NG::NavigationTitleMode mode)59 void NavigationModelImpl::SetTitleMode(NG::NavigationTitleMode mode)
60 {
61 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
62 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
63 if (!navigationContainer) {
64 LOGI("component is not navigationContainer.");
65 return;
66 }
67 navigationContainer->GetDeclaration()->titleMode = static_cast<NavigationTitleMode>(mode);
68 }
69
SetSubtitle(const std::string & subtitle)70 void NavigationModelImpl::SetSubtitle(const std::string& subtitle)
71 {
72 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
73 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
74 if (!navigationContainer) {
75 LOGI("component is not navigationContainer.");
76 return;
77 }
78 navigationContainer->GetDeclaration()->subTitle = subtitle;
79 }
80
SetEnableModeChangeAnimation(bool isEnable)81 void NavigationModelImpl::SetEnableModeChangeAnimation(bool isEnable)
82 {
83 return;
84 }
85
SetHideTitleBar(bool hideTitleBar,bool animated)86 void NavigationModelImpl::SetHideTitleBar(bool hideTitleBar, bool animated)
87 {
88 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
89 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
90 if (!navigationContainer) {
91 LOGI("component is not navigationContainer.");
92 return;
93 }
94 auto declaration = navigationContainer->GetDeclaration();
95 declaration->hideBar = hideTitleBar;
96 declaration->animationOption = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
97 }
98
SetHideNavBar(bool hideNavBar)99 void NavigationModelImpl::SetHideNavBar(bool hideNavBar)
100 {
101 return;
102 }
103
SetBackButtonIcon(const std::function<void (WeakPtr<NG::FrameNode>)> & symbolApply,const std::string & src,const NG::ImageOption & imageOption,RefPtr<PixelMap> & pixMap,const std::vector<std::string> & nameList,bool userDefinedAccessibilityText,const std::string & backButtonAccessibilityText)104 void NavigationModelImpl::SetBackButtonIcon(const std::function<void(WeakPtr<NG::FrameNode>)>& symbolApply,
105 const std::string& src, const NG::ImageOption& imageOption, RefPtr<PixelMap>& pixMap,
106 const std::vector<std::string>& nameList, bool userDefinedAccessibilityText,
107 const std::string& backButtonAccessibilityText)
108 {
109 return;
110 }
111
SetBackButtonIcon(const std::function<void (WeakPtr<NG::FrameNode>)> & symbolApply,const RefPtr<ResourceObject> & resObj,const NG::ImageOption & imageOption,RefPtr<PixelMap> & pixMap,const std::vector<std::string> & nameList,bool userDefinedAccessibilityText,const std::string & backButtonAccessibilityText)112 void NavigationModelImpl::SetBackButtonIcon(const std::function<void(WeakPtr<NG::FrameNode>)>& symbolApply,
113 const RefPtr<ResourceObject>& resObj, const NG::ImageOption& imageOption, RefPtr<PixelMap>& pixMap,
114 const std::vector<std::string>& nameList, bool userDefinedAccessibilityText,
115 const std::string& backButtonAccessibilityText)
116 {
117 return;
118 }
119
SetBackButtonIconTextRes(const std::function<void (WeakPtr<NG::FrameNode>)> & symbolApply,const std::string & src,const NG::ImageOption & imageOption,RefPtr<PixelMap> & pixMap,const std::vector<std::string> & nameList,bool userDefinedAccessibilityText,const RefPtr<ResourceObject> & resObj)120 void NavigationModelImpl::SetBackButtonIconTextRes(const std::function<void(WeakPtr<NG::FrameNode>)>& symbolApply,
121 const std::string& src, const NG::ImageOption& imageOption, RefPtr<PixelMap>& pixMap,
122 const std::vector<std::string>& nameList, bool userDefinedAccessibilityText, const RefPtr<ResourceObject>& resObj)
123 {
124 return;
125 }
126
SetBackButtonIconSrcAndTextRes(const std::function<void (WeakPtr<NG::FrameNode>)> & symbolApply,const RefPtr<ResourceObject> & backButtonResObj,const NG::ImageOption & imageOption,RefPtr<PixelMap> & pixMap,const std::vector<std::string> & nameList,bool userDefinedAccessibilityText,const RefPtr<ResourceObject> & backButtonTextResObj)127 void NavigationModelImpl::SetBackButtonIconSrcAndTextRes(
128 const std::function<void(WeakPtr<NG::FrameNode>)>& symbolApply,
129 const RefPtr<ResourceObject>& backButtonResObj, const NG::ImageOption& imageOption, RefPtr<PixelMap>& pixMap,
130 const std::vector<std::string>& nameList, bool userDefinedAccessibilityText,
131 const RefPtr<ResourceObject>& backButtonTextResObj)
132 {
133 return;
134 }
135
UpdateBackButtonIcon(const std::vector<std::string> & nameList,NG::FrameNode * frameNode,const RefPtr<ResourceObject> & backButtonIconResObj)136 void NavigationModelImpl::UpdateBackButtonIcon(const std::vector<std::string>& nameList,
137 NG::FrameNode* frameNode, const RefPtr<ResourceObject>& backButtonIconResObj)
138 {
139 return;
140 }
141
UpdateBackButtonIconText(bool userDefinedAccessibilityText,const RefPtr<NG::TitleBarNode> & titleBarNode,const RefPtr<ResourceObject> & backButtonTextResObj)142 void NavigationModelImpl::UpdateBackButtonIconText(bool userDefinedAccessibilityText,
143 const RefPtr<NG::TitleBarNode>& titleBarNode, const RefPtr<ResourceObject>& backButtonTextResObj)
144 {
145 return;
146 }
147
SetHideBackButton(bool hideBackButton)148 void NavigationModelImpl::SetHideBackButton(bool hideBackButton)
149 {
150 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
151 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
152 if (!navigationContainer) {
153 LOGI("component is not navigationContainer.");
154 return;
155 }
156 navigationContainer->GetDeclaration()->hideBarBackButton = hideBackButton;
157 }
158
SetHideToolBar(bool hideToolBar,bool animated)159 void NavigationModelImpl::SetHideToolBar(bool hideToolBar, bool animated)
160 {
161 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
162 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
163 if (!navigationContainer) {
164 LOGI("component is not navigationContainer.");
165 return;
166 }
167 auto declaration = navigationContainer->GetDeclaration();
168 declaration->hideToolbar = hideToolBar;
169 declaration->animationOption = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
170 }
171
SetCustomToolBar(const RefPtr<AceType> & node)172 void NavigationModelImpl::SetCustomToolBar(const RefPtr<AceType>& node)
173 {
174 auto customToolBar = AceType::DynamicCast<Component>(node);
175 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
176 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
177 if (!navigationContainer) {
178 LOGI("component is not navigationContainer.");
179 return;
180 }
181 navigationContainer->GetDeclaration()->toolBarBuilder = customToolBar;
182 }
183
NeedSetItems()184 bool NavigationModelImpl::NeedSetItems()
185 {
186 return false;
187 }
188
SetToolBarItems(std::vector<NG::BarItem> && toolBarItems)189 void NavigationModelImpl::SetToolBarItems(std::vector<NG::BarItem>&& toolBarItems)
190 {
191 return;
192 }
193
SetToolbarConfiguration(std::vector<NG::BarItem> && toolBarItems)194 void NavigationModelImpl::SetToolbarConfiguration(std::vector<NG::BarItem>&& toolBarItems) {}
195
GetToolBarItems(std::list<RefPtr<AceType>> & items)196 void NavigationModelImpl::GetToolBarItems(std::list<RefPtr<AceType>>& items)
197 {
198 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
199 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
200 CHECK_NULL_VOID(navigationContainer);
201 auto toolbarItems = navigationContainer->GetDeclaration()->toolbarItems;
202 items.clear();
203 for (auto item : toolbarItems) {
204 items.push_back(item);
205 }
206 }
207
SetMenuItems(std::vector<NG::BarItem> && menuItems)208 void NavigationModelImpl::SetMenuItems(std::vector<NG::BarItem>&& menuItems)
209 {
210 return;
211 }
212
GetMenuItems(std::list<RefPtr<AceType>> & items)213 void NavigationModelImpl::GetMenuItems(std::list<RefPtr<AceType>>& items)
214 {
215 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
216 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
217 CHECK_NULL_VOID(navigationContainer);
218 auto toolbarItems = navigationContainer->GetDeclaration()->menuItems;
219 items.clear();
220 for (auto item : toolbarItems) {
221 items.push_back(item);
222 }
223 }
224
SetCustomMenu(const RefPtr<AceType> & customMenu)225 void NavigationModelImpl::SetCustomMenu(const RefPtr<AceType>& customMenu)
226 {
227 auto customMenus = AceType::DynamicCast<Component>(customMenu);
228 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
229 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
230 if (!navigationContainer) {
231 LOGI("component is not navigationContainer.");
232 return;
233 }
234 #if defined(PREVIEW)
235 auto composedComponent = ViewStackProcessor::GetInstance()->CreateInspectorWrapper("NavigationMenus");
236 composedComponent->SetChild(customMenus);
237 navigationContainer->GetDeclaration()->customMenus = composedComponent;
238 #else
239 navigationContainer->GetDeclaration()->customMenus = customMenus;
240 #endif
241 }
242
SetOnTitleModeChange(std::function<void (NG::NavigationTitleMode)> && onTitleModeChange,std::function<void (const BaseEventInfo * baseInfo)> && eventInfo)243 void NavigationModelImpl::SetOnTitleModeChange(std::function<void(NG::NavigationTitleMode)>&& onTitleModeChange,
244 std::function<void(const BaseEventInfo* baseInfo)>&& eventInfo)
245 {
246 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
247 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
248 auto eventMarker = EventMarker(std::move(eventInfo));
249 if (navigationContainer) {
250 navigationContainer->GetDeclaration()->titleModeChangedEvent = eventMarker;
251 }
252 }
253
SetUsrNavigationMode(NG::NavigationMode mode)254 void NavigationModelImpl::SetUsrNavigationMode(NG::NavigationMode mode)
255 {
256 return;
257 }
258
SetNavBarPosition(NG::NavBarPosition mode)259 void NavigationModelImpl::SetNavBarPosition(NG::NavBarPosition mode)
260 {
261 return;
262 }
263
SetNavBarWidth(const Dimension & value,bool isDoubleBind)264 void NavigationModelImpl::SetNavBarWidth(const Dimension& value, bool isDoubleBind)
265 {
266 return;
267 }
268
SetOnNavBarStateChange(std::function<void (bool)> && onNavBarStateChange)269 void NavigationModelImpl::SetOnNavBarStateChange(std::function<void(bool)>&& onNavBarStateChange)
270 {
271 return;
272 }
273
SetOnNavigationModeChange(std::function<void (NG::NavigationMode)> && onNavigationChange)274 void NavigationModelImpl::SetOnNavigationModeChange(std::function<void(NG::NavigationMode)>&& onNavigationChange)
275 {
276 return;
277 }
278
SetNavigationMode(NG::NavigationMode mode)279 void NavigationModelImpl::SetNavigationMode(NG::NavigationMode mode)
280 {
281 return;
282 }
283
SetNavigationStack()284 void NavigationModelImpl::SetNavigationStack()
285 {
286 return;
287 }
288
SetNavigationStack(const RefPtr<NG::NavigationStack> & navigationStack)289 void NavigationModelImpl::SetNavigationStack(const RefPtr<NG::NavigationStack>& navigationStack)
290 {
291 return;
292 }
293
SetNavigationStackProvided(bool provided)294 void NavigationModelImpl::SetNavigationStackProvided(bool provided)
295 {
296 return;
297 }
298
SetNavDestination(std::function<void (std::string)> && builder)299 void NavigationModelImpl::SetNavDestination(std::function<void(std::string)>&& builder)
300 {
301 return;
302 }
303
GetNavigationStack()304 RefPtr<NG::NavigationStack> NavigationModelImpl::GetNavigationStack()
305 {
306 return nullptr;
307 }
308
SetMenuCount(int32_t menuCount)309 void NavigationModelImpl::SetMenuCount(int32_t menuCount)
310 {
311 auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
312 auto navigationContainer = AceType::DynamicCast<OHOS::Ace::NavigationContainerComponent>(component);
313 if (navigationContainer) {
314 navigationContainer->SetMenuCount(menuCount);
315 }
316 }
317
SetCustomTransition(NavigationTransitionEvent && animationTransition)318 void NavigationModelImpl::SetCustomTransition(NavigationTransitionEvent&& animationTransition) {}
319
SetIsCustomAnimation(bool isCustom)320 void NavigationModelImpl::SetIsCustomAnimation(bool isCustom) {}
321
SetIgnoreLayoutSafeArea(const NG::IgnoreLayoutSafeAreaOpts & opts)322 void NavigationModelImpl::SetIgnoreLayoutSafeArea(const NG::IgnoreLayoutSafeAreaOpts& opts) {}
323 } // namespace OHOS::Ace::Framework
324