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