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