• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #include <array>
17 #include <utility>
18 
19 #include "base/geometry/ng/size_t.h"
20 #include "base/i18n/localization.h"
21 #include "base/log/log.h"
22 #include "base/log/log_wrapper.h"
23 #include "base/memory/ace_type.h"
24 #include "bridge/card_frontend/card_frontend_declarative.h"
25 #include "bridge/common/utils/engine_helper.h"
26 #include "bridge/declarative_frontend/engine/functions/js_drag_function.h"
27 #include "bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h"
28 #include "bridge/declarative_frontend/engine/js_object_template.h"
29 #include "bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
30 #include "bridge/declarative_frontend/engine/jsi/jsi_extra_view_register.h"
31 #include "bridge/declarative_frontend/engine/jsi/jsi_view_register.h"
32 #ifdef NG_BUILD
33 #include "bridge/declarative_frontend/ng/declarative_frontend_ng.h"
34 #else
35 #include "bridge/declarative_frontend/frontend_delegate_declarative.h"
36 #endif
37 #include "bridge/declarative_frontend/ark_theme/theme_apply/js_with_theme.h"
38 #include "bridge/declarative_frontend/interfaces/profiler/js_profiler.h"
39 #include "bridge/declarative_frontend/jsview/action_sheet/js_action_sheet.h"
40 #include "bridge/declarative_frontend/jsview/canvas/js_canvas.h"
41 #include "bridge/declarative_frontend/jsview/canvas/js_canvas_gradient.h"
42 #include "bridge/declarative_frontend/jsview/canvas/js_canvas_path.h"
43 #include "bridge/declarative_frontend/jsview/canvas/js_canvas_pattern.h"
44 #include "bridge/declarative_frontend/jsview/canvas/js_drawing_rendering_context.h"
45 #include "bridge/declarative_frontend/jsview/canvas/js_matrix2d.h"
46 #include "bridge/declarative_frontend/jsview/canvas/js_offscreen_canvas.h"
47 #include "bridge/declarative_frontend/jsview/canvas/js_offscreen_rendering_context.h"
48 #include "bridge/declarative_frontend/jsview/canvas/js_path2d.h"
49 #include "bridge/declarative_frontend/jsview/canvas/js_render_image.h"
50 #include "bridge/declarative_frontend/jsview/canvas/js_rendering_context.h"
51 #include "bridge/declarative_frontend/jsview/canvas/js_rendering_context_settings.h"
52 #include "bridge/declarative_frontend/jsview/dialog/js_alert_dialog.h"
53 #include "bridge/declarative_frontend/jsview/dialog/js_custom_dialog_controller.h"
54 #include "bridge/declarative_frontend/jsview/js_animator.h"
55 #include "bridge/declarative_frontend/jsview/js_badge.h"
56 #include "bridge/declarative_frontend/jsview/js_base_node.h"
57 #include "bridge/declarative_frontend/jsview/js_blank.h"
58 #include "bridge/declarative_frontend/jsview/js_button.h"
59 #include "bridge/declarative_frontend/jsview/js_cached_image.h"
60 #include "bridge/declarative_frontend/jsview/js_calendar.h"
61 #include "bridge/declarative_frontend/jsview/js_calendar_controller.h"
62 #include "bridge/declarative_frontend/jsview/js_calendar_picker.h"
63 #include "bridge/declarative_frontend/jsview/js_checkbox.h"
64 #include "bridge/declarative_frontend/jsview/js_checkboxgroup.h"
65 #include "bridge/declarative_frontend/jsview/js_circle.h"
66 #include "bridge/declarative_frontend/jsview/js_circle_shape.h"
67 #include "bridge/declarative_frontend/jsview/js_clipboard.h"
68 #include "bridge/declarative_frontend/jsview/js_column.h"
69 #include "bridge/declarative_frontend/jsview/js_column_split.h"
70 #include "bridge/declarative_frontend/jsview/js_common_view.h"
71 #include "bridge/declarative_frontend/jsview/js_container_base.h"
72 #include "bridge/declarative_frontend/jsview/js_container_span.h"
73 #include "bridge/declarative_frontend/jsview/js_content_slot.h"
74 #include "bridge/declarative_frontend/jsview/js_counter.h"
75 #include "bridge/declarative_frontend/jsview/js_data_panel.h"
76 #include "bridge/declarative_frontend/jsview/js_datepicker.h"
77 #include "bridge/declarative_frontend/jsview/js_divider.h"
78 #include "bridge/declarative_frontend/jsview/js_dynamic_component.h"
79 #include "bridge/declarative_frontend/jsview/js_ellipse.h"
80 #include "bridge/declarative_frontend/jsview/js_ellipse_shape.h"
81 #include "bridge/declarative_frontend/jsview/js_environment.h"
82 #include "bridge/declarative_frontend/jsview/js_flex_impl.h"
83 #include "bridge/declarative_frontend/jsview/js_folder_stack.h"
84 #include "bridge/declarative_frontend/jsview/js_foreach.h"
85 #include "bridge/declarative_frontend/jsview/js_form_link.h"
86 #include "bridge/declarative_frontend/jsview/js_gauge.h"
87 #include "bridge/declarative_frontend/jsview/js_gesture.h"
88 #include "bridge/declarative_frontend/jsview/js_grid.h"
89 #include "bridge/declarative_frontend/jsview/js_grid_col.h"
90 #include "bridge/declarative_frontend/jsview/js_grid_container.h"
91 #include "bridge/declarative_frontend/jsview/js_grid_item.h"
92 #include "bridge/declarative_frontend/jsview/js_grid_row.h"
93 #include "bridge/declarative_frontend/jsview/js_hyperlink.h"
94 #include "bridge/declarative_frontend/jsview/js_if_else.h"
95 #include "bridge/declarative_frontend/jsview/js_image.h"
96 #include "bridge/declarative_frontend/jsview/js_image_animator.h"
97 #include "bridge/declarative_frontend/jsview/js_image_span.h"
98 #include "bridge/declarative_frontend/jsview/js_indexer.h"
99 #include "bridge/declarative_frontend/jsview/js_indicator.h"
100 #include "bridge/declarative_frontend/jsview/js_isolated_component.h"
101 #include "bridge/declarative_frontend/jsview/js_keyboard_avoid.h"
102 #include "bridge/declarative_frontend/jsview/js_layout_manager.h"
103 #include "bridge/declarative_frontend/jsview/js_lazy_foreach.h"
104 #include "bridge/declarative_frontend/jsview/js_line.h"
105 #include "bridge/declarative_frontend/jsview/js_linear_gradient.h"
106 #include "bridge/declarative_frontend/jsview/js_list.h"
107 #include "bridge/declarative_frontend/jsview/js_list_item.h"
108 #include "bridge/declarative_frontend/jsview/js_list_item_group.h"
109 #include "bridge/declarative_frontend/jsview/js_loading_progress.h"
110 #include "bridge/declarative_frontend/jsview/js_local_storage.h"
111 #include "bridge/declarative_frontend/jsview/js_location_button.h"
112 #include "bridge/declarative_frontend/jsview/js_marquee.h"
113 #include "bridge/declarative_frontend/jsview/js_menu.h"
114 #include "bridge/declarative_frontend/jsview/js_menu_item.h"
115 #include "bridge/declarative_frontend/jsview/js_menu_item_group.h"
116 #include "bridge/declarative_frontend/jsview/js_mock.h"
117 #include "bridge/declarative_frontend/jsview/js_nav_path_stack.h"
118 #include "bridge/declarative_frontend/jsview/js_navdestination.h"
119 #include "bridge/declarative_frontend/jsview/js_navigation.h"
120 #include "bridge/declarative_frontend/jsview/js_navigator.h"
121 #include "bridge/declarative_frontend/jsview/js_navrouter.h"
122 #include "bridge/declarative_frontend/jsview/js_node_container.h"
123 #include "bridge/declarative_frontend/jsview/js_page_transition.h"
124 #include "bridge/declarative_frontend/jsview/js_pan_handler.h"
125 #include "bridge/declarative_frontend/jsview/js_particle.h"
126 #include "bridge/declarative_frontend/jsview/js_paste_button.h"
127 #include "bridge/declarative_frontend/jsview/js_path.h"
128 #include "bridge/declarative_frontend/jsview/js_path_shape.h"
129 #include "bridge/declarative_frontend/jsview/js_pattern_lock.h"
130 #include "bridge/declarative_frontend/jsview/js_persistent.h"
131 #include "bridge/declarative_frontend/jsview/js_polygon.h"
132 #include "bridge/declarative_frontend/jsview/js_polyline.h"
133 #include "bridge/declarative_frontend/jsview/js_progress.h"
134 #include "bridge/declarative_frontend/jsview/js_qrcode.h"
135 #include "bridge/declarative_frontend/jsview/js_radio.h"
136 #include "bridge/declarative_frontend/jsview/js_rect.h"
137 #include "bridge/declarative_frontend/jsview/js_rect_shape.h"
138 #include "bridge/declarative_frontend/jsview/js_recycle_view.h"
139 #include "bridge/declarative_frontend/jsview/js_refresh.h"
140 #include "bridge/declarative_frontend/jsview/js_relative_container.h"
141 #include "bridge/declarative_frontend/jsview/js_repeat.h"
142 #include "bridge/declarative_frontend/jsview/js_repeat_virtual_scroll.h"
143 #include "bridge/declarative_frontend/jsview/js_richeditor.h"
144 #include "bridge/declarative_frontend/jsview/js_row.h"
145 #include "bridge/declarative_frontend/jsview/js_row_split.h"
146 #include "bridge/declarative_frontend/jsview/js_save_button.h"
147 #include "bridge/declarative_frontend/jsview/js_scope_util.h"
148 #include "bridge/declarative_frontend/jsview/js_scroll.h"
149 #include "bridge/declarative_frontend/jsview/js_scroller.h"
150 #include "bridge/declarative_frontend/jsview/js_search.h"
151 #include "bridge/declarative_frontend/jsview/js_select.h"
152 #include "bridge/declarative_frontend/jsview/js_shape.h"
153 #include "bridge/declarative_frontend/jsview/js_shape_abstract.h"
154 #include "bridge/declarative_frontend/jsview/js_sheet.h"
155 #include "bridge/declarative_frontend/jsview/js_side_bar.h"
156 #include "bridge/declarative_frontend/jsview/js_slider.h"
157 #include "bridge/declarative_frontend/jsview/js_sliding_panel.h"
158 #include "bridge/declarative_frontend/jsview/js_span.h"
159 #include "bridge/declarative_frontend/jsview/js_stack.h"
160 #include "bridge/declarative_frontend/jsview/js_state_mgmt_profiler.h"
161 #include "bridge/declarative_frontend/jsview/js_stepper.h"
162 #include "bridge/declarative_frontend/jsview/js_stepper_item.h"
163 #include "bridge/declarative_frontend/jsview/js_swiper.h"
164 #include "bridge/declarative_frontend/jsview/js_symbol.h"
165 #include "bridge/declarative_frontend/jsview/js_symbol_span.h"
166 #include "bridge/declarative_frontend/jsview/js_tab_content.h"
167 #include "bridge/declarative_frontend/jsview/js_tabs.h"
168 #include "bridge/declarative_frontend/jsview/js_tabs_controller.h"
169 #include "bridge/declarative_frontend/jsview/js_text.h"
170 #include "bridge/declarative_frontend/jsview/js_text_clock.h"
171 #include "bridge/declarative_frontend/jsview/js_textarea.h"
172 #include "bridge/declarative_frontend/jsview/js_textinput.h"
173 #include "bridge/declarative_frontend/jsview/js_textpicker.h"
174 #include "bridge/declarative_frontend/jsview/js_texttimer.h"
175 #include "bridge/declarative_frontend/jsview/js_toggle.h"
176 #include "bridge/declarative_frontend/jsview/js_touch_handler.h"
177 #include "bridge/declarative_frontend/jsview/js_view.h"
178 #include "bridge/declarative_frontend/jsview/js_view_context.h"
179 #include "bridge/declarative_frontend/jsview/js_view_measure_layout.h"
180 #include "bridge/declarative_frontend/jsview/js_view_stack_processor.h"
181 #include "bridge/declarative_frontend/jsview/js_water_flow.h"
182 #include "bridge/declarative_frontend/jsview/js_water_flow_item.h"
183 #include "bridge/declarative_frontend/jsview/menu/js_context_menu.h"
184 #include "bridge/declarative_frontend/jsview/scroll_bar/js_scroll_bar.h"
185 #include "bridge/declarative_frontend/sharedata/js_share_data.h"
186 #include "bridge/declarative_frontend/style_string/js_span_object.h"
187 #include "bridge/declarative_frontend/style_string/js_span_string.h"
188 #include "core/components_ng/base/ui_node.h"
189 #include "core/components_ng/base/view_stack_processor.h"
190 #include "core/components_ng/pattern/custom/custom_title_node.h"
191 #include "core/components_ng/pattern/stage/page_pattern.h"
192 #include "frameworks/bridge/declarative_frontend/jsview/js_dump_log.h"
193 #include "frameworks/bridge/declarative_frontend/jsview/js_scrollable_base.h"
194 #include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
195 
196 #ifdef REMOTE_WINDOW_SUPPORTED
197 #include "bridge/declarative_frontend/jsview/js_remote_window.h"
198 #endif
199 
200 #ifdef EFFECT_COMPONENT_SUPPORTED
201 #include "bridge/declarative_frontend/jsview/js_effect_component.h"
202 #endif
203 
204 #ifndef WEARABLE_PRODUCT
205 #include "bridge/declarative_frontend/jsview/js_piece.h"
206 #include "bridge/declarative_frontend/jsview/js_rating.h"
207 #if defined(PLAYER_FRAMEWORK_EXISTS)
208 #ifdef VIDEO_SUPPORTED
209 #include "bridge/declarative_frontend/jsview/js_video.h"
210 #include "bridge/declarative_frontend/jsview/js_video_controller.h"
211 #endif
212 #endif
213 #endif
214 
215 #if defined(XCOMPONENT_SUPPORTED)
216 #include "bridge/declarative_frontend/jsview/js_xcomponent.h"
217 #include "bridge/declarative_frontend/jsview/js_xcomponent_controller.h"
218 #endif
219 
220 #if defined(PREVIEW)
221 #include "bridge/declarative_frontend/jsview/js_previewer_mock.h"
222 #endif
223 
224 #ifdef ABILITY_COMPONENT_SUPPORTED
225 #include "bridge/declarative_frontend/jsview/js_ability_component.h"
226 #include "bridge/declarative_frontend/jsview/js_ability_component_controller.h"
227 #endif
228 
229 #if defined(MODEL_COMPONENT_SUPPORTED)
230 #include "bridge/declarative_frontend/jsview/js_sceneview.h"
231 #endif
232 
233 #ifdef PLUGIN_COMPONENT_SUPPORTED
234 #include "bridge/declarative_frontend/jsview/js_plugin.h"
235 #include "core/common/plugin_manager.h"
236 #endif
237 
238 #ifdef FORM_SUPPORTED
239 #include "bridge/declarative_frontend/jsview/js_form.h"
240 #include "bridge/declarative_frontend/jsview/js_form_menu_item.h"
241 #endif
242 
243 #ifdef WEB_SUPPORTED
244 #include "bridge/declarative_frontend/jsview/js_richtext.h"
245 #include "bridge/declarative_frontend/jsview/js_web.h"
246 #include "bridge/declarative_frontend/jsview/js_web_controller.h"
247 #endif
248 
249 #ifndef WEARABLE_PRODUCT
250 #if defined(CAMERA_FRAMEWORK_EXISTS) && defined(PLAYER_FRAMEWORK_EXISTS)
251 #include "bridge/declarative_frontend/jsview/js_camera.h"
252 #endif
253 #endif
254 
255 #if defined(WINDOW_SCENE_SUPPORTED)
256 #include "bridge/declarative_frontend/jsview/js_embedded_component.h"
257 #include "bridge/declarative_frontend/jsview/js_security_ui_extension.h"
258 #include "bridge/declarative_frontend/jsview/js_ui_extension.h"
259 #include "bridge/declarative_frontend/jsview/window_scene/js_root_scene.h"
260 #include "bridge/declarative_frontend/jsview/window_scene/js_screen.h"
261 #include "bridge/declarative_frontend/jsview/window_scene/js_window_scene.h"
262 #endif
263 
264 namespace OHOS::Ace::Framework {
265 
AddCustomTitleBarComponent(const panda::Local<panda::ObjectRef> & obj)266 void AddCustomTitleBarComponent(const panda::Local<panda::ObjectRef>& obj)
267 {
268     const auto object = JSRef<JSObject>::Make(obj);
269     const EcmaVM* vm = object->GetEcmaVM();
270     auto* view = static_cast<JSView*>(obj->GetNativePointerField(vm, 0));
271     if (!view && !static_cast<JSViewPartialUpdate*>(view) && !static_cast<JSViewFullUpdate*>(view)) {
272         return;
273     }
274     auto uiNode = AceType::DynamicCast<NG::UINode>(view->CreateViewNode(true));
275     CHECK_NULL_VOID(uiNode);
276     auto customNode = AceType::DynamicCast<NG::CustomTitleNode>(uiNode);
277     CHECK_NULL_VOID(customNode);
278 
279     auto id = ContainerScope::CurrentId();
280     const JSRef<JSVal> setAppTitle = object->GetProperty("setAppTitle");
281     if (setAppTitle->IsFunction()) {
282         JSRef<JSFunc> jsSetAppTitleFunc = JSRef<JSFunc>::Cast(setAppTitle);
283         auto callback = [obj = object, jsFunc = jsSetAppTitleFunc, id, vm](const std::string& title) {
284             ContainerScope scope(id);
285             CHECK_NULL_VOID(vm);
286             JSRef<JSVal> param = JSRef<JSVal>::Make(JsiValueConvertor::toJsiValueWithVM(vm, title));
287             jsFunc->Call(obj, 1, &param);
288         };
289         customNode->SetAppTitleCallback(callback);
290     }
291 #ifdef PIXEL_MAP_SUPPORTED
292     const JSRef<JSVal> setAppIcon = object->GetProperty("setAppIcon");
293     if (setAppIcon->IsFunction()) {
294         JSRef<JSFunc> jsSetAppIconFunc = JSRef<JSFunc>::Cast(setAppIcon);
295         auto callback = [obj = object, jsFunc = jsSetAppIconFunc, id](const RefPtr<PixelMap>& icon) {
296             ContainerScope scope(id);
297             JSRef<JSVal> param = ConvertPixmap(icon);
298             jsFunc->Call(obj, 1, &param);
299         };
300         customNode->SetAppIconCallback(callback);
301     }
302 #endif
303     const JSRef<JSVal> onWindowFocused = object->GetProperty("onWindowFocused");
304     if (onWindowFocused->IsFunction()) {
305         JSRef<JSFunc> jsOnWindowFocusedFunc = JSRef<JSFunc>::Cast(onWindowFocused);
306         auto callback = [obj = object, jsFunc = jsOnWindowFocusedFunc, id]() {
307             ContainerScope scope(id);
308             jsFunc->Call(obj);
309         };
310         customNode->SetOnWindowFocusedCallback(callback);
311     }
312 
313     const JSRef<JSVal> onWindowUnfocused = object->GetProperty("onWindowUnfocused");
314     if (onWindowUnfocused->IsFunction()) {
315         JSRef<JSFunc> jsOnWindowUnfocusedFunc = JSRef<JSFunc>::Cast(onWindowUnfocused);
316         auto callback = [obj = object, jsFunc = jsOnWindowUnfocusedFunc, id]() {
317             ContainerScope scope(id);
318             jsFunc->Call(obj);
319         };
320         customNode->SetOnWindowUnfocusedCallback(callback);
321     }
322     NG::ViewStackProcessor::GetInstance()->SetCustomTitleNode(customNode);
323 }
324 
CleanPageNode(const RefPtr<NG::FrameNode> & pageNode)325 void CleanPageNode(const RefPtr<NG::FrameNode>& pageNode)
326 {
327     if (pageNode->GetChildren().empty()) {
328         return;
329     }
330 
331     auto oldChild = AceType::DynamicCast<NG::CustomNode>(pageNode->GetChildren().front());
332     if (oldChild) {
333 #ifdef PLUGIN_COMPONENT_SUPPORTED
334         if (Container::CurrentId() >= MIN_PLUGIN_SUBCONTAINER_ID) {
335             oldChild->FireOnDisappear();
336         }
337 #endif
338         oldChild->Reset();
339     }
340     pageNode->Clean();
341 }
342 
UpdateRootComponent(const EcmaVM * vm,const panda::Local<panda::ObjectRef> & obj)343 void UpdateRootComponent(const EcmaVM* vm, const panda::Local<panda::ObjectRef>& obj)
344 {
345     auto* view = static_cast<JSView*>(obj->GetNativePointerField(vm, 0));
346     if (!view && !static_cast<JSViewPartialUpdate*>(view) && !static_cast<JSViewFullUpdate*>(view)) {
347         return;
348     }
349 
350     auto container = Container::Current();
351     if (!container) {
352         return;
353     }
354     if (container->IsUseNewPipeline()) {
355         RefPtr<NG::FrameNode> pageNode;
356 #ifdef PLUGIN_COMPONENT_SUPPORTED
357         std::function<void(const std::string&)> callback = [weak = Referenced::WeakClaim(view)](
358                                                                const std::string& params) {
359             auto view = weak.Upgrade();
360             if (view && !params.empty()) {
361                 view->ExecuteInitiallyProvidedValue(params);
362             }
363         };
364         if (view->isFullUpdate()) {
365             callback = [weak = Referenced::WeakClaim(view)](const std::string& params) {
366                 auto view = weak.Upgrade();
367                 if (view && !params.empty()) {
368                     view->ExecuteUpdateWithValueParams(params);
369                 }
370             };
371         }
372         if (Container::CurrentId() >= MIN_PLUGIN_SUBCONTAINER_ID) {
373             auto pluginContainer = PluginManager::GetInstance().GetPluginSubContainer(Container::CurrentId());
374             CHECK_NULL_VOID(pluginContainer);
375             pageNode = pluginContainer->GetPluginNode().Upgrade();
376             CHECK_NULL_VOID(pageNode);
377             pluginContainer->SetDeclarativeOnUpdateWithValueParamsCallback(std::move(callback));
378         } else
379 #endif
380         {
381 #ifdef NG_BUILD
382             auto frontEnd = AceType::DynamicCast<DeclarativeFrontendNG>(container->GetFrontend());
383 #else
384             auto frontEnd = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend());
385 #endif
386             CHECK_NULL_VOID(frontEnd);
387             auto pageRouterManager = frontEnd->GetPageRouterManager();
388             CHECK_NULL_VOID(pageRouterManager);
389             pageNode = pageRouterManager->GetCurrentPageNode();
390             CHECK_NULL_VOID(pageNode);
391         }
392         Container::SetCurrentUsePartialUpdate(!view->isFullUpdate());
393         CleanPageNode(pageNode);
394         auto pageRootNode = AceType::DynamicCast<NG::UINode>(view->CreateViewNode());
395         CHECK_NULL_VOID(pageRootNode);
396         // root custom component
397         pageRootNode->MountToParent(pageNode);
398         // update page life cycle function.
399         auto pagePattern = pageNode->GetPattern<NG::PagePattern>();
400         CHECK_NULL_VOID(pagePattern);
401         // Register RenderDone callback to jsView so that js view can notify pagePattern the render function has been
402         // finish. The onPageShow life cycle must be after the InitialRender function execution.
403         view->RegisterRenderDoneCallback([weak = AceType::WeakClaim(AceType::RawPtr(pagePattern))]() {
404             auto pagePattern = weak.Upgrade();
405             CHECK_NULL_VOID(pagePattern);
406             pagePattern->MarkRenderDone();
407         });
408         pagePattern->SetOnPageShow([weak = Referenced::WeakClaim(view)]() {
409             auto view = weak.Upgrade();
410             if (view) {
411                 view->FireOnShow();
412             }
413         });
414         pagePattern->SetOnPageHide([weak = Referenced::WeakClaim(view)]() {
415             auto view = weak.Upgrade();
416             if (view) {
417                 view->FireOnHide();
418             }
419         });
420         pagePattern->SetOnBackPressed([weak = Referenced::WeakClaim(view)]() {
421             auto view = weak.Upgrade();
422             if (view) {
423                 return view->FireOnBackPress();
424             }
425             return false;
426         });
427         auto customNode = AceType::DynamicCast<NG::CustomNodeBase>(pageRootNode);
428 
429         pagePattern->SetPageTransitionFunc(
430             [weakCustom = WeakPtr<NG::CustomNodeBase>(customNode), weakPage = WeakPtr<NG::FrameNode>(pageNode)]() {
431                 auto custom = weakCustom.Upgrade();
432                 auto page = weakPage.Upgrade();
433                 if (custom && page) {
434                     NG::ScopedViewStackProcessor scopedViewStackProcessor;
435                     NG::ViewStackProcessor::GetInstance()->SetPageNode(page);
436                     custom->CallPageTransitionFunction();
437                     NG::ViewStackProcessor::GetInstance()->SetPageNode(nullptr);
438                 }
439             });
440         pagePattern->RegisterDumpInfoListener(
441             [weakView = Referenced::WeakClaim(view)](const std::vector<std::string>& params) {
442                 auto view = weakView.Upgrade();
443                 if (view) {
444                     view->OnDumpInfo(params);
445                 }
446             });
447         return;
448     }
449 
450     auto runtime = JsiDeclarativeEngineInstance::GetCurrentRuntime();
451     auto page = JsiDeclarativeEngineInstance::GetStagingPage(Container::CurrentId());
452     JsiDeclarativeEngineInstance::RootViewHandle(obj);
453 
454     Container::SetCurrentUsePartialUpdate(!view->isFullUpdate());
455     LOGI("Loading page[%{public}d] root component: Setting pipeline to use %{public}s.", page->GetPageId(),
456         view->isFullUpdate() ? "Full Update" : "Partial Update");
457     auto rootComponent = AceType::DynamicCast<Component>(view->CreateViewNode());
458     std::list<RefPtr<Component>> stackChildren;
459     stackChildren.emplace_back(rootComponent);
460     auto rootStackComponent = AceType::MakeRefPtr<StackComponent>(
461         Alignment::TOP_LEFT, StackFit::INHERIT, Overflow::OBSERVABLE, stackChildren);
462     rootStackComponent->SetMainStackSize(MainStackSize::MAX);
463     auto rootComposed = AceType::MakeRefPtr<ComposedComponent>("0", "root");
464     rootComposed->SetChild(rootStackComponent);
465     page->SetRootComponent(rootComposed);
466     auto pageTransitionComponent = ViewStackProcessor::GetInstance()->GetPageTransitionComponent();
467     ViewStackProcessor::GetInstance()->ClearPageTransitionComponent();
468     page->SetPageTransition(pageTransitionComponent);
469 
470     // We are done, tell to the JSAgePage
471     page->SetPageCreated();
472     auto weak = Referenced::WeakClaim(view);
473     page->SetDeclarativeOnPageAppearCallback([weak]() {
474         auto view = weak.Upgrade();
475         if (view) {
476             view->FireOnShow();
477         }
478     });
479     page->SetDeclarativeOnPageDisAppearCallback([weak]() {
480         auto view = weak.Upgrade();
481         if (view) {
482             view->FireOnHide();
483         }
484     });
485     page->SetDeclarativeOnBackPressCallback([weak]() {
486         auto view = weak.Upgrade();
487         if (view) {
488             return view->FireOnBackPress();
489         }
490         return false;
491     });
492     page->SetDeclarativeOnPageRefreshCallback([weak]() {
493         auto view = weak.Upgrade();
494         if (view) {
495             view->MarkNeedUpdate();
496         }
497     });
498     page->SetDeclarativeOnUpdateWithValueParamsCallback([weak](const std::string& params) {
499         auto view = weak.Upgrade();
500         if (view && !params.empty()) {
501             view->ExecuteUpdateWithValueParams(params);
502         }
503     });
504 }
505 
506 static const std::unordered_map<std::string, std::function<void(BindingTarget)>> formBindFuncs = {
507     { "Flex", JSFlexImpl::JSBind },
508     { "Text", JSText::JSBind },
509     { "TextClock", JSTextClock::JSBind },
510     { "TextClockController", JSTextClockController::JSBind },
511     { "Animator", JSAnimator::JSBind },
512     { "SpringProp", JSAnimator::JSBind },
513     { "SpringMotion", JSAnimator::JSBind },
514     { "ScrollMotion", JSAnimator::JSBind },
515     { "Animator", JSAnimator::JSBind },
516     { "Span", JSSpan::JSBind },
517     { "NativeCustomSpan", JSNativeCustomSpan::JSBind },
518     { "SpanString", JSSpanString::JSBind },
519     { "MutableSpanString", JSMutableSpanString::JSBind },
520     { "TextStyle", JSFontSpan::JSBind },
521     { "DecorationStyle", JSDecorationSpan::JSBind },
522     { "BaselineOffsetStyle", JSBaselineOffsetSpan::JSBind },
523     { "LetterSpacingStyle", JSLetterSpacingSpan::JSBind },
524     { "UrlStyle", JSUrlSpan::JSBind },
525     { "NativeGestureStyle", JSGestureSpan::JSBind },
526     { "TextShadowSpan", JSTextShadowSpan::JSBind },
527     { "BackgroundColorStyle", JSBackgroundColorSpan::JSBind },
528     { "ImageAttachment", JSImageAttachment::JSBind },
529     { "ParagraphStyleSpan", JSParagraphStyleSpan::JSBind},
530     { "LineHeightSpan", JSLineHeightSpan::JSBind},
531     { "Button", JSButton::JSBind },
532     { "Canvas", JSCanvas::JSBind },
533     { "Matrix2D", JSMatrix2d::JSBind },
534     { "CanvasPattern", JSCanvasPattern::JSBind },
535     { "List", JSList::JSBind },
536     { "ListItem", JSListItem::JSBind },
537     { "LoadingProgress", JSLoadingProgress::JSBind },
538     { "Image", JSImage::JSBind },
539     { "Counter", JSCounter::JSBind },
540     { "CalendarPicker", JSCalendarPicker::JSBind },
541     { "Progress", JSProgress::JSBind },
542     { "Column", JSColumn::JSBind },
543     { "Row", JSRow::JSBind },
544     { "Slider", JSSlider::JSBind },
545     { "Stack", JSStack::JSBind },
546     { "FolderStack", JSFolderStack::JSBind},
547     { "ForEach", JSForEach::JSBind },
548     { "Divider", JSDivider::JSBind },
549     { "If", JSIfElse::JSBind },
550     { "Scroll", JSScroll::JSBind },
551     { "GridRow", JSGridRow::JSBind },
552     { "GridCol", JSGridCol::JSBind },
553     { "Toggle", JSToggle::JSBind },
554     { "Blank", JSBlank::JSBind },
555     { "Calendar", JSCalendar::JSBind },
556     { "Rect", JSRect::JSBind },
557     { "Shape", JSShape::JSBind },
558     { "Path", JSPath::JSBind },
559     { "Circle", JSCircle::JSBind },
560     { "Line", JSLine::JSBind },
561     { "Polygon", JSPolygon::JSBind },
562     { "Polyline", JSPolyline::JSBind },
563     { "Ellipse", JSEllipse::JSBind },
564     { "Radio", JSRadio::JSBind },
565     { "QRCode", JSQRCode::JSBind },
566     { "Piece", JSPiece::JSBind },
567     { "Rating", JSRating::JSBind },
568     { "DataPanel", JSDataPanel::JSBind },
569     { "Badge", JSBadge::JSBind },
570     { "Gauge", JSGauge::JSBind },
571     { "Marquee", JSMarquee::JSBind },
572     { "Swiper", JSSwiper::JSBind },
573     { "Indicator", JSIndicator::JSBind },
574     { "SwiperController", JSSwiperController::JSBind },
575     { "CalendarController", JSCalendarController::JSBind },
576     { "CanvasRenderingContext2D", JSRenderingContext::JSBind },
577     { "OffscreenCanvasRenderingContext2D", JSOffscreenRenderingContext::JSBind },
578     { "CanvasGradient", JSCanvasGradient::JSBind },
579     { "ImageData", JSCanvasImageData::JSBind },
580     { "ImageAnimator", JSImageAnimator::JSBind },
581     { "Path2D", JSPath2D::JSBind },
582     { "RenderingContextSettings", JSRenderingContextSettings::JSBind },
583     { "Sheet", JSSheet::JSBind },
584     { "TextTimer", JSTextTimer::JSBind },
585     { "TextTimerController", JSTextTimerController::JSBind },
586     { "Checkbox", JSCheckbox::JSBind },
587     { "CheckboxGroup", JSCheckboxGroup::JSBind },
588     { "RelativeContainer", JSRelativeContainer::JSBind },
589     { "__Common__", JSCommonView::JSBind },
590     { "LinearGradient", JSLinearGradient::JSBind },
591     { "FormLink", JSFormLink::JSBind },
592     { "SymbolSpan", JSSymbolSpan::JSBind },
593     { "DrawingRenderingContext", JSDrawingRenderingContext::JSBind },
594 };
595 
596 static const std::unordered_map<std::string, std::function<void(BindingTarget)>> bindFuncs = {
597     { "Flex", JSFlexImpl::JSBind },
598     { "TextController", JSTextController::JSBind },
599     { "Text", JSText::JSBind },
600     { "Animator", JSAnimator::JSBind },
601     { "SpringProp", JSAnimator::JSBind },
602     { "SpringMotion", JSAnimator::JSBind },
603     { "ScrollMotion", JSAnimator::JSBind },
604     { "Animator", JSAnimator::JSBind },
605     { "Span", JSSpan::JSBind },
606     { "NativeCustomSpan", JSNativeCustomSpan::JSBind },
607     { "SpanString", JSSpanString::JSBind },
608     { "MutableSpanString", JSMutableSpanString::JSBind },
609     { "TextStyle", JSFontSpan::JSBind },
610     { "DecorationStyle", JSDecorationSpan::JSBind },
611     { "BaselineOffsetStyle", JSBaselineOffsetSpan::JSBind },
612     { "LetterSpacingStyle", JSLetterSpacingSpan::JSBind },
613     { "UrlStyle", JSUrlSpan::JSBind },
614     { "NativeGestureStyle", JSGestureSpan::JSBind },
615     { "TextShadowSpan", JSTextShadowSpan::JSBind },
616     { "BackgroundColorStyle", JSBackgroundColorSpan::JSBind },
617     { "ImageAttachment", JSImageAttachment::JSBind },
618     { "ParagraphStyleSpan", JSParagraphStyleSpan::JSBind},
619     { "LineHeightSpan", JSLineHeightSpan::JSBind},
620     { "Button", JSButton::JSBind },
621     { "Canvas", JSCanvas::JSBind },
622     { "LazyForEach", JSLazyForEach::JSBind },
623     { "List", JSList::JSBind },
624     { "ListItem", JSListItem::JSBind },
625     { "ListItemGroup", JSListItemGroup::JSBind },
626     { "LoadingProgress", JSLoadingProgress::JSBind },
627     { "Image", JSImage::JSBind },
628     { "ImageAnimator", JSImageAnimator::JSBind },
629     { "Counter", JSCounter::JSBind },
630     { "CalendarPicker", JSCalendarPicker::JSBind },
631     { "Progress", JSProgress::JSBind },
632     { "Column", JSColumn::JSBind },
633     { "Row", JSRow::JSBind },
634     { "Grid", JSGrid::JSBind },
635     { "GridItem", JSGridItem::JSBind },
636     { "GridContainer", JSGridContainer::JSBind },
637     { "Slider", JSSlider::JSBind },
638     { "Stack", JSStack::JSBind },
639     { "FolderStack", JSFolderStack::JSBind},
640     { "ForEach", JSForEach::JSBind },
641     { "Divider", JSDivider::JSBind },
642     { "Swiper", JSSwiper::JSBind },
643     { "Indicator", JSIndicator::JSBind },
644     { "Panel", JSSlidingPanel::JSBind },
645     { "RepeatNative", JSRepeat::JSBind },
646     { "RepeatVirtualScrollNative", JSRepeatVirtualScroll::JSBind },
647     { "NavDestination", JSNavDestination::JSBind },
648     { "Navigation", JSNavigation::JSBind },
649     { "NativeNavPathStack", JSNavPathStack::JSBind },
650     { "Navigator", JSNavigator::JSBind },
651     { "NavRouter", JSNavRouter::JSBind },
652     { "ColumnSplit", JSColumnSplit::JSBind },
653     { "If", JSIfElse::JSBind },
654     { "Scroll", JSScroll::JSBind },
655     { "ScrollBar", JSScrollBar::JSBind },
656     { "GridRow", JSGridRow::JSBind },
657     { "GridCol", JSGridCol::JSBind },
658     { "Stepper", JSStepper::JSBind },
659     { "StepperItem", JSStepperItem::JSBind },
660     { "Toggle", JSToggle::JSBind },
661     { "Blank", JSBlank::JSBind },
662     { "Calendar", JSCalendar::JSBind },
663     { "CalendarPickerDialog", JSCalendarPickerDialog::JSBind },
664     { "Rect", JSRect::JSBind },
665     { "Shape", JSShape::JSBind },
666     { "Path", JSPath::JSBind },
667     { "Circle", JSCircle::JSBind },
668     { "Line", JSLine::JSBind },
669     { "Polygon", JSPolygon::JSBind },
670     { "Polyline", JSPolyline::JSBind },
671     { "Ellipse", JSEllipse::JSBind },
672     { "Tabs", JSTabs::JSBind },
673     { "TabContent", JSTabContent::JSBind },
674     { "TextPicker", JSTextPicker::JSBind },
675     { "TimePicker", JSTimePicker::JSBind },
676     { "TextPickerDialog", JSTextPickerDialog::JSBind },
677     { "TimePickerDialog", JSTimePickerDialog::JSBind },
678     { "DatePicker", JSDatePicker::JSBind },
679     { "DatePickerDialog", JSDatePickerDialog::JSBind },
680     { "PageTransitionEnter", JSPageTransition::JSBind },
681     { "PageTransitionExit", JSPageTransition::JSBind },
682     { "RowSplit", JSRowSplit::JSBind },
683     { "ColumnSplit", JSColumnSplit::JSBind },
684     { "AlphabetIndexer", JSIndexer::JSBind },
685     { "Hyperlink", JSHyperlink::JSBind },
686     { "Radio", JSRadio::JSBind },
687     { "ActionSheet", JSActionSheet::JSBind },
688     { "AlertDialog", JSAlertDialog::JSBind },
689     { "ContextMenu", JSContextMenu::JSBind },
690     { "FormLink", JSFormLink::JSBind },
691     { "LocationButton", JSLocationButton::JSBind },
692     { "PasteButton", JSPasteButton::JSBind },
693     { "Particle", JSParticle::JSBind },
694     { "SaveButton", JSSaveButton::JSBind },
695     { "WithTheme", JSWithTheme::JSBind },
696     { "__KeyboardAvoid__", JSKeyboardAvoid::JSBind },
697 #ifdef ABILITY_COMPONENT_SUPPORTED
698     { "AbilityComponent", JSAbilityComponent::JSBind },
699 #endif
700     { "TextArea", JSTextArea::JSBind },
701     { "TextInput", JSTextInput::JSBind },
702     { "TextClock", JSTextClock::JSBind },
703     { "SideBarContainer", JSSideBar::JSBind },
704     { "QRCode", JSQRCode::JSBind },
705 #ifdef FORM_SUPPORTED
706     { "FormComponent", JSForm::JSBind },
707     { "FormMenuItem", JSFormMenuItem::JSBind },
708 #endif
709 #ifdef PLUGIN_COMPONENT_SUPPORTED
710     { "PluginComponent", JSPlugin::JSBind },
711 #endif
712 #ifdef WEB_SUPPORTED
713 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
714     { "RichText", JSRichText::JSBind },
715     { "WebController", JSWebController::JSBind },
716 #endif
717     { "Web", JSWeb::JSBind },
718 #endif
719 #ifdef REMOTE_WINDOW_SUPPORTED
720     { "RemoteWindow", JSRemoteWindow::JSBind },
721 #endif
722 #ifdef EFFECT_COMPONENT_SUPPORTED
723     { "EffectComponent", JSEffectComponent::JSBind },
724 #endif
725 #ifndef WEARABLE_PRODUCT
726 #if defined(CAMERA_FRAMEWORK_EXISTS) && defined(PLAYER_FRAMEWORK_EXISTS)
727     { "Camera", JSCamera::JSBind },
728 #endif
729     { "Piece", JSPiece::JSBind },
730     { "Rating", JSRating::JSBind },
731 #if defined(PLAYER_FRAMEWORK_EXISTS)
732 #ifdef VIDEO_SUPPORTED
733     { "Video", JSVideo::JSBind },
734 #endif
735 #endif
736 #endif
737 #if defined(XCOMPONENT_SUPPORTED)
738     { "XComponent", JSXComponent::JSBind },
739     { "XComponentController", JSXComponentController::JSBind },
740 #endif
741     { "DataPanel", JSDataPanel::JSBind },
742     { "Badge", JSBadge::JSBind },
743     { "Gauge", JSGauge::JSBind },
744     { "Marquee", JSMarquee::JSBind },
745     { "Menu", JSMenu::JSBind },
746     { "MenuItem", JSMenuItem::JSBind },
747     { "MenuItemGroup", JSMenuItemGroup::JSBind },
748     { "Gesture", JSGesture::JSBind },
749     { "TapGesture", JSGesture::JSBind },
750     { "LongPressGesture", JSGesture::JSBind },
751     { "PanGesture", JSGesture::JSBind },
752     { "SwipeGesture", JSGesture::JSBind },
753     { "PinchGesture", JSGesture::JSBind },
754     { "RotationGesture", JSGesture::JSBind },
755     { "GestureGroup", JSGesture::JSBind },
756     { "PanGestureOption", JSPanGestureOption::JSBind },
757     { "PanGestureOptions", JSPanGestureOption::JSBind },
758     { "NativeCustomDialogController", JSCustomDialogController::JSBind },
759     { "Scroller", JSScroller::JSBind },
760     { "ListScroller", JSListScroller::JSBind },
761     { "SwiperController", JSSwiperController::JSBind },
762     { "IndicatorController", JSIndicatorController::JSBind },
763     { "TabsController", JSTabsController::JSBind },
764     { "CalendarController", JSCalendarController::JSBind },
765 #ifdef ABILITY_COMPONENT_SUPPORTED
766     { "AbilityController", JSAbilityComponentController::JSBind },
767 #endif
768     { "CanvasRenderingContext2D", JSRenderingContext::JSBind },
769     { "OffscreenCanvasRenderingContext2D", JSOffscreenRenderingContext::JSBind },
770     { "CanvasGradient", JSCanvasGradient::JSBind },
771     { "ImageData", JSCanvasImageData::JSBind },
772     { "Path2D", JSPath2D::JSBind },
773     { "RenderingContextSettings", JSRenderingContextSettings::JSBind },
774     { "Matrix2D", JSMatrix2d::JSBind },
775     { "CanvasPattern", JSCanvasPattern::JSBind },
776     { "DrawingRenderingContext", JSDrawingRenderingContext::JSBind },
777 #if defined(PLAYER_FRAMEWORK_EXISTS)
778 #ifdef VIDEO_SUPPORTED
779     { "VideoController", JSVideoController::JSBind },
780 #endif
781 #endif
782     { "Search", JSSearch::JSBind },
783     { "Select", JSSelect::JSBind },
784     { "SearchController", JSSearchController::JSBind },
785     { "TextClockController", JSTextClockController::JSBind },
786     { "Sheet", JSSheet::JSBind },
787     { "JSClipboard", JSClipboard::JSBind },
788     { "PatternLock", JSPatternLock::JSBind },
789     { "PatternLockController", JSPatternLockController::JSBind },
790     { "TextTimer", JSTextTimer::JSBind },
791     { "TextAreaController", JSTextAreaController::JSBind },
792     { "TextInputController", JSTextInputController::JSBind },
793     { "TextTimerController", JSTextTimerController::JSBind },
794     { "Checkbox", JSCheckbox::JSBind },
795     { "CheckboxGroup", JSCheckboxGroup::JSBind },
796     { "Refresh", JSRefresh::JSBind },
797     { "WaterFlow", JSWaterFlow::JSBind },
798     { "FlowItem", JSWaterFlowItem::JSBind },
799     { "RelativeContainer", JSRelativeContainer::JSBind },
800     { "__Common__", JSCommonView::JSBind },
801     { "__Recycle__", JSRecycleView::JSBind },
802     { "LinearGradient", JSLinearGradient::JSBind },
803     { "ImageSpan", JSImageSpan::JSBind },
804 #ifdef PREVIEW
805     { "FormComponent", JSForm::JSBind },
806     { "XComponent", JSXComponent::JSBind },
807     { "XComponentController", JSXComponentController::JSBind },
808     { "RichText", JSRichText::JSBind },
809     { "Web", JSWeb::JSBind },
810     { "WebController", JSWebController::JSBind },
811 #if defined(PLAYER_FRAMEWORK_EXISTS)
812     { "Video", JSVideo::JSBind },
813     { "VideoController", JSVideoController::JSBind },
814 #endif
815     { "PluginComponent", JSPlugin::JSBind },
816     { "SecurityUIExtensionComponent", JSSecurityUIExtension::JSBind },
817     { "UIExtensionComponent", JSUIExtension::JSBind },
818 #endif
819 #if defined(MODEL_COMPONENT_SUPPORTED)
820     { "Component3D", JSSceneView::JSBind },
821 #endif
822 #if defined(WINDOW_SCENE_SUPPORTED)
823     { "EmbeddedComponent", JSEmbeddedComponent::JSBind },
824     { "RootScene", JSRootScene::JSBind },
825     { "Screen", JSScreen::JSBind },
826     { "SecurityUIExtensionComponent", JSSecurityUIExtension::JSBind },
827     { "SecurityUIExtensionProxy", JSSecurityUIExtensionProxy::JSBind },
828     { "UIExtensionComponent", JSUIExtension::JSBind },
829     { "UIExtensionProxy", JSUIExtensionProxy::JSBind },
830     { "WindowScene", JSWindowScene::JSBind },
831 #if defined(DYNAMIC_COMPONENT_SUPPORT)
832     { "DynamicComponent", JSDynamicComponent::JSBind },
833     { "IsolatedComponent", JSIsolatedComponent::JSBind },
834 #endif
835 #endif
836     { "RichEditor", JSRichEditor::JSBind },
837     { "RichEditorController", JSRichEditorController::JSBind },
838     { "RichEditorStyledStringController", JSRichEditorStyledStringController::JSBind },
839     { "LayoutManager", JSLayoutManager::JSBind },
840     { "NodeContainer", JSNodeContainer::JSBind },
841     { "__JSBaseNode__", JSBaseNode::JSBind },
842     { "ContainerSpan",  JSContainerSpan::JSBind},
843     { "SymbolGlyph", JSSymbol::JSBind },
844     { "SymbolSpan", JSSymbolSpan::JSBind },
845     { "__PathShape__", JSPathShape::JSBind },
846     { "__RectShape__", JSRectShape::JSBind },
847     { "__CircleShape__", JSCircleShape::JSBind },
848     { "__EllipseShape__", JSEllipseShape::JSBind },
849     { "ContentSlot", JSContentSlot::JSBind },
850     { "ArkUINativeNodeContent", JSNodeContent::JSBind },
851     { "GestureRecognizer", JSGestureRecognizer::JSBind },
852     { "EventTargetInfo", JSEventTargetInfo::JSBind },
853     { "ScrollableTargetInfo", JSScrollableTargetInfo::JSBind },
854     { "PanRecognizer", JSPanRecognizer::JSBind }
855 };
856 
RegisterBindFuncs(BindingTarget globalObj)857 void RegisterBindFuncs(BindingTarget globalObj)
858 {
859     auto container = Container::Current();
860     if (container && container->IsDynamicRender() && !container->GetRegisterComponents().empty()) {
861         for (auto& moudle : container->GetRegisterComponents()) {
862             auto bindFunc = bindFuncs.find(moudle);
863             if (bindFunc != bindFuncs.end()) {
864                 bindFunc->second(globalObj);
865                 continue;
866             }
867             if (!RegisterExtraViewByName(globalObj, moudle)) {
868                 LOGW("module not exist, name: %{public}s", moudle.c_str());
869             }
870         }
871         return;
872     }
873 
874     for (auto& iter : bindFuncs) {
875         iter.second(globalObj);
876     }
877 }
878 
RegisterAllModule(BindingTarget globalObj,void * nativeEngine)879 void RegisterAllModule(BindingTarget globalObj, void* nativeEngine)
880 {
881     JSColumn::JSBind(globalObj);
882     JSCommonView::JSBind(globalObj);
883     JSSwiperController::JSBind(globalObj);
884     JSIndicatorController::JSBind(globalObj);
885     JSTabsController::JSBind(globalObj);
886     JSScroller::JSBind(globalObj);
887     JSListScroller::JSBind(globalObj);
888     JSCalendarController::JSBind(globalObj);
889     JSRenderingContext::JSBind(globalObj);
890     JSOffscreenRenderingContext::JSBind(globalObj);
891     JSCanvasGradient::JSBind(globalObj);
892     JSRenderImage::JSBind(globalObj, nativeEngine);
893     JSCanvasImageData::JSBind(globalObj);
894     JSPath2D::JSBind(globalObj);
895     JSRenderingContextSettings::JSBind(globalObj);
896     JSOffscreenCanvas::JSBind(globalObj, nativeEngine);
897 #ifdef ABILITY_COMPONENT_SUPPORTED
898     JSAbilityComponentController::JSBind(globalObj);
899 #endif
900 #if defined(PLAYER_FRAMEWORK_EXISTS)
901 #ifdef VIDEO_SUPPORTED
902     JSVideoController::JSBind(globalObj);
903 #endif
904 #endif
905     JSTextInputController::JSBind(globalObj);
906     JSTextAreaController::JSBind(globalObj);
907     JSSearchController::JSBind(globalObj);
908     JSTextClockController::JSBind(globalObj);
909     JSTextTimerController::JSBind(globalObj);
910     JSLinearGradient::JSBind(globalObj);
911 #ifdef WEB_SUPPORTED
912 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
913     JSWebController::JSBind(globalObj);
914 #endif
915 #endif
916     JSRichEditorController::JSBind(globalObj);
917     JSRichEditorStyledStringController::JSBind(globalObj);
918     JSLayoutManager::JSBind(globalObj);
919     JSTextController::JSBind(globalObj);
920     JSNodeContainer::JSBind(globalObj);
921     JSBaseNode::JSBind(globalObj);
922     JSRectShape::JSBind(globalObj);
923     JSCircleShape::JSBind(globalObj);
924     JSEllipseShape::JSBind(globalObj);
925     JSPathShape::JSBind(globalObj);
926 
927     RegisterBindFuncs(globalObj);
928     RegisterExtraViews(globalObj);
929 }
930 
RegisterAllFormModule(BindingTarget globalObj,void * nativeEngine)931 void RegisterAllFormModule(BindingTarget globalObj, void* nativeEngine)
932 {
933     JSColumn::JSBind(globalObj);
934     JSCommonView::JSBind(globalObj);
935     JSSwiperController::JSBind(globalObj);
936     JSIndicatorController::JSBind(globalObj);
937     JSScroller::JSBind(globalObj);
938     JSListScroller::JSBind(globalObj);
939     JSCalendarController::JSBind(globalObj);
940     JSRenderingContext::JSBind(globalObj);
941     JSOffscreenRenderingContext::JSBind(globalObj);
942     JSCanvasGradient::JSBind(globalObj);
943     JSRenderImage::JSBind(globalObj, nativeEngine);
944     JSOffscreenCanvas::JSBind(globalObj, nativeEngine);
945     JSCanvasImageData::JSBind(globalObj);
946     JSPath2D::JSBind(globalObj);
947     JSRenderingContextSettings::JSBind(globalObj);
948     JSTextTimerController::JSBind(globalObj);
949     JSLinearGradient::JSBind(globalObj);
950     for (auto& iter : formBindFuncs) {
951         iter.second(globalObj);
952     }
953     RegisterExtraViews(globalObj);
954 }
955 
RegisterFormModuleByName(BindingTarget globalObj,const std::string & module,void * nativeEngine)956 void RegisterFormModuleByName(BindingTarget globalObj, const std::string& module, void* nativeEngine)
957 {
958     if (module == "ImageBitmap") {
959         JSRenderImage::JSBind(globalObj, nativeEngine);
960         return;
961     }
962     if (module == "OffscreenCanvas") {
963         JSOffscreenCanvas::JSBind(globalObj, nativeEngine);
964         return;
965     }
966     auto func = bindFuncs.find(module);
967     if (func == bindFuncs.end()) {
968         RegisterExtraViewByName(globalObj, module);
969         return;
970     }
971     if ((*func).first == "Swiper") {
972         JSSwiperController::JSBind(globalObj);
973     } else if ((*func).first == "Calendar") {
974         JSCalendarController::JSBind(globalObj);
975     } else if ((*func).first == "TextTimer") {
976         JSTextTimerController::JSBind(globalObj);
977     } else if ((*func).first == "TextClock") {
978         JSTextClockController::JSBind(globalObj);
979     } else if ((*func).first == "Canvas") {
980         JSCanvasPattern::JSBind(globalObj);
981         JSCanvasGradient::JSBind(globalObj);
982         JSCanvasImageData::JSBind(globalObj);
983         JSMatrix2d::JSBind(globalObj);
984         JSRenderImage::JSBind(globalObj, nativeEngine);
985     }
986 
987     (*func).second(globalObj);
988 }
989 
RegisterModuleByName(BindingTarget globalObj,std::string moduleName)990 void RegisterModuleByName(BindingTarget globalObj, std::string moduleName)
991 {
992     auto func = bindFuncs.find(moduleName);
993     if (func == bindFuncs.end()) {
994         RegisterExtraViewByName(globalObj, moduleName);
995         return;
996     }
997     if ((*func).first == "Swiper") {
998         JSSwiperController::JSBind(globalObj);
999     } else if ((*func).first == "Tabs") {
1000         JSTabsController::JSBind(globalObj);
1001     } else if ((*func).first == "Calendar") {
1002         JSCalendarController::JSBind(globalObj);
1003     } else if ((*func).first == "AbilityComponent") {
1004 #ifdef ABILITY_COMPONENT_SUPPORTED
1005         JSAbilityComponentController::JSBind(globalObj);
1006 #endif
1007     } else if ((*func).first == "Video") {
1008 #if defined(PLAYER_FRAMEWORK_EXISTS)
1009 #ifdef VIDEO_SUPPORTED
1010         JSVideoController::JSBind(globalObj);
1011 #endif
1012 #endif
1013     } else if ((*func).first == "Grid") {
1014         JSColumn::JSBind(globalObj);
1015     } else if ((*func).first == "TextTimer") {
1016         JSTextTimerController::JSBind(globalObj);
1017     } else if ((*func).first == "TextInput") {
1018         JSTextInputController::JSBind(globalObj);
1019     } else if ((*func).first == "TextClock") {
1020         JSTextClockController::JSBind(globalObj);
1021     } else if ((*func).first == "TextArea") {
1022         JSTextAreaController::JSBind(globalObj);
1023     } else if ((*func).first == "Search") {
1024         JSSearchController::JSBind(globalObj);
1025     } else if ((*func).first == "Web") {
1026 #ifdef WEB_SUPPORTED
1027         JSWebController::JSBind(globalObj);
1028 #endif
1029     } else if ((*func).first == V2::RICH_EDITOR_ETS_TAG) {
1030         JSRichEditorController::JSBind(globalObj);
1031         JSRichEditorStyledStringController::JSBind(globalObj);
1032         JSLayoutManager::JSBind(globalObj);
1033     } else if ((*func).first == V2::TEXT_ETS_TAG) {
1034         JSTextController::JSBind(globalObj);
1035     }
1036 
1037     (*func).second(globalObj);
1038 }
1039 
JsUINodeRegisterCleanUp(BindingTarget globalObj)1040 void JsUINodeRegisterCleanUp(BindingTarget globalObj)
1041 {
1042     // globalObj is panda::Local<panda::ObjectRef>
1043     const auto globalObject = JSRef<JSObject>::Make(globalObj);
1044 
1045     const JSRef<JSVal> cleanUpIdleTask = globalObject->GetProperty("uiNodeCleanUpIdleTask");
1046     if (cleanUpIdleTask->IsFunction()) {
1047         LOGI("CleanUpIdleTask is a valid function");
1048         const auto globalFunc = JSRef<JSFunc>::Cast(cleanUpIdleTask);
1049         const std::function<void(void)> callback = [jsFunc = globalFunc, globalObject = globalObject]() {
1050             jsFunc->Call(globalObject);
1051         };
1052         ElementRegister::GetInstance()->RegisterJSCleanUpIdleTaskFunc(callback);
1053     }
1054 }
1055 
JsRegisterModules(BindingTarget globalObj,std::string modules,void * nativeEngine)1056 void JsRegisterModules(BindingTarget globalObj, std::string modules, void* nativeEngine)
1057 {
1058     std::stringstream input(modules);
1059     std::string moduleName;
1060     while (std::getline(input, moduleName, ',')) {
1061         RegisterModuleByName(globalObj, moduleName);
1062     }
1063     JsUINodeRegisterCleanUp(globalObj);
1064 
1065     JSRenderingContext::JSBind(globalObj);
1066     JSOffscreenRenderingContext::JSBind(globalObj);
1067     JSCanvasGradient::JSBind(globalObj);
1068     JSRenderImage::JSBind(globalObj, nativeEngine);
1069     JSOffscreenCanvas::JSBind(globalObj, nativeEngine);
1070     JSCanvasImageData::JSBind(globalObj);
1071     JSPath2D::JSBind(globalObj);
1072     JSRenderingContextSettings::JSBind(globalObj);
1073 }
1074 
JsBindFormViews(BindingTarget globalObj,const std::unordered_set<std::string> & formModuleList,void * nativeEngine,bool isReload)1075 void JsBindFormViews(
1076     BindingTarget globalObj, const std::unordered_set<std::string>& formModuleList, void* nativeEngine, bool isReload)
1077 {
1078     if (!isReload) {
1079         JSViewAbstract::JSBind(globalObj);
1080         JSContainerBase::JSBind(globalObj);
1081         JSScrollableBase::JSBind(globalObj);
1082         JSShapeAbstract::JSBind(globalObj);
1083         JSView::JSBind(globalObj);
1084         JSDumpLog::JSBind(globalObj);
1085         JSDumpRegister::JSBind(globalObj);
1086         JSLocalStorage::JSBind(globalObj);
1087         JSStateMgmtProfiler::JSBind(globalObj);
1088         JSCustomDialogController::JSBind(globalObj);
1089 
1090         JSEnvironment::JSBind(globalObj);
1091         JSViewContext::JSBind(globalObj);
1092         JSViewStackProcessor::JSBind(globalObj);
1093         JSTouchHandler::JSBind(globalObj);
1094         JSPersistent::JSBind(globalObj);
1095         JSScroller::JSBind(globalObj);
1096         JSListScroller::JSBind(globalObj);
1097 
1098         JSProfiler::JSBind(globalObj);
1099         JSCommonView::JSBind(globalObj);
1100         JSLinearGradient::JSBind(globalObj);
1101         JSPath2D::JSBind(globalObj);
1102         JSOffscreenRenderingContext::JSBind(globalObj);
1103         JSRenderingContextSettings::JSBind(globalObj);
1104         JSRenderingContext::JSBind(globalObj);
1105 
1106         JSRectShape::JSBind(globalObj);
1107         JSCircleShape::JSBind(globalObj);
1108         JSEllipseShape::JSBind(globalObj);
1109         JSPathShape::JSBind(globalObj);
1110     }
1111 
1112     if (!formModuleList.empty()) {
1113         for (const std::string& module : formModuleList) {
1114             RegisterFormModuleByName(globalObj, module, nativeEngine);
1115         }
1116     } else {
1117         TAG_LOGI(AceLogTag::ACE_FORM, "register all form components, isReload:%{public}d", isReload);
1118         RegisterAllFormModule(globalObj, nativeEngine);
1119     }
1120 }
1121 
JsBindViews(BindingTarget globalObj,void * nativeEngine)1122 void JsBindViews(BindingTarget globalObj, void* nativeEngine)
1123 {
1124     JSViewAbstract::JSBind(globalObj);
1125     JSContainerBase::JSBind(globalObj);
1126     JSScrollableBase::JSBind(globalObj);
1127     JSShapeAbstract::JSBind(globalObj);
1128     JSView::JSBind(globalObj);
1129     JSDumpLog::JSBind(globalObj);
1130     JSDumpRegister::JSBind(globalObj);
1131     JSLocalStorage::JSBind(globalObj);
1132     JSStateMgmtProfiler::JSBind(globalObj);
1133 
1134     JSEnvironment::JSBind(globalObj);
1135     JSViewContext::JSBind(globalObj);
1136     JSViewStackProcessor::JSBind(globalObj);
1137     JSTouchHandler::JSBind(globalObj);
1138     JSPanHandler::JSBind(globalObj);
1139     JSGesture::JSBind(globalObj);
1140     JSPanGestureOption::JSBind(globalObj);
1141     JsDragFunction::JSBind(globalObj);
1142     JSCustomDialogController::JSBind(globalObj);
1143     JSShareData::JSBind(globalObj);
1144     JSPersistent::JSBind(globalObj);
1145     JSScroller::JSBind(globalObj);
1146     JSListScroller::JSBind(globalObj);
1147 
1148     JSProfiler::JSBind(globalObj);
1149     JSScopeUtil::JSBind(globalObj);
1150 
1151     auto delegate = JsGetFrontendDelegate();
1152     std::string jsModules;
1153     if (delegate && delegate->GetAssetContent("component_collection.txt", jsModules)) {
1154         JsRegisterModules(globalObj, jsModules, nativeEngine);
1155     } else {
1156         RegisterAllModule(globalObj, nativeEngine);
1157     }
1158 }
1159 
JsBindWorkerViews(BindingTarget globalObj,void * nativeEngine)1160 void JsBindWorkerViews(BindingTarget globalObj, void* nativeEngine)
1161 {
1162     JSCanvasGradient::JSBind(globalObj);
1163     JSCanvasPattern::JSBind(globalObj);
1164     JSMatrix2d::JSBind(globalObj);
1165     JSOffscreenCanvas::JSBind(globalObj, nativeEngine);
1166     JSOffscreenRenderingContext::JSBind(globalObj);
1167     JSRenderingContextSettings::JSBind(globalObj);
1168     JSRenderImage::JSBind(globalObj, nativeEngine);
1169     JSPath2D::JSBind(globalObj);
1170     JSCanvasImageData::JSBind(globalObj);
1171     JSMock::JSBind(globalObj);
1172 }
1173 
1174 } // namespace OHOS::Ace::Framework
1175