• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <arkui/native_node_napi.h>
17 #include <hilog/log.h>
18 #include <js_native_api.h>
19 #include "NativeEntry.h"
20 #include "CreateDialogExample.h"
21 
22 namespace NativeModule {
23 
CreateNativeRoot(napi_env env,napi_callback_info info)24 napi_value CreateNativeRoot(napi_env env, napi_callback_info info) {
25     size_t argc = 1;
26     napi_value args[1] = {nullptr};
27 
28     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
29 
30     // 获取NodeContent
31     ArkUI_NodeContentHandle contentHandle;
32     OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle);
33     NativeEntry::GetInstance()->SetContentHandle(contentHandle);
34 
35     // 创建文本列表
36     auto page = CreateDialogExample();
37 
38     // 保持Native侧对象到管理类中,维护生命周期。
39     NativeEntry::GetInstance()->SetRootNode(page);
40     return nullptr;
41 }
42 
DestroyNativeRoot(napi_env env,napi_callback_info info)43 napi_value DestroyNativeRoot(napi_env env, napi_callback_info info) {
44     // 从管理类中释放Native侧对象。
45     NativeEntry::GetInstance()->DisposeRootNode();
46     return nullptr;
47 }
48 
49 } // namespace NativeModule