diff --git a/ArkUIKit/NativeNodeNapi/AppScope/app.json5 b/ArkUIKit/NativeNodeNapi/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bdf31a37e01ac463ba1438372cb142f729a5915b --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.native_node_napi", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/NativeNodeNapi/AppScope/resources/base/element/string.json b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9e206b8fdfe2a67f400fc8016966544b37f1dde0 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "native_node_napi" + } + ] +} diff --git a/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/background.png b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/foreground.png b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/layered_image.json b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/README.md b/ArkUIKit/NativeNodeNapi/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8ccb9c371c550ea403d03ebdbccb6f91359e9b38 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/README.md @@ -0,0 +1,87 @@ +# Native_node_napi + +## 介绍 + +本示例基于[native_node.h](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/capi-native-node-h.md)、[native_node_napi.h](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/capi-native-node-napi-h.md)展示了如何通过调用CAPI提供的相关方法来获取、设置navigation组件等组件的相关属性和信息,以及将ArkTS侧创建的DrawableDescriptor对象映射到native侧的ArkUI_DrawableDescriptor。 + +## 效果预览 + +| 首页 | navigation页面 | +| ---- | -------------------------------------------------------- | +| | | +| | | + +## 使用说明 + +1. 安装编译生成的hap包,并打开应用。 +2. 进入首页,可选择不同模块页面。 +3. 点击navigation选择框进入navigation组件相关的CAPI接口展示界面,通过点击不同的按钮来触发不同的事件,具体结果在log中查看。 +4. 点击accessibility选择框进入accessibility组件相关的CAPI接口展示界面,在屏幕朗读模式下,通过点击等行为来感知具体的无障碍属性,具体结果在log中查看。 +5. 点击embedded component选择框进入embedded component组件相关的CAPI接口展示界面,通过hdc设置不同的参数配置来触发不同的事件,具体结果在log中查看。 +6. 点击Mapping DrawableDescriptor选择项进入DrawableDescriptor映射页面,通过点击按钮方式1:GetDrawableDescriptorFromNapiValue,来触发DrawableDescriptor的映射接口,若接口成功调用可以在DevEco Studio开发环境中的日志界面看到如下相关日志信息: +``` +"success to get drawable descriptor" +``` + +## 工程目录 + +``` +entry/src/main/ets/ +└── pages + ├── Index.ets (获取导航页面) + ├── page_navigation.ets (获取导航页面) + ├── page_accessibility.ets (无障碍界面) + ├── page_embedded_component.ets (嵌入式组件界面) + └── GetDrawableDescriptor.ets (映射DrawableDescriptor页面) +entry/src/main/ +├── cpp +│ ├── types +│ │ └── libentry +│ │ └── Index.d.ts (函数对应的js映射) +│ ├── CMakeLists.txt (CMake脚本) +| ├── manager.cpp +| ├── manager.h +│ ├── napi_init.cpp +| ├── ....... +| ├── AccessibilityMaker.h +| ├── AccessibilityMaker.cpp +| ├── EmbeddedComponentMaker,cpp +| ├── EmbeddedComponentMaker.h +| ├── NavigationContext.cpp +│ └── NavigationContext.h +└── resources + ├── base + │ ├── element + │ │ ├── color.json + │ │ ├── float.json + │ │ └── string.json + │ └── media +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.36; + +3. 本示例已支持使DevEco Studio 5.1.1 Release (构建版本:5.1.1.840,构建 2025年9月20日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +```bash +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/NativeNodeNapi/native_node_napi > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/build-profile.json5 b/ArkUIKit/NativeNodeNapi/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..11e19dc1ca66d83c53c3d66d57197bb03f63b418 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "release" + } + ], + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/code-linter.json5 b/ArkUIKit/NativeNodeNapi/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4c531be90a6c875995767bd87f2de3cbd6b55160 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/build-profile.json5 b/ArkUIKit/NativeNodeNapi/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016ca8c62da83754a0b09bfc58f360872d6ab80 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/hvigorfile.ts b/ArkUIKit/NativeNodeNapi/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..10f881f112b08550ed5c8a3ceb7d0148be2a0b6e --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/obfuscation-rules.txt b/ArkUIKit/NativeNodeNapi/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/oh-package.json5 b/ArkUIKit/NativeNodeNapi/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9f254ab4d0e3a4de30318e04483b785b552ce977 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/AccessibilityMaker.cpp b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/AccessibilityMaker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99c94a69ca54d79d580debb8231eb399a605977e --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/AccessibilityMaker.cpp @@ -0,0 +1,680 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "AccessibilityMaker.h" + +constexpr int32_t ACCESSIBILITY_VALUE_MIN = 0; +constexpr int32_t ACCESSIBILITY_VALUE_MAX = 100; +constexpr int32_t ACCESSIBILITY_VALUE_CURRENT = 50; +constexpr const char* ACCESSIBILITY_VALUE_TEXT = "Value"; +constexpr int32_t ACCESSIBILITY_RANGE_MIN = 0; +constexpr int32_t ACCESSIBILITY_RANGE_MAX = 10; +constexpr int32_t ACCESSIBILITY_RANGE_CURRENT = 5; +constexpr float COL_WIDTH_PX = 300.0f; +constexpr float TEXT_WIDTH_PX = 300.0f; +constexpr float TEXT_HEIGHT_PX = 100.0f; +constexpr float BORDER_WIDTH_PX = 1.0f; +constexpr float BUTTON_WIDTH_PX = 200.0f; +constexpr float BUTTON_HEIGHT_PX = 50.0f; +constexpr float BUTTON_MARGIN_PX = 5.0f; +constexpr int EVENT_ID = 11111; +constexpr const char* SAMPLE_TEXT = "Hello Accessibility Sample"; +static ArkUI_AccessibilityState* accessibilityState_; +static ArkUI_AccessibilityValue* accessibilityValue_; + +void AccessibilityMaker::CreateAccessibilitySelectedSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "1. 通过 OH_ArkUI_AccessibilityState_SetSelected 设置无障碍状态:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle column = BuildColumnNode(nodeApi); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, "Hello Accessibility Sample(non-selected)"); + ArkUI_NodeHandle text3 = BuildTextNode(nodeApi, "Hello Accessibility Sample(selected)"); + CreateAccessibilityState(); + SetAccessibilityDisabled(false); + bool disabled = IsAccessibilityDisabled(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "IsAccessibilityDisabled: disabled=%{public}d", + disabled); + SetAccessibilitySelected(true); + bool selected = IsAccessibilitySelected(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "IsAccessibilitySelected: selected=%{public}d", + selected); + ArkUI_AttributeItem accessibilityItem = { .object = accessibilityState_ }; + nodeApi->setAttribute(text3, NODE_ACCESSIBILITY_STATE, &accessibilityItem); + SetAccessibilitySelected(false); + accessibilityItem = { .object = accessibilityState_ }; + nodeApi->setAttribute(text2, NODE_ACCESSIBILITY_STATE, &accessibilityItem); + nodeApi->addChild(column, text2); + nodeApi->addChild(column, text3); + nodeApi->addChild(parent, column); +} + +void AccessibilityMaker::CreateAccessibilityCheckedSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "2. 通过 OH_ArkUI_AccessibilityState_SetCheckedState 设置无障碍状态:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle column = BuildColumnNode(nodeApi); + ArkUI_NodeHandle checkbox = nodeApi->createNode(ARKUI_NODE_CHECKBOX); + ArkUI_NodeHandle checkbox2 = nodeApi->createNode(ARKUI_NODE_CHECKBOX); + CreateAccessibilityState(); + SetAccessibilityDisabled(false); + bool disabled = IsAccessibilityDisabled(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "IsAccessibilityDisabled: disabled=%{public}d", + disabled); + SetAccessibilityCheckedState(ARKUI_ACCESSIBILITY_UNCHECKED); + int32_t checkedState = GetAccessibilityCheckedState(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityCheckedState: state=%{public}d", + checkedState); + ArkUI_AttributeItem accessibilityItem = { .object = accessibilityState_ }; + nodeApi->setAttribute(parent, NODE_ACCESSIBILITY_STATE, &accessibilityItem); + SetAccessibilityCheckedState(ARKUI_ACCESSIBILITY_CHECKED); + accessibilityItem = { .object = accessibilityState_ }; + nodeApi->setAttribute(checkbox2, NODE_ACCESSIBILITY_STATE, &accessibilityItem); + nodeApi->addChild(column, checkbox); + nodeApi->addChild(column, checkbox2); + nodeApi->addChild(parent, column); +} + +void AccessibilityMaker::CreateAccessibilityValueSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "3. 通过 NODE_ACCESSIBILITY_VALUE 设置无障碍信息属性:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + CreateAccessibilityValue(); + SetAccessibilityValueMin(ACCESSIBILITY_VALUE_MIN); + int32_t valueMin = GetAccessibilityValueMin(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityValueMin: min=%{public}d", valueMin); + SetAccessibilityValueMax(ACCESSIBILITY_VALUE_MAX); + int32_t valueMax = GetAccessibilityValueMax(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityValueMax: max=%{public}d", valueMax); + SetAccessibilityValueCurrent(ACCESSIBILITY_VALUE_CURRENT); + int32_t valueCurrent = GetAccessibilityValueCurrent(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityValueCurrent: current=%{public}d", + valueCurrent); + SetAccessibilityValueText(ACCESSIBILITY_VALUE_TEXT); + const char* valueText = GetAccessibilityValueText(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityValueText: text=%{public}s", + valueText); + SetAccessibilityRangeMin(ACCESSIBILITY_RANGE_MIN); + int32_t rangeMin = GetAccessibilityRangeMin(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityRangeMin: min=%{public}d", rangeMin); + SetAccessibilityRangeMax(ACCESSIBILITY_RANGE_MAX); + int32_t rangeMax = GetAccessibilityValueMax(); + rangeMax = GetAccessibilityRangeMax(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityRangeMax: max=%{public}d", rangeMax); + SetAccessibilityRangeCurrent(ACCESSIBILITY_RANGE_CURRENT); + int32_t rangeCurrent = GetAccessibilityRangeCurrent(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityRangeCurrent: current=%{public}d", + rangeCurrent); + ArkUI_AttributeItem accessibilityValueItem = { .object = accessibilityValue_ }; + nodeApi->setAttribute(text2, NODE_ACCESSIBILITY_VALUE, &accessibilityValueItem); + nodeApi->addChild(parent, text2); +} + +void AccessibilityMaker::CreateAccessibilityNodeIdSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, "4. 通过 NODE_ID 获取无障碍节点ID:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + SetNodeId(nodeApi, text2, "test node id"); + const char* nodeId = GetNodeId(nodeApi, text2); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetNodeId: id=%{public}s", nodeId); + nodeApi->addChild(parent, text2); +} + +void AccessibilityMaker::CreateAccessibilityGroupSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "5. 通过 NODE_ACCESSIBILITY_GROUP 设置无障碍分组:"); + ArkUI_NodeHandle column = BuildColumnNode(nodeApi); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, "column子节点1"); + ArkUI_NodeHandle text3 = BuildTextNode(nodeApi, "column子节点2"); + SetAccessibilityGroup(nodeApi, column, true); + bool isGroup = GetAccessibilityGroup(nodeApi, column); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityGroup: isGroup=%{public}d", isGroup); + nodeApi->addChild(column, text2); + nodeApi->addChild(column, text3); + nodeApi->addChild(parent, text1); + nodeApi->addChild(parent, column); +} + +void AccessibilityMaker::CreateAccessibilityModeSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "6. 通过 NODE_ACCESSIBILITY_MODE 设置无障碍辅助服务模式(ACCESSIBILITY_MODE):"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, "Hello Accessibility Sample(DISABLED, 不可被无障碍辅助服务所识别)"); + SetAccessibilityMode(nodeApi, text2, ARKUI_ACCESSIBILITY_MODE_DISABLED); + ArkUI_AccessibilityMode mode = GetAccessibilityMode(nodeApi, text2); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityMode: mode=%{public}d", mode); + nodeApi->addChild(parent, text2); +} + + +void AccessibilityMaker::CreateAccessibilityTextSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "7. 通过 NODE_ACCESSIBILITY_TEXT 设置无障碍文本:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + SetAccessibilityText(nodeApi, text2, "This is a text"); + const char* accessibilityText = GetAccessibilityText(nodeApi, text2); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityText: text=%{public}s", + accessibilityText); + nodeApi->addChild(parent, text2); +} + +void AccessibilityMaker::CreateAccessibilityDescriptionSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "8. 通过 NODE_ACCESSIBILITY_DESCRIPTION 设置无障碍描述:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + SetAccessibilityDescription(nodeApi, text2, "This is accessibility description"); + const char* description = GetAccessibilityDescription(nodeApi, text2); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityDescription: description=%{public}s", + description); + nodeApi->addChild(parent, text2); +} + +void AccessibilityMaker::CreateAccessibilityIdSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "9. 通过 NODE_ACCESSIBILITY_ID 获取无障碍ID:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + int accessibilityId = GetAccessibilityId(nodeApi, text2); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityId: id=%{public}d", accessibilityId); + nodeApi->addChild(parent, text2); +} + +void AccessibilityMaker::CreateAccessibilityActionsSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, "10. 设置无障碍支持操作事件:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle button = nodeApi->createNode(ARKUI_NODE_BUTTON); + ArkUI_NumberValue button_widthValue[] = {BUTTON_WIDTH_PX}; + ArkUI_AttributeItem button_widthItem = {button_widthValue, 1}; + ArkUI_NumberValue button_heightValue1[] = {BUTTON_HEIGHT_PX}; + ArkUI_AttributeItem button_heightItem = {button_heightValue1, 1}; + ArkUI_NumberValue marginValue[] = {BUTTON_MARGIN_PX}; + ArkUI_AttributeItem marginItem = {marginValue, 1}; + nodeApi->setAttribute(button, NODE_WIDTH, &button_widthItem); + nodeApi->setAttribute(button, NODE_HEIGHT, &button_heightItem); + nodeApi->setAttribute(button, NODE_MARGIN, &marginItem); + SetAccessibilityActions(nodeApi, button); + nodeApi->registerNodeEvent(button, NODE_ON_CLICK, 0, nullptr); + nodeApi->registerNodeEvent(button, NODE_ON_ACCESSIBILITY_ACTIONS, EVENT_ID, nullptr); + nodeApi->registerNodeEventReceiver([](ArkUI_NodeEvent *event) { + auto eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + if (eventId == EVENT_ID) { + auto componentEvent = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + auto actionType = componentEvent->data[0].u32; + switch (actionType) { + case ARKUI_ACCESSIBILITY_ACTION_CLICK: + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "ARKUI_ACCESSIBILITY_ACTION_CLICK"); + break; + default: + break; + } + } + }); + nodeApi->addChild(parent, button); +} + +void AccessibilityMaker::CreateAccessibilityRoleSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "11. 通过 NODE_ACCESSIBILITY_ROLE 设置无障碍组件类型:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + SetAccessibilityRole(nodeApi, text2, ARKUI_NODE_TEXT); + uint32_t role = GetAccessibilityRole(nodeApi, text2); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetAccessibilityRole: role=%{public}u", role); + nodeApi->addChild(parent, text2); +} + +void AccessibilityMaker::CreateUniqueIdSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent) +{ + ArkUI_NodeHandle text1 = BuildTextNodeWithoutAccessibilityFocus(nodeApi, + "12. 通过 NODE_UNIQUE_ID 获取唯一ID:"); + nodeApi->addChild(parent, text1); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, SAMPLE_TEXT); + GetUniqueId(nodeApi, text2); + nodeApi->addChild(parent, text2); +} + +ArkUI_NodeHandle AccessibilityMaker::CreateNativeNode() +{ + ArkUI_NativeNodeAPI_1 *nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + if (nodeApi == nullptr) { + return nullptr; + } + // 创建一个Column容器组件 + ArkUI_NodeHandle column = BuildColumnNode(nodeApi); + // 创建Text组件 + ArkUI_NodeHandle text = BuildTextNode(nodeApi, SAMPLE_TEXT); + + auto scrollNode = nodeApi->createNode(ARKUI_NODE_SCROLL); + nodeApi->addChild(scrollNode, column); + + CreateAccessibilitySelectedSection(nodeApi, column); + CreateAccessibilityCheckedSection(nodeApi, column); + CreateAccessibilityValueSection(nodeApi, column); + CreateAccessibilityNodeIdSection(nodeApi, column); + CreateAccessibilityGroupSection(nodeApi, column); + CreateAccessibilityModeSection(nodeApi, column); + CreateAccessibilityTextSection(nodeApi, column); + CreateAccessibilityDescriptionSection(nodeApi, column); + CreateAccessibilityIdSection(nodeApi, column); + CreateAccessibilityActionsSection(nodeApi, column); + CreateAccessibilityRoleSection(nodeApi, column); + CreateUniqueIdSection(nodeApi, column); + + // Column作为XComponent子组件 + return scrollNode; +} + +ArkUI_NodeHandle AccessibilityMaker::BuildTextNodeWithoutAccessibilityFocus(ArkUI_NativeNodeAPI_1* nodeApi, + const char* content) +{ + ArkUI_NodeHandle text = nodeApi->createNode(ARKUI_NODE_TEXT); + ArkUI_NumberValue textWidth[] = {{.f32 = TEXT_WIDTH_PX}}; + ArkUI_AttributeItem textWidthItem = { textWidth, sizeof(textWidth) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_WIDTH, &textWidthItem); + ArkUI_NumberValue textHeight[] = {{.f32 = TEXT_HEIGHT_PX}}; + ArkUI_AttributeItem textHeightItem = { textHeight, sizeof(textHeight) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_HEIGHT, &textHeightItem); + ArkUI_AttributeItem valueItem = {.string = content}; + nodeApi->setAttribute(text, NODE_TEXT_CONTENT, &valueItem); + SetAccessibilityMode(nodeApi, text, ARKUI_ACCESSIBILITY_MODE_DISABLED); + return text; +} +ArkUI_NodeHandle AccessibilityMaker::BuildTextNode(ArkUI_NativeNodeAPI_1* nodeApi, const char* content) +{ + ArkUI_NodeHandle text = nodeApi->createNode(ARKUI_NODE_TEXT); + ArkUI_NumberValue textWidth[] = {{.f32 = TEXT_WIDTH_PX}}; + ArkUI_AttributeItem textWidthItem = { textWidth, sizeof(textWidth) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_WIDTH, &textWidthItem); + ArkUI_NumberValue textHeight[] = {{.f32 = TEXT_HEIGHT_PX}}; + ArkUI_AttributeItem textHeightItem = { textHeight, sizeof(textHeight) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_HEIGHT, &textHeightItem); + ArkUI_AttributeItem valueItem = {.string = content}; + nodeApi->setAttribute(text, NODE_TEXT_CONTENT, &valueItem); + return text; +} + +ArkUI_NodeHandle AccessibilityMaker::BuildColumnNode(ArkUI_NativeNodeAPI_1* nodeApi) +{ + ArkUI_NodeHandle column = nodeApi->createNode(ARKUI_NODE_COLUMN); + ArkUI_NumberValue colWidth[] = {{.f32 = COL_WIDTH_PX}}; + ArkUI_AttributeItem widthItem = { colWidth, sizeof(colWidth) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(column, NODE_WIDTH, &widthItem); + return column; +} + +AccessibilityMaker::~AccessibilityMaker() +{ + DisposeAccessibilityState(); + DisposeAccessibilityValue(); +} + +void AccessibilityMaker::CreateAccessibilityState() +{ + if (!accessibilityState_) { + accessibilityState_ = OH_ArkUI_AccessibilityState_Create(); + } +} + +void AccessibilityMaker::SetAccessibilityDisabled(bool isDisabled) +{ + if (accessibilityState_) { + OH_ArkUI_AccessibilityState_SetDisabled(accessibilityState_, isDisabled); + } +} + +bool AccessibilityMaker::IsAccessibilityDisabled() +{ + if (accessibilityState_) { + return OH_ArkUI_AccessibilityState_IsDisabled(accessibilityState_); + } + return false; +} + +void AccessibilityMaker::SetAccessibilitySelected(bool isSelected) +{ + if (accessibilityState_) { + OH_ArkUI_AccessibilityState_SetSelected(accessibilityState_, isSelected); + } +} + +bool AccessibilityMaker::IsAccessibilitySelected() +{ + if (accessibilityState_) { + return OH_ArkUI_AccessibilityState_IsSelected(accessibilityState_); + } + return false; +} + +void AccessibilityMaker::SetAccessibilityCheckedState(int32_t checkedState) +{ + if (accessibilityState_) { + OH_ArkUI_AccessibilityState_SetCheckedState(accessibilityState_, checkedState); + } +} + +int32_t AccessibilityMaker::GetAccessibilityCheckedState() +{ + if (accessibilityState_) { + return OH_ArkUI_AccessibilityState_GetCheckedState(accessibilityState_); + } + return 0; +} + +void AccessibilityMaker::DisposeAccessibilityState() +{ + if (accessibilityState_) { + OH_ArkUI_AccessibilityState_Dispose(accessibilityState_); + accessibilityState_ = nullptr; + } +} + +void AccessibilityMaker::CreateAccessibilityValue() +{ + if (!accessibilityValue_) { + accessibilityValue_ = OH_ArkUI_AccessibilityValue_Create(); + } +} + +void AccessibilityMaker::DisposeAccessibilityValue() +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_Dispose(accessibilityValue_); + accessibilityValue_ = nullptr; + } +} + +void AccessibilityMaker::SetAccessibilityValueMin(int32_t min) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetMin(accessibilityValue_, min); + } +} + +int32_t AccessibilityMaker::GetAccessibilityValueMin() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetMin(accessibilityValue_); + } + return 0; +} + +void AccessibilityMaker::SetAccessibilityValueMax(int32_t max) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetMax(accessibilityValue_, max); + } +} + +int32_t AccessibilityMaker::GetAccessibilityValueMax() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetMax(accessibilityValue_); + } + return 0; +} + +void AccessibilityMaker::SetAccessibilityValueCurrent(int32_t current) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetCurrent(accessibilityValue_, current); + } +} + +int32_t AccessibilityMaker::GetAccessibilityValueCurrent() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetCurrent(accessibilityValue_); + } + return 0; +} + +void AccessibilityMaker::SetAccessibilityValueText(const char* text) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetText(accessibilityValue_, text); + } +} + +const char* AccessibilityMaker::GetAccessibilityValueText() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetText(accessibilityValue_); + } + return nullptr; +} + +void AccessibilityMaker::SetAccessibilityRangeMin(int32_t rangeMin) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetRangeMin(accessibilityValue_, rangeMin); + } +} + +int32_t AccessibilityMaker::GetAccessibilityRangeMin() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetRangeMin(accessibilityValue_); + } + return 0; +} + +void AccessibilityMaker::SetAccessibilityRangeMax(int32_t rangeMax) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetRangeMax(accessibilityValue_, rangeMax); + } +} + +int32_t AccessibilityMaker::GetAccessibilityRangeMax() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetRangeMax(accessibilityValue_); + } + return 0; +} + +void AccessibilityMaker::SetAccessibilityRangeCurrent(int32_t rangeCurrent) +{ + if (accessibilityValue_) { + OH_ArkUI_AccessibilityValue_SetRangeCurrent(accessibilityValue_, rangeCurrent); + } +} + +int32_t AccessibilityMaker::GetAccessibilityRangeCurrent() +{ + if (accessibilityValue_) { + return OH_ArkUI_AccessibilityValue_GetRangeCurrent(accessibilityValue_); + } + return 0; +} + +void AccessibilityMaker::SetNodeId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, const char* id) +{ + if (nodeApi && node) { + ArkUI_AttributeItem idItem = {.string = id}; + nodeApi->setAttribute(node, NODE_ID, &idItem); + } +} + +const char* AccessibilityMaker::GetNodeId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attributeItem = nodeApi->getAttribute(node, NODE_ID); + if (attributeItem) { + return attributeItem->string; + } + } + return nullptr; +} + +void AccessibilityMaker::SetAccessibilityGroup(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, bool isGroup) +{ + if (nodeApi && node) { + ArkUI_NumberValue value[] = {{.i32 = isGroup}}; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_ACCESSIBILITY_GROUP, &item); + } +} + +bool AccessibilityMaker::GetAccessibilityGroup(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attributeItem = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_GROUP); + if (attributeItem) { + return attributeItem->value[0].i32; + } + } + return false; +} + +void AccessibilityMaker::SetAccessibilityMode(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, + ArkUI_AccessibilityMode mode) +{ + if (nodeApi && node) { + ArkUI_NumberValue value[] = {{.i32 = mode}}; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_ACCESSIBILITY_MODE, &item); + } +} + +ArkUI_AccessibilityMode AccessibilityMaker::GetAccessibilityMode(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attr = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_MODE); + if (attr && attr->size > 0) { + return static_cast(attr->value[0].i32); + } + } + return ARKUI_ACCESSIBILITY_MODE_AUTO; +} + +void AccessibilityMaker::SetAccessibilityDescription(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, + const char* description) +{ + if (nodeApi && node) { + ArkUI_AttributeItem item = {.string = description}; + nodeApi->setAttribute(node, NODE_ACCESSIBILITY_DESCRIPTION, &item); + } +} + +const char* AccessibilityMaker::GetAccessibilityDescription(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attr = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_DESCRIPTION); + if (attr) { + return attr->string; + } + } + return nullptr; +} + +int AccessibilityMaker::GetAccessibilityId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attr = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_ID); + if (attr && attr->size > 0) { + return attr->value[0].i32; + } + } + return -1; +} + +void AccessibilityMaker::SetAccessibilityText(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, const char* text) +{ + if (nodeApi && node) { + ArkUI_AttributeItem item = {.string = text}; + nodeApi->setAttribute(node, NODE_ACCESSIBILITY_TEXT, &item); + } +} + +const char* AccessibilityMaker::GetAccessibilityText(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attr = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_TEXT); + if (attr) { + return attr->string; + } + } + return nullptr; +} + +void AccessibilityMaker::SetAccessibilityActions(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + ArkUI_NumberValue value[] = {{ .u32 = ARKUI_ACCESSIBILITY_ACTION_CLICK}}; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_ACCESSIBILITY_ACTIONS, &item); + } +} + +uint32_t AccessibilityMaker::GetAccessibilityActions(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attr = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_ACTIONS); + if (attr && attr->size > 0) { + return attr->value[0].u32; + } + } + return 0U; +} + +void AccessibilityMaker::SetAccessibilityRole(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, + const uint32_t role) +{ + if (nodeApi && node) { + ArkUI_NumberValue value[] = {{ .u32 = role}}; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(node, NODE_ACCESSIBILITY_ROLE, &item); + } +} + +uint32_t AccessibilityMaker::GetAccessibilityRole(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem* attr = nodeApi->getAttribute(node, NODE_ACCESSIBILITY_ROLE); + if (attr && attr->size > 0) { + return attr->value[0].u32; + } + } + return 0U; +} + +void AccessibilityMaker::GetUniqueId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + const ArkUI_AttributeItem *attributeItem = nodeApi->getAttribute(node, NODE_UNIQUE_ID); + // 组件id作为targetid来区分不同组件的事件。 + auto id = attributeItem->value[0].i32; + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "GetUniqueId: id=%{public}d", id); + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/AccessibilityMaker.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/AccessibilityMaker.h new file mode 100644 index 0000000000000000000000000000000000000000..7b92b4a8a34bb1172c7b1139c38b95b227848fbd --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/AccessibilityMaker.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_NODE_SAMPLE_ACCESSIBILITYMAKER_H +#define NATIVE_NODE_SAMPLE_ACCESSIBILITYMAKER_H + +#include +#include +#include +#include +#include "manager.h" + +class AccessibilityMaker { +public: + AccessibilityMaker(){}; + ~AccessibilityMaker(); + static ArkUI_NodeHandle CreateNativeNode(); + static ArkUI_NodeHandle BuildTextNode(ArkUI_NativeNodeAPI_1* nodeApi, const char* content); + static ArkUI_NodeHandle BuildTextNodeWithoutAccessibilityFocus(ArkUI_NativeNodeAPI_1* nodeApi, const char* content); + static void CreateAccessibilityState(); + static void SetAccessibilityDisabled(bool isDisabled); + static bool IsAccessibilityDisabled(); + static void SetAccessibilitySelected(bool isSelected); + static bool IsAccessibilitySelected(); + static void SetAccessibilityCheckedState(int32_t checkedState); + static int32_t GetAccessibilityCheckedState(); + static void DisposeAccessibilityState(); + static ArkUI_NodeHandle BuildColumnNode(ArkUI_NativeNodeAPI_1* nodeApi); + static void CreateAccessibilityValue(); + static void DisposeAccessibilityValue(); + static void SetAccessibilityValueMin(int32_t min); + static int32_t GetAccessibilityValueMin(); + static void SetAccessibilityValueMax(int32_t max); + static int32_t GetAccessibilityValueMax(); + static void SetAccessibilityValueCurrent(int32_t current); + static int32_t GetAccessibilityValueCurrent(); + static void SetAccessibilityValueText(const char* text); + static const char* GetAccessibilityValueText(); + static void SetAccessibilityRangeMin(int32_t rangeMin); + static int32_t GetAccessibilityRangeMin(); + static void SetAccessibilityRangeMax(int32_t rangeMax); + static int32_t GetAccessibilityRangeMax(); + static void SetAccessibilityRangeCurrent(int32_t rangeCurrent); + static int32_t GetAccessibilityRangeCurrent(); + static void SetNodeId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, const char* id); + static const char* GetNodeId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void SetAccessibilityGroup(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, bool isGroup); + static bool GetAccessibilityGroup(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void SetAccessibilityMode(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, + ArkUI_AccessibilityMode mode); + static ArkUI_AccessibilityMode GetAccessibilityMode(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void SetAccessibilityText(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, const char* text); + static const char* GetAccessibilityText(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void SetAccessibilityDescription(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, + const char* description); + static const char* GetAccessibilityDescription(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static int GetAccessibilityId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void SetAccessibilityActions(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static uint32_t GetAccessibilityActions(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void SetAccessibilityRole(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node, const uint32_t role); + static uint32_t GetAccessibilityRole(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void GetUniqueId(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void CreateAccessibilityCheckedSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilitySelectedSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityValueSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityNodeIdSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityGroupSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityModeSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityTextSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityDescriptionSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityIdSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityActionsSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateAccessibilityRoleSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void CreateUniqueIdSection(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle parent); + static void OnErrorCallback(int32_t code, const char* name, const char* message); + static void OnTerminatedCallback(int32_t code, AbilityBase_Want* want); +}; + +#endif // NATIVE_NODE_SAMPLE_ACCESSIBILITYMAKER_H diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIAnimationNode.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIAnimationNode.h new file mode 100644 index 0000000000000000000000000000000000000000..4aa0dfe3437774be8438b22a675074467fe9a387 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIAnimationNode.h @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIDOBASENODE_H +#define MYAPPLICATION_ARKUIDOBASENODE_H +#include "ArkUIColumnNode.h" +#include "ArkUITextNode.h" +#include "ArkUINumber.h" +#include + +namespace NativeModule { +std::shared_ptr g_keyframe_text = nullptr; +std::shared_ptr g_keyframe_column1 = nullptr; +std::shared_ptr g_keyframe_column2 = nullptr; +std::shared_ptr CreateAnimationCenter() +{ + auto column = std::make_shared(); + auto textNodeTransition = std::make_shared(); + textNodeTransition->SetTextContent("NODE_TRANSITION"); + textNodeTransition->SetWidth(MIDDLE_LENGTH); + textNodeTransition->SetHeight(SMALL_LENGTH); + ArkUI_RotationOptions rotation; + rotation.x = NUMBER_0; + rotation.y = NUMBER_0; + rotation.z = NUMBER_1; + rotation.angle = NUMBER_180; + rotation.perspective = NUMBER_0; + ArkUI_TransitionEffect* options = OH_ArkUI_CreateRotationTransitionEffect(&rotation); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + OH_ArkUI_AnimateOption_SetDuration(option, DURATION_TIME); + OH_ArkUI_TransitionEffect_SetAnimation(options, option); + auto columnTransition = std::make_shared(); + columnTransition->SetWidth(MIDDLE_LENGTH); + columnTransition->SetHeight(MIDDLE_LENGTH); + columnTransition->SetBackgroundColor(COLOR_RED); + columnTransition->SetTransition(options); + column->AddChild(textNodeTransition); + column->AddChild(columnTransition); + + auto textNodeTransformCenter = std::make_shared(); + textNodeTransformCenter->SetTextContent("transformCenter"); + textNodeTransformCenter->SetWidth(MIDDLE_LENGTH); + textNodeTransformCenter->SetHeight(SMALL_LENGTH); + auto columnTransformCenter = std::make_shared(); + columnTransformCenter->SetWidth(MIDDLE_LENGTH); + columnTransformCenter->SetHeight(MIDDLE_LENGTH); + columnTransformCenter->SetBackgroundColor(COLOR_PINK); + columnTransformCenter->SetRotateTransition(); + columnTransformCenter->SetTransformCenter(NUMBER_20); + column->AddChild(textNodeTransformCenter); + column->AddChild(columnTransformCenter); + + return column; +} + +std::shared_ptr CreateAnimationOpacity() +{ + auto column = std::make_shared(); + auto textNodeOpacityTransition = std::make_shared(); + textNodeOpacityTransition->SetTextContent("OpacityTransition"); + textNodeOpacityTransition->SetWidth(MIDDLE_LENGTH); + textNodeOpacityTransition->SetHeight(SMALL_LENGTH); + auto columnOpacityTransition = std::make_shared(); + columnOpacityTransition->SetWidth(MIDDLE_LENGTH); + columnOpacityTransition->SetHeight(MIDDLE_LENGTH); + columnOpacityTransition->SetBackgroundColor(COLOR_RED); + columnOpacityTransition->SetOpacityTransition(); + column->AddChild(textNodeOpacityTransition); + column->AddChild(columnOpacityTransition); + + auto textNodeRotateTransition = std::make_shared(); + textNodeRotateTransition->SetTextContent("RotateTransition"); + textNodeRotateTransition->SetWidth(MIDDLE_LENGTH); + textNodeRotateTransition->SetHeight(SMALL_LENGTH); + auto columnRotateTransition = std::make_shared(); + columnRotateTransition->SetWidth(MIDDLE_LENGTH); + columnRotateTransition->SetHeight(MIDDLE_LENGTH); + columnRotateTransition->SetBackgroundColor(COLOR_PINK); + columnRotateTransition->SetRotateTransition(); + column->AddChild(textNodeRotateTransition); + column->AddChild(columnRotateTransition); + + auto textNodeScaleTransition = std::make_shared(); + textNodeScaleTransition->SetTextContent("ScaleTransition"); + textNodeScaleTransition->SetWidth(MIDDLE_LENGTH); + textNodeScaleTransition->SetHeight(SMALL_LENGTH); + auto columnScaleTransition = std::make_shared(); + columnScaleTransition->SetWidth(MIDDLE_LENGTH); + columnScaleTransition->SetHeight(MIDDLE_LENGTH); + columnScaleTransition->SetBackgroundColor(COLOR_PINK); + columnScaleTransition->SetScaleTransition(); + column->AddChild(textNodeScaleTransition); + column->AddChild(columnScaleTransition); + + return column; +} + +std::shared_ptr CreateAnimationTranslate() +{ + auto column = std::make_shared(); + auto textNodeTranslateTransition = std::make_shared(); + textNodeTranslateTransition->SetTextContent("TranslateTransition"); + textNodeTranslateTransition->SetWidth(MIDDLE_LENGTH); + textNodeTranslateTransition->SetHeight(SMALL_LENGTH); + auto columnTranslateTransition = std::make_shared(); + columnTranslateTransition->SetWidth(MIDDLE_LENGTH); + columnTranslateTransition->SetHeight(MIDDLE_LENGTH); + columnTranslateTransition->SetBackgroundColor(COLOR_RED); + columnTranslateTransition->SetTranslateTransition(); + column->AddChild(textNodeTranslateTransition); + column->AddChild(columnTranslateTransition); + + auto textNodeMoveTransition = std::make_shared(); + textNodeMoveTransition->SetTextContent("MoveTransition"); + textNodeMoveTransition->SetWidth(MIDDLE_LENGTH); + textNodeMoveTransition->SetHeight(SMALL_LENGTH); + auto columnMoveTransition = std::make_shared(); + columnMoveTransition->SetWidth(MIDDLE_LENGTH); + columnMoveTransition->SetHeight(MIDDLE_LENGTH); + columnMoveTransition->SetBackgroundColor(COLOR_PINK); + columnMoveTransition->SetMoveTransition(); + column->AddChild(textNodeMoveTransition); + column->AddChild(columnMoveTransition); + + return column; +} + +std::shared_ptr CreateAnimationFit() +{ + auto column = std::make_shared(); + auto textNode = std::make_shared(); + textNode->SetTextContent("NODE_RENDER_FIT"); + textNode->SetWidth(MIDDLE_LENGTH); + textNode->SetHeight(SMALL_LENGTH); + + auto text = std::make_shared(); + text->SetWidth(MIDDLE_LENGTH); + text->SetHeight(SMALL_LENGTH); + text->SetBackgroundColor(COLOR_PINK); + text->SetTextContent("NODE_RENDER_FIT"); + text->SetRenderFit(ARKUI_RENDER_FIT_BOTTOM); + + g_keyframe_text = text; + text->RegisterNodeEvent(text->GetHandle(), NODE_ON_CLICK, NUMBER_1, nullptr); + auto onTouch1 = [](ArkUI_NodeEvent *event) { + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUMBER_1) { + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_keyframe_text->GetHandle()); + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + completeCallback->callback = [](void *userData) { + }; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + g_keyframe_text->SetWidth(LARGE_LENGTH); + g_keyframe_text->SetHeight(MIDDLE_LENGTH); + g_keyframe_text->SetBackgroundColor(COLOR_RED); + }; + animateApi->animateTo(context, option, update, completeCallback); + } + }; + text->RegisterNodeEventReceiver(onTouch1); + column->AddChild(textNode); + column->AddChild(text); + + return column; +} + +std::shared_ptr CreateAnimationGeometry() +{ + auto column = std::make_shared(); + auto textNodeTitle1 = std::make_shared(); + textNodeTitle1->SetTextContent("GeometryTransition"); + textNodeTitle1->SetWidth(MIDDLE_LENGTH); + textNodeTitle1->SetHeight(SMALL_LENGTH); + const char* str = "animation"; + auto column1 = std::make_shared(); + column1->SetWidth(MIDDLE_LENGTH); + column1->SetHeight(MIDDLE_LENGTH); + column1->SetBackgroundColor(COLOR_PINK); + column1->SetOpacityTransition(); + column1->SetGeometryTransition(NUMBER_0, str); + + auto column2 = std::make_shared(); + column2->SetWidth(LARGE_LENGTH); + column2->SetHeight(LARGE_LENGTH); + column2->SetBackgroundColor(COLOR_RED); + column2->SetVisibility(ARKUI_VISIBILITY_NONE); + column2->SetGeometryTransition(NUMBER_1, str); + column2->SetOpacityTransition(); + + g_keyframe_column1 = column1; + g_keyframe_column2 = column2; + column1->RegisterNodeEvent(column1->GetHandle(), NODE_ON_CLICK, NUMBER_1, nullptr); + auto onTouch1 = [](ArkUI_NodeEvent *event) { + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUMBER_1) { + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_keyframe_column1->GetHandle()); + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetDuration(option, NUMBER_1000); + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + completeCallback->callback = [](void *userData) { + }; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + g_keyframe_column2->SetVisibility(ARKUI_VISIBILITY_VISIBLE); + g_keyframe_column1->SetVisibility(ARKUI_VISIBILITY_NONE); + }; + animateApi->animateTo(context, option, update, completeCallback); + } + }; + column1->RegisterNodeEventReceiver(onTouch1); + column->AddChild(textNodeTitle1); + column->AddChild(column1); + column->AddChild(column2); + + return column; +} +} // namespace NativeModule + +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIBaseNode.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIBaseNode.h new file mode 100644 index 0000000000000000000000000000000000000000..9931c7d7296b187bbaa88ffabf6f1e5e416b2f66 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIBaseNode.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIBASENODE_H +#define MYAPPLICATION_ARKUIBASENODE_H + +#include +#include +#include + +#include "manager.h" +#include "NativeModule.h" + +namespace NativeModule { + +class ArkUIBaseNode { +public: + explicit ArkUIBaseNode(ArkUI_NodeHandle handle) + : handle_(handle), nativeModule_(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()) {} + + virtual ~ArkUIBaseNode() + { + if (!children_.empty()) { + for (const auto& child : children_) { + nativeModule_->removeChild(handle_, child->GetHandle()); + } + children_.clear(); + } + nativeModule_->disposeNode(handle_); + } + void AddChild(const std::shared_ptr &child) + { + children_.emplace_back(child); + OnAddChild(child); + } + void RemoveChild(const std::shared_ptr &child) + { + children_.remove(child); + OnRemoveChild(child); + } + void InsertChild(const std::shared_ptr &child, int32_t index) + { + if (index >= children_.size()) { + AddChild(child); + } else { + auto iter = children_.begin(); + std::advance(iter, index); + children_.insert(iter, child); + OnInsertChild(child, index); + } + } + ArkUI_NodeHandle GetHandle() const { return handle_; } + ArkUI_NativeNodeAPI_1* GetNativeModule() const + { + return nativeModule_; + } + +protected: + virtual void OnAddChild(const std::shared_ptr &child) {} + virtual void OnRemoveChild(const std::shared_ptr &child) {} + virtual void OnInsertChild(const std::shared_ptr &child, int32_t index) {} + + ArkUI_NodeHandle handle_; + ArkUI_NativeNodeAPI_1 *nativeModule_ = nullptr; + +private: + std::list> children_; +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUIBASENODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIColumnNode.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIColumnNode.h new file mode 100644 index 0000000000000000000000000000000000000000..b51935def52c4e1a5656c2ff53787dae02a8d0d1 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIColumnNode.h @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUICOLUMNNODE_H +#define MYAPPLICATION_ARKUICOLUMNNODE_H + +#include "ArkUINode.h" +#include + +namespace NativeModule { +class ArkUIColumnNode : public ArkUINode { +public: + ArkUIColumnNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_COLUMN)) {} + + void SetTranslate(float x, float y, float z) + { + ArkUI_NumberValue nums[NUMBER_3] = {x, y, z}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + nativeModule_->setAttribute(handle_, NODE_TRANSLATE, &item); + } + void SetScale(float x, float y) + { + ArkUI_NumberValue nums[NUMBER_2] = {x, y}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_2}; + nativeModule_->setAttribute(handle_, NODE_SCALE, &item); + } + void SetRotate(float x, float y, float z, float angle, float center) + { + ArkUI_NumberValue nums[NUMBER_5] = {x, y, z, angle, center}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_5}; + nativeModule_->setAttribute(handle_, NODE_ROTATE, &item); + } + void SetBrightness(float light) + { + ArkUI_NumberValue nums[NUMBER_1] = {light}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BRIGHTNESS, &item); + } + void SetSaturate(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_SATURATION, &item); + } + int32_t SetLinearGradient(float angle, int32_t direction, int32_t repeat) + { + ArkUI_NumberValue nums[NUMBER_3]; + nums[NUMBER_0].f32 = angle; + nums[NUMBER_1].i32 = direction; + nums[NUMBER_2].i32 = repeat; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3, .object = &colorStop}; + auto err = nativeModule_->setAttribute(handle_, NODE_LINEAR_GRADIENT, &item); + return err; + } + void SetOpacity(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_OPACITY, &item); + } + void SetBorderRadius(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BORDER_RADIUS, &item); + } + int32_t SetClip(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].i32 = number; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_CLIP, &item); + return err; + } + int32_t SetCircleShape(int32_t number, float width, float height) + { + ArkUI_NumberValue nums[NUMBER_3]; + nums[NUMBER_0].i32 = number; + nums[NUMBER_1].f32 = width; + nums[NUMBER_2].f32 = height; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_CLIP_SHAPE, &item); + return err; + } + int32_t SetTransform() + { + ArkUI_NumberValue value2[NUMBER_16]; + for (int i = NUMBER_0; i < NUMBER_16; i++) { + value2[i].f32 = NUMBER_0; + } + value2[NUMBER_0].f32 = NUMBER_1; + value2[NUMBER_1].f32 = NUMBER_1; + ArkUI_AttributeItem item = { .value = value2, .size = NUMBER_3 }; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSFORM, &item); + return err; + } + int32_t SetShadow(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_0]; + nums[NUMBER_0].i32 = number; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_SHADOW, &item); + return err; + } + int32_t SetBackgroundBlurStyle(int32_t number) + { + ArkUI_NumberValue blurStyle[NUMBER_6]; + blurStyle[NUMBER_0].i32 = number; + blurStyle[NUMBER_2].i32 = ARKUI_ADAPTIVE_COLOR_AVERAGE; + ArkUI_AttributeItem item = { .value = blurStyle, .size = NUMBER_2}; + auto err = nativeModule_->setAttribute(handle_, NODE_BACKGROUND_BLUR_STYLE, &item); + return err; + } + int32_t SetTransformCenter(float number) + { + ArkUI_NumberValue centerPointArray[] = {number}; + ArkUI_AttributeItem item = { .value = centerPointArray, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSFORM_CENTER, &item); + return err; + } + int32_t SetSweepGradient() + { + ArkUI_NumberValue nums[NUMBER_6]; + nums[NUMBER_0].f32 = SMALL_LENGTH; + nums[NUMBER_1].f32 = SMALL_LENGTH; + nums[NUMBER_2].f32 = NUMBER_0; + nums[NUMBER_3].f32 = NUMBER_359; + nums[NUMBER_4].f32 = NUMBER_45; + nums[NUMBER_5].f32 = NUMBER_1; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_6, .object = &colorStop }; + auto err = nativeModule_->setAttribute(handle_, NODE_SWEEP_GRADIENT, &item); + return err; + } + int32_t SetRadialGradient() + { + ArkUI_NumberValue nums[NUMBER_4]; + nums[NUMBER_0].f32 = SMALL_LENGTH; + nums[NUMBER_1].f32 = SMALL_LENGTH; + nums[NUMBER_2].f32 = NUMBER_60; + nums[NUMBER_3].f32 = NUMBER_1; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_4, .object = &colorStop }; + auto err = nativeModule_->setAttribute(handle_, NODE_RADIAL_GRADIENT, &item); + return err; + } + int32_t SetMask() + { + ArkUI_NumberValue nums[NUMBER_4]; + nums[NUMBER_0].i32 = ARKUI_MASK_TYPE_PROGRESS; + nums[NUMBER_1].f32 = NUMBER_10; + nums[NUMBER_2].f32 = NUMBER_100; + nums[NUMBER_3].u32 = COLOR_WHITE; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_4 }; + auto err = nativeModule_->setAttribute(handle_, NODE_MASK, &item); + return err; + } + int32_t SetGrayScale(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_GRAY_SCALE, &item); + return err; + } + int32_t SetInvert(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_INVERT, &item); + return err; + } + int32_t SetSepia(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_SEPIA, &item); + return err; + } + int32_t SetContrast(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_CONTRAST, &item); + return err; + } + int32_t SetColumnJustifyContent(int32_t number) + { + ArkUI_NumberValue nums[] = { { .i32 = number } }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_COLUMN_JUSTIFY_CONTENT, &item); + return err; + } + ~ArkUIColumnNode() override {} +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUILISTNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUINode.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUINode.h new file mode 100644 index 0000000000000000000000000000000000000000..7ee5b530c0fe34a89389bf287793435568397196 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUINode.h @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUINODE_H +#define MYAPPLICATION_ARKUINODE_H + +#include "ArkUIBaseNode.h" +#include "NativeModule.h" +#include +#include +#include +#include +#include "ArkUINumber.h" + +namespace NativeModule { +class ArkUINode : public ArkUIBaseNode { +public: + explicit ArkUINode(ArkUI_NodeHandle handle) : ArkUIBaseNode(handle) {} + + ~ArkUINode() override {} + + void SetWidth(float width) + { + ArkUI_NumberValue value[] = {{.f32 = width}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_WIDTH, &item); + } + void SetPercentWidth(float percent) + { + ArkUI_NumberValue value[] = {{.f32 = percent}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_WIDTH_PERCENT, &item); + } + void SetHeight(float height) + { + ArkUI_NumberValue value[] = {{.f32 = height}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_HEIGHT, &item); + } + void SetPercentHeight(float percent) + { + ArkUI_NumberValue value[] = {{.f32 = percent}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_HEIGHT_PERCENT, &item); + } + void SetBackgroundColor(uint32_t color) + { + ArkUI_NumberValue value[] = {{.u32 = color}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BACKGROUND_COLOR, &item); + } + int32_t SetZIndex(int32_t number) + { + ArkUI_NumberValue value[] = {{.i32 = number}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_Z_INDEX, &item); + return err; + } + int32_t SetForegroundColor(uint32_t color) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].u32 = color; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_FOREGROUND_COLOR, &item); + return err; + } + int32_t SetMarkAnchor(float x, float y) + { + ArkUI_NumberValue nums[NUMBER_2] = {x, y}; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_2}; + auto err = nativeModule_->setAttribute(handle_, NODE_MARK_ANCHOR, &item); + return err; + } + int32_t SetVisibility(int32_t visibility) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].i32 = visibility; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_VISIBILITY, &item); + return err; + } + void RegisterNodeEvent(ArkUI_NodeHandle node, + ArkUI_NodeEventType eventType, int32_t targetId, void* userData) + { + nativeModule_->registerNodeEvent(node, eventType, targetId, userData); + } + void RegisterNodeEventReceiver(void (*eventReceiver)(ArkUI_NodeEvent* event)) + { + nativeModule_->registerNodeEventReceiver(eventReceiver); + } + int32_t SetOpacityTransition() + { + ArkUI_NumberValue opacityTransition[] = { + NUMBER_02, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_EASE_IN_OUT) } + }; + ArkUI_AttributeItem item = { .value = opacityTransition, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_OPACITY_TRANSITION, &item); + return err; + } + int32_t SetRotateTransition() + { + ArkUI_NumberValue rotateTransition[] = { + NUMBER_00, + NUMBER_00, + NUMBER_1F, + NUMBER_180, + NUMBER_0, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = rotateTransition, .size = NUMBER_7}; + auto err = nativeModule_->setAttribute(handle_, NODE_ROTATE_TRANSITION, &item); + return err; + } + int32_t SetScaleTransition() + { + ArkUI_NumberValue scaleTransition[] = { + NUMBER_00, + NUMBER_00, + NUMBER_00, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = scaleTransition, .size = NUMBER_5}; + auto err = nativeModule_->setAttribute(handle_, NODE_SCALE_TRANSITION, &item); + return err; + } + int32_t SetTranslateTransition() + { + ArkUI_NumberValue translateTransition[] = { + NUMBER_100F, + NUMBER_100F, + NUMBER_00, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = translateTransition, .size = NUMBER_5}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSLATE_TRANSITION, &item); + return err; + } + int32_t SetMoveTransition() + { + ArkUI_NumberValue translateTransition[] = { + {.i32 = ARKUI_TRANSITION_EDGE_START }, + {.i32 = NUMBER_3000 }, + {.i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = translateTransition, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_MOVE_TRANSITION, &item); + return err; + } + int32_t SetForegroundBlurStyle(int32_t number) + { + ArkUI_NumberValue nums[] = { { .i32 = number} }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_FOREGROUND_BLUR_STYLE, &item); + return err; + } + int32_t SetColorBlend(uint32_t color) + { + ArkUI_NumberValue nums[] = { { .u32 = color} }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_COLOR_BLEND, &item); + return err; + } + int32_t SetTransition(ArkUI_TransitionEffect* effect) + { + ArkUI_AttributeItem item = { .object = effect}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSITION, &item); + return err; + } + int32_t SetBackdropBlur(float round) + { + ArkUI_NumberValue nums[] = { round, NUMBER_100, NUMBER_100 }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_BACKDROP_BLUR, &item); + return err; + } + void SetTranslateWithPercent(float x, float y, float z) + { + ArkUI_NumberValue nums[NUMBER_3] = {x, y, z}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + nativeModule_->setAttribute(handle_, NODE_TRANSLATE_WITH_PERCENT, &item); + } + void SetRotateAngle(float x, float y, float z, float see) + { + ArkUI_NumberValue nums[NUMBER_4] = {x, y, z, see}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_4}; + nativeModule_->setAttribute(handle_, NODE_ROTATE_ANGLE, &item); + } + int32_t SetGeometryTransition(int32_t share, const char* str) + { + ArkUI_NumberValue nums[NUMBER_1] = { {.i32 = share} }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1, .string = str}; + auto err = nativeModule_->setAttribute(handle_, NODE_GEOMETRY_TRANSITION, &item); + return err; + } + int32_t SetCustomShadow() + { + ArkUI_NumberValue nums[NUMBER_7] = { + NUMBER_20, + {.i32 = NUMBER_0 }, + SMALL_LENGTH, + SMALL_LENGTH, + { .i32 = ARKUI_SHADOW_TYPE_COLOR }, + { .u32 = COLOR_RED }, + { .u32 = NUMBER_0 } + }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_7}; + auto err = nativeModule_->setAttribute(handle_, NODE_CUSTOM_SHADOW, &item); + return err; + } + int32_t SetBlur(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_BLUR, &item); + return err; + } + int32_t SetBackGroundImage(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_BLUR, &item); + return err; + } + int32_t SetRenderFit(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_RENDER_FIT, &item); + return err; + } + int32_t SetRenderGroup(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_1] = { { .i32 = number } }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_RENDER_GROUP, &item); + return err; + } +protected: + void OnAddChild(const std::shared_ptr &child) override + { + nativeModule_->addChild(handle_, child->GetHandle()); + } + void OnRemoveChild(const std::shared_ptr &child) override + { + nativeModule_->removeChild(handle_, child->GetHandle()); + } + void OnInsertChild(const std::shared_ptr &child, int32_t index) override + { + nativeModule_->insertChildAt(handle_, child->GetHandle(), index); + } +}; +} // namespace NativeModule +#endif // MYAPPLICATION_ARKUINODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUINumber.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUINumber.h new file mode 100644 index 0000000000000000000000000000000000000000..8c38b168a8978d27e49da212d1c3f130d5047be0 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUINumber.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUINUMBER_H +#define ARKUINUMBER_H +namespace NativeModule { +constexpr uint32_t COLOR_1 = 0x33FF0000; +constexpr uint32_t COLOR_2 = 0x3300FF00; +constexpr uint32_t COLOR_3 = 0x330000FF; +constexpr uint32_t COLOR_BLACK = 0xFF000000; +constexpr uint32_t COLOR_PINK = 0x33FF0000; +constexpr uint32_t COLOR_RED = 0xFFFF0000; +constexpr uint32_t COLOR_WHITE = 0xFFFFFFFF; +constexpr uint32_t COLOR_YELLOW = 0xFF0000FF; +constexpr int32_t DURATION_TIME = 2000; +constexpr int32_t LARGE_LENGTH = 300; +constexpr int32_t MIDDLE_LENGTH = 200; +constexpr int32_t NUMBER_0 = 0; +constexpr float NUMBER_00 = 0.0; +constexpr float NUMBER_01 = 0.1; +constexpr float NUMBER_02 = 0.2; +constexpr float NUMBER_03 = 0.3; +constexpr float NUMBER_04 = 0.4; +constexpr float NUMBER_05 = 0.5; +constexpr float NUMBER_06 = 0.6; +constexpr int32_t NUMBER_1 = 1; +constexpr float NUMBER_1F = 1.0; +constexpr int32_t NUMBER_2 = 2; +constexpr int32_t NUMBER_3 = 3; +constexpr int32_t NUMBER_4 = 4; +constexpr int32_t NUMBER_5 = 5; +constexpr int32_t NUMBER_6 = 6; +constexpr int32_t NUMBER_7 = 7; +constexpr int32_t NUMBER_10 = 10; +constexpr int32_t NUMBER_16 = 16; +constexpr int32_t NUMBER_20 = 20; +constexpr int32_t NUMBER_25 = 25; +constexpr int32_t NUMBER_30 = 30; +constexpr int32_t NUMBER_45 = 45; +constexpr int32_t NUMBER_60 = 60; +constexpr int32_t NUMBER_90 = 90; +constexpr int32_t NUMBER_100 = 100; +constexpr float NUMBER_100F = 100.0; +constexpr int32_t NUMBER_150 = 150; +constexpr int32_t NUMBER_180 = 180; +constexpr int32_t NUMBER_1000 = 1000; +constexpr int32_t NUMBER_3000 = 3000; +constexpr int32_t NUMBER_359 = 359; +constexpr int32_t SMALL_LENGTH = 50; +} +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUITextNode.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUITextNode.h new file mode 100644 index 0000000000000000000000000000000000000000..0426e46b14131d0f6adb02ff956d13733441b45f --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUITextNode.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// ArkUITextNode.h +#ifndef MYAPPLICATION_ARKUITEXTNODE_H +#define MYAPPLICATION_ARKUITEXTNODE_H + +#include "ArkUINode.h" + +#include + +namespace NativeModule { +class ArkUITextNode : public ArkUINode { +public: + ArkUITextNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_TEXT)) {} + void SetFontSize(float fontSize) + { + ArkUI_NumberValue value[] = {{.f32 = fontSize}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_FONT_SIZE, &item); + } + void SetFontColor(uint32_t color) + { + ArkUI_NumberValue value[] = {{.u32 = color}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_FONT_COLOR, &item); + } + void SetTextContent(const std::string &content) + { + ArkUI_AttributeItem item = {nullptr, 0, content.c_str()}; + nativeModule_->setAttribute(handle_, NODE_TEXT_CONTENT, &item); + } + void SetTextAlign(ArkUI_TextAlignment align) + { + ArkUI_NumberValue value[] = {{.i32 = align}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_TEXT_ALIGN, &item); + } +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUITEXTNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIVisualEffectsNode.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIVisualEffectsNode.h new file mode 100644 index 0000000000000000000000000000000000000000..c9aa7abcc207d55694d1cc6015242e4a8aa5ab92 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/ArkUIVisualEffectsNode.h @@ -0,0 +1,468 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIVISUALEFFECTSNODE_H +#define MYAPPLICATION_ARKUIVISUALEFFECTSNODE_H +#include "ArkUIColumnNode.h" +#include "ArkUITextNode.h" +#include + +namespace NativeModule { +std::shared_ptr CreateVisualEffectsScale() +{ + auto column = std::make_shared(); + auto textNodeTran = std::make_shared(); + textNodeTran->SetTextContent("translate"); + textNodeTran->SetWidth(MIDDLE_LENGTH); + textNodeTran->SetHeight(SMALL_LENGTH); + auto columnTran = std::make_shared(); + columnTran->SetWidth(SMALL_LENGTH); + columnTran->SetHeight(SMALL_LENGTH); + columnTran->SetBackgroundColor(COLOR_PINK); + columnTran->SetTranslate(SMALL_LENGTH, NUMBER_0, NUMBER_0); + + auto textNodeScale = std::make_shared(); + textNodeScale->SetTextContent("scale"); + textNodeScale->SetWidth(MIDDLE_LENGTH); + textNodeScale->SetHeight(SMALL_LENGTH); + auto columnScale = std::make_shared(); + columnScale->SetWidth(SMALL_LENGTH); + columnScale->SetHeight(SMALL_LENGTH); + columnScale->SetBackgroundColor(COLOR_PINK); + columnScale->SetScale(NUMBER_2, NUMBER_05); + + auto textNodeRotate = std::make_shared(); + textNodeRotate->SetTextContent("rotate"); + textNodeRotate->SetWidth(SMALL_LENGTH); + textNodeRotate->SetHeight(SMALL_LENGTH); + auto columnRotate = std::make_shared(); + columnRotate->SetWidth(SMALL_LENGTH); + columnRotate->SetHeight(SMALL_LENGTH); + columnRotate->SetBackgroundColor(COLOR_PINK); + columnRotate->SetRotate(NUMBER_0, NUMBER_0, NUMBER_1, LARGE_LENGTH, NUMBER_0); + + column->AddChild(textNodeTran); + column->AddChild(columnTran); + column->AddChild(textNodeScale); + column->AddChild(columnScale); + column->AddChild(textNodeRotate); + column->AddChild(columnRotate); + + return column; +} + +std::shared_ptr CreateVisualEffectsBlur() +{ + auto column = std::make_shared(); + auto textNodeBrightness = std::make_shared(); + textNodeBrightness->SetTextContent("Brightness"); + textNodeBrightness->SetWidth(MIDDLE_LENGTH); + textNodeBrightness->SetHeight(SMALL_LENGTH); + auto columnBrightness = std::make_shared(); + columnBrightness->SetWidth(NUMBER_100); + columnBrightness->SetHeight(NUMBER_100); + columnBrightness->SetBackgroundColor(COLOR_PINK); + columnBrightness->SetBrightness(NUMBER_05); + column->AddChild(textNodeBrightness); + column->AddChild(columnBrightness); + + auto textNodeSaturate = std::make_shared(); + textNodeSaturate->SetTextContent("saturate"); + textNodeSaturate->SetWidth(MIDDLE_LENGTH); + textNodeSaturate->SetHeight(SMALL_LENGTH); + auto columnSaturate = std::make_shared(); + columnSaturate->SetWidth(NUMBER_100); + columnSaturate->SetHeight(NUMBER_100); + columnSaturate->SetBackgroundColor(COLOR_PINK); + columnSaturate->SetSaturate(NUMBER_30); + column->AddChild(textNodeSaturate); + column->AddChild(columnSaturate); + + auto textNodeBlur = std::make_shared(); + textNodeBlur->SetTextContent("blur"); + textNodeBlur->SetWidth(MIDDLE_LENGTH); + textNodeBlur->SetHeight(SMALL_LENGTH); + + auto text = std::make_shared(); + text->SetTextContent("NODE_BLUR"); + text->SetWidth(MIDDLE_LENGTH); + text->SetHeight(NUMBER_100); + text->SetBackgroundColor(COLOR_PINK); + text->SetBlur(NUMBER_10); + column->AddChild(textNodeBlur); + column->AddChild(text); + + return column; +} + +std::shared_ptr CreateVisualEffectsShape() +{ + auto column = std::make_shared(); + auto textNodeLinearGradient = std::make_shared(); + textNodeLinearGradient->SetTextContent("linearGradient"); + textNodeLinearGradient->SetWidth(MIDDLE_LENGTH); + textNodeLinearGradient->SetHeight(SMALL_LENGTH); + auto columnLinearGradient = std::make_shared(); + columnLinearGradient->SetWidth(NUMBER_100); + columnLinearGradient->SetHeight(NUMBER_100); + columnLinearGradient->SetLinearGradient(NUMBER_90, ARKUI_LINEAR_GRADIENT_DIRECTION_CUSTOM, NUMBER_0); + column->AddChild(textNodeLinearGradient); + column->AddChild(columnLinearGradient); + + auto textNodeOpacity = std::make_shared(); + textNodeOpacity->SetTextContent("opacity"); + textNodeOpacity->SetWidth(MIDDLE_LENGTH); + textNodeOpacity->SetHeight(SMALL_LENGTH); + auto columnOpacity = std::make_shared(); + columnOpacity->SetWidth(NUMBER_100); + columnOpacity->SetHeight(NUMBER_100); + columnOpacity->SetBackgroundColor(COLOR_PINK); + columnOpacity->SetOpacity(NUMBER_03); + column->AddChild(textNodeOpacity); + column->AddChild(columnOpacity); + + auto textNodeClip = std::make_shared(); + textNodeClip->SetTextContent("clip"); + textNodeClip->SetWidth(MIDDLE_LENGTH); + textNodeClip->SetHeight(SMALL_LENGTH); + auto columnInside = std::make_shared(); + columnInside->SetWidth(NUMBER_100); + columnInside->SetHeight(NUMBER_100); + columnInside->SetBackgroundColor(COLOR_PINK); + columnInside->SetBorderRadius(NUMBER_20); + auto columnClip = std::make_shared(); + columnClip->SetBorderRadius(NUMBER_20); + columnClip->SetClip(NUMBER_1); + columnClip->AddChild(columnInside); + column->AddChild(textNodeClip); + column->AddChild(columnClip); + + return column; +} + +std::shared_ptr CreateVisualEffectsShadow() +{ + auto column = std::make_shared(); + auto textNodeCircleShape = std::make_shared(); + textNodeCircleShape->SetTextContent("CircleShape"); + textNodeCircleShape->SetWidth(MIDDLE_LENGTH); + textNodeCircleShape->SetHeight(SMALL_LENGTH); + auto columnCircleShape = std::make_shared(); + columnCircleShape->SetWidth(MIDDLE_LENGTH); + columnCircleShape->SetHeight(MIDDLE_LENGTH); + columnCircleShape->SetBackgroundColor(COLOR_PINK); + columnCircleShape->SetCircleShape(ARKUI_CLIP_TYPE_CIRCLE, MIDDLE_LENGTH, MIDDLE_LENGTH); + column->AddChild(textNodeCircleShape); + column->AddChild(columnCircleShape); + + auto textNodeTransform = std::make_shared(); + textNodeTransform->SetTextContent("Transform"); + textNodeTransform->SetWidth(MIDDLE_LENGTH); + textNodeTransform->SetHeight(SMALL_LENGTH); + auto columnTransform = std::make_shared(); + columnTransform->SetWidth(MIDDLE_LENGTH); + columnTransform->SetHeight(MIDDLE_LENGTH); + columnTransform->SetBackgroundColor(COLOR_PINK); + columnTransform->SetTransform(); + column->AddChild(textNodeTransform); + column->AddChild(columnTransform); + + auto textNodeShadow = std::make_shared(); + textNodeShadow->SetTextContent("Shadow"); + textNodeShadow->SetWidth(MIDDLE_LENGTH); + textNodeShadow->SetHeight(SMALL_LENGTH); + auto columnShadow = std::make_shared(); + columnShadow->SetWidth(MIDDLE_LENGTH); + columnShadow->SetHeight(MIDDLE_LENGTH); + columnShadow->SetBackgroundColor(COLOR_PINK); + columnShadow->SetShadow(ARKUI_SHADOW_STYLE_OUTER_DEFAULT_LG); + column->AddChild(textNodeShadow); + column->AddChild(columnShadow); + + return column; +} + +std::shared_ptr CreateVisualEffectsSepia() +{ + auto column = std::make_shared(); + auto textNodeSweepGradient = std::make_shared(); + textNodeSweepGradient->SetTextContent("sweepGradient"); + textNodeSweepGradient->SetWidth(MIDDLE_LENGTH); + textNodeSweepGradient->SetHeight(SMALL_LENGTH); + auto columnSweepGradient = std::make_shared(); + columnSweepGradient->SetWidth(MIDDLE_LENGTH); + columnSweepGradient->SetHeight(MIDDLE_LENGTH); + columnSweepGradient->SetBackgroundColor(COLOR_PINK); + columnSweepGradient->SetSweepGradient(); + column->AddChild(textNodeSweepGradient); + column->AddChild(columnSweepGradient); + + auto textNodeRadialGradient = std::make_shared(); + textNodeRadialGradient->SetTextContent("radialGradient"); + textNodeRadialGradient->SetWidth(MIDDLE_LENGTH); + textNodeRadialGradient->SetHeight(SMALL_LENGTH); + auto columnRadialGradient = std::make_shared(); + columnRadialGradient->SetWidth(MIDDLE_LENGTH); + columnRadialGradient->SetHeight(MIDDLE_LENGTH); + columnSweepGradient->SetBackgroundColor(COLOR_PINK); + columnRadialGradient->SetRadialGradient(); + column->AddChild(textNodeRadialGradient); + column->AddChild(columnRadialGradient); + + auto textNodeMask = std::make_shared(); + textNodeMask->SetTextContent("mask"); + textNodeMask->SetWidth(MIDDLE_LENGTH); + textNodeMask->SetHeight(SMALL_LENGTH); + auto columnMask = std::make_shared(); + columnMask->SetWidth(MIDDLE_LENGTH); + columnMask->SetHeight(MIDDLE_LENGTH); + columnMask->SetBackgroundColor(COLOR_PINK); + columnMask->SetMask(); + column->AddChild(textNodeMask); + column->AddChild(columnMask); + + return column; +} + +std::shared_ptr CreateVisualEffectsMask() +{ + auto column = std::make_shared(); + auto textNodeGrayScale = std::make_shared(); + textNodeGrayScale->SetTextContent("GrayScale"); + textNodeGrayScale->SetWidth(MIDDLE_LENGTH); + textNodeGrayScale->SetHeight(SMALL_LENGTH); + auto columnGrayScale = std::make_shared(); + columnGrayScale->SetWidth(MIDDLE_LENGTH); + columnGrayScale->SetHeight(MIDDLE_LENGTH); + columnGrayScale->SetBackgroundColor(COLOR_PINK); + columnGrayScale->SetGrayScale(NUMBER_05); + column->AddChild(textNodeGrayScale); + column->AddChild(columnGrayScale); + + auto textNodeInvert = std::make_shared(); + textNodeInvert->SetTextContent("Invert"); + textNodeInvert->SetWidth(MIDDLE_LENGTH); + textNodeInvert->SetHeight(SMALL_LENGTH); + auto columnInvert = std::make_shared(); + columnInvert->SetWidth(MIDDLE_LENGTH); + columnInvert->SetHeight(MIDDLE_LENGTH); + columnInvert->SetBackgroundColor(COLOR_PINK); + columnInvert->SetInvert(NUMBER_05); + column->AddChild(textNodeInvert); + column->AddChild(columnInvert); + + auto textNodeSepia = std::make_shared(); + textNodeSepia->SetTextContent("Sepia"); + textNodeSepia->SetWidth(MIDDLE_LENGTH); + textNodeSepia->SetHeight(SMALL_LENGTH); + auto columnSepia = std::make_shared(); + columnSepia->SetWidth(MIDDLE_LENGTH); + columnSepia->SetHeight(MIDDLE_LENGTH); + columnSepia->SetBackgroundColor(COLOR_PINK); + columnSepia->SetSepia(NUMBER_05); + column->AddChild(textNodeSepia); + column->AddChild(columnSepia); + + return column; +} + +std::shared_ptr CreateVisualEffectsCont() +{ + auto column = std::make_shared(); + auto textNodeContrast = std::make_shared(); + textNodeContrast->SetTextContent("Contrast"); + textNodeContrast->SetWidth(MIDDLE_LENGTH); + textNodeContrast->SetHeight(SMALL_LENGTH); + auto columnContrast = std::make_shared(); + columnContrast->SetWidth(MIDDLE_LENGTH); + columnContrast->SetHeight(MIDDLE_LENGTH); + columnContrast->SetBackgroundColor(COLOR_PINK); + columnContrast->SetContrast(NUMBER_01); + column->AddChild(textNodeContrast); + column->AddChild(columnContrast); + + auto columBlank = std::make_shared(); + columBlank->SetHeight(NUMBER_20); + column->AddChild(columBlank); + + auto textNodeForegroundColor = std::make_shared(); + textNodeForegroundColor->SetTextContent("ForegroundColor"); + textNodeForegroundColor->SetWidth(MIDDLE_LENGTH); + textNodeForegroundColor->SetHeight(SMALL_LENGTH); + textNodeForegroundColor->SetBackgroundColor(COLOR_PINK); + textNodeForegroundColor->SetForegroundColor(COLOR_RED); + column->AddChild(textNodeForegroundColor); + + auto textNodeMarkAnchor = std::make_shared(); + textNodeMarkAnchor->SetTextContent("MarkAnchor"); + textNodeMarkAnchor->SetWidth(MIDDLE_LENGTH); + textNodeMarkAnchor->SetHeight(SMALL_LENGTH); + auto columnMarkAnchor = std::make_shared(); + columnMarkAnchor->SetWidth(MIDDLE_LENGTH); + columnMarkAnchor->SetHeight(MIDDLE_LENGTH); + columnMarkAnchor->SetBackgroundColor(COLOR_PINK); + auto textNode = std::make_shared(); + textNode->SetTextContent("text"); + textNode->SetHeight(NUMBER_25); + textNode->SetHeight(NUMBER_25); + textNode->SetMarkAnchor(NUMBER_25, NUMBER_25); + column->AddChild(textNodeMarkAnchor); + column->AddChild(columnMarkAnchor); + column->AddChild(textNode); + + return column; +} + +std::shared_ptr CreateVisualEffectsAngle() +{ + auto column = std::make_shared(); + auto textNodeTranslateWithPercent = std::make_shared(); + textNodeTranslateWithPercent->SetTextContent("TranslateWithPercent"); + textNodeTranslateWithPercent->SetWidth(MIDDLE_LENGTH); + textNodeTranslateWithPercent->SetHeight(SMALL_LENGTH); + auto columnTranslateWithPercent = std::make_shared(); + columnTranslateWithPercent->SetWidth(MIDDLE_LENGTH); + columnTranslateWithPercent->SetHeight(MIDDLE_LENGTH); + columnTranslateWithPercent->SetBackgroundColor(COLOR_PINK); + columnTranslateWithPercent->SetTranslateWithPercent(NUMBER_04, NUMBER_02, NUMBER_0); + column->AddChild(textNodeTranslateWithPercent); + column->AddChild(columnTranslateWithPercent); + + auto textNodeRotateAngle = std::make_shared(); + textNodeRotateAngle->SetTextContent("RotateAngle"); + textNodeRotateAngle->SetWidth(MIDDLE_LENGTH); + textNodeRotateAngle->SetHeight(SMALL_LENGTH); + auto columnRotateAngle = std::make_shared(); + columnRotateAngle->SetWidth(MIDDLE_LENGTH); + columnRotateAngle->SetHeight(MIDDLE_LENGTH); + columnRotateAngle->SetBackgroundColor(COLOR_PINK); + columnRotateAngle->SetRotateAngle(NUMBER_45, NUMBER_45, NUMBER_0, NUMBER_0); + column->AddChild(textNodeRotateAngle); + column->AddChild(columnRotateAngle); + + auto textNodeCustomShadow = std::make_shared(); + textNodeCustomShadow->SetTextContent("CustomShadow"); + textNodeCustomShadow->SetWidth(MIDDLE_LENGTH); + textNodeCustomShadow->SetHeight(SMALL_LENGTH); + auto columnCustomShadow = std::make_shared(); + columnCustomShadow->SetWidth(MIDDLE_LENGTH); + columnCustomShadow->SetHeight(MIDDLE_LENGTH); + columnCustomShadow->SetBackgroundColor(COLOR_PINK); + columnCustomShadow->SetCustomShadow(); + column->AddChild(textNodeCustomShadow); + column->AddChild(columnCustomShadow); + + return column; +} + +std::shared_ptr CreateVisualEffectsStyle() +{ + auto column = std::make_shared(); + auto textNodeBlurStyle = std::make_shared(); + textNodeBlurStyle->SetTextContent("BackgroundBlurStyle"); + textNodeBlurStyle->SetWidth(MIDDLE_LENGTH); + textNodeBlurStyle->SetHeight(SMALL_LENGTH); + auto columnBlurStyle = std::make_shared(); + columnBlurStyle->SetWidth(MIDDLE_LENGTH); + columnBlurStyle->SetHeight(MIDDLE_LENGTH); + columnBlurStyle->SetBackgroundColor(COLOR_PINK); + columnBlurStyle->SetBackgroundBlurStyle(ARKUI_BLUR_STYLE_THICK); + column->AddChild(textNodeBlurStyle); + column->AddChild(columnBlurStyle); + + auto textNodeForegroundBlurStyle = std::make_shared(); + textNodeForegroundBlurStyle->SetTextContent("ForegroundBlurStyle"); + textNodeForegroundBlurStyle->SetWidth(MIDDLE_LENGTH); + textNodeForegroundBlurStyle->SetHeight(SMALL_LENGTH); + auto columnTextNode = std::make_shared(); + columnTextNode->SetTextContent("厚材质模糊"); + columnTextNode->SetWidth(MIDDLE_LENGTH); + columnTextNode->SetHeight(SMALL_LENGTH); + columnTextNode->SetBackgroundColor(COLOR_PINK); + columnTextNode->SetForegroundBlurStyle(ARKUI_BLUR_STYLE_THICK); + column->AddChild(textNodeForegroundBlurStyle); + column->AddChild(columnTextNode); + + auto textNodeColorBlend = std::make_shared(); + textNodeColorBlend->SetTextContent("ColorBlend"); + textNodeColorBlend->SetWidth(MIDDLE_LENGTH); + textNodeColorBlend->SetHeight(SMALL_LENGTH); + auto columnColorBlend = std::make_shared(); + columnColorBlend->SetWidth(MIDDLE_LENGTH); + columnColorBlend->SetHeight(MIDDLE_LENGTH); + columnColorBlend->SetBackgroundColor(COLOR_YELLOW); + columnColorBlend->SetColorBlend(COLOR_RED); + column->AddChild(textNodeColorBlend); + column->AddChild(columnColorBlend); + + return column; +} + +std::shared_ptr CreateVisualEffectsGroup() +{ + auto column = std::make_shared(); + auto textNodeBackdropBlur = std::make_shared(); + textNodeBackdropBlur->SetTextContent("BackdropBlur"); + textNodeBackdropBlur->SetWidth(MIDDLE_LENGTH); + textNodeBackdropBlur->SetHeight(SMALL_LENGTH); + textNodeBackdropBlur->SetBackgroundColor(COLOR_PINK); + auto textNode = std::make_shared(); + textNode->SetTextContent("backdropBlur"); + textNode->SetWidth(MIDDLE_LENGTH); + textNode->SetHeight(MIDDLE_LENGTH); + textNode->SetBackgroundColor(COLOR_PINK); + textNode->SetBackdropBlur(NUMBER_20); + column->AddChild(textNodeBackdropBlur); + column->AddChild(textNode); + + auto textNodeRenderGroup = std::make_shared(); + textNodeRenderGroup->SetTextContent("RenderGroup"); + textNodeRenderGroup->SetWidth(MIDDLE_LENGTH); + textNodeRenderGroup->SetHeight(SMALL_LENGTH); + auto column1 = std::make_shared(); + column1->SetWidth(MIDDLE_LENGTH); + column1->SetHeight(MIDDLE_LENGTH); + column1->SetBackgroundColor(COLOR_BLACK); + column1->SetOpacity(NUMBER_1); + column1->SetColumnJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + + auto column2 = std::make_shared(); + column2->SetWidth(NUMBER_150); + column2->SetHeight(NUMBER_150); + column2->SetBackgroundColor(COLOR_WHITE); + column2->SetColumnJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + column2->SetOpacity(NUMBER_06); + column2->SetRenderGroup(NUMBER_1); + + auto column3 = std::make_shared(); + column3->SetWidth(NUMBER_100); + column3->SetHeight(NUMBER_100); + column3->SetBackgroundColor(COLOR_BLACK); + column3->SetOpacity(NUMBER_1); + column3->SetColumnJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + + column->AddChild(textNodeRenderGroup); + column->AddChild(column1); + column1->AddChild(column2); + column2->AddChild(column3); + column->AddChild(column1); + + return column; +} + + +} // namespace NativeModule + +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e327511a5b6215608526c8fd1ee59492e6c0c96 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,18 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(native_node_napi) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp manager.cpp NavigationContext.cpp AccessibilityMaker.cpp EmbeddedComponentMaker.cpp) + +find_library(hilog-lib hilog_ndk.z) + +find_library(libace-lib ace_ndk.z) + +find_library(libnapi-lib ace_napi.z) + +target_link_libraries(entry PUBLIC ${hilog-lib} ${libace-lib} ${libnapi-lib} libability_base_want.so) \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/EmbeddedComponentMaker.cpp b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/EmbeddedComponentMaker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9ca27d9e301430d88cfc1c0e3062c4560fe3732 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/EmbeddedComponentMaker.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "EmbeddedComponentMaker.h" +#include +#include +#include +#include + +constexpr float TEXT_WIDTH_PX = 300.0f; +constexpr float TEXT_HEIGHT_PX = 100.0f; +constexpr int EMBEDDED_COMPONENT_WIDTH = 480; +constexpr int WANT_STR_BUF_LEN = 10; +constexpr int WANT_STR_COPY_LEN = 5; +constexpr int WANT_URI_BUF_LEN = 10; +constexpr int WANT_URI_COPY_LEN = 5; +constexpr float COL_WIDTH_PX = 300.0f; +static ArkUI_EmbeddedComponentOption* embeddedComponentOption_; + +ArkUI_NodeHandle EmbeddedComponentMaker::CreateNativeNode() +{ + ArkUI_NativeNodeAPI_1 *nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + if (nodeApi == nullptr) { + return nullptr; + } + // 创建一个Column容器组件 + ArkUI_NodeHandle column = BuildColumnNode(nodeApi); + + // 创建一个EmbeddedComponent组件节点 + ArkUI_NodeHandle embeddedNode = BuildEmbeddedComponentSection(nodeApi); + ArkUI_NodeHandle text2 = BuildTextNode(nodeApi, "嵌入式组件:"); + nodeApi->addChild(column, text2); + + // 将嵌入式组件添加到列容器 + nodeApi->addChild(column, embeddedNode); + // Column作为XComponent子组件 + return column; +} + +ArkUI_NodeHandle EmbeddedComponentMaker::BuildColumnNode(ArkUI_NativeNodeAPI_1* nodeApi) +{ + ArkUI_NodeHandle column = nodeApi->createNode(ARKUI_NODE_COLUMN); + ArkUI_NumberValue colWidth[] = {{.f32 = COL_WIDTH_PX}}; + ArkUI_AttributeItem widthItem = { colWidth, sizeof(colWidth) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(column, NODE_WIDTH, &widthItem); + return column; +} + +ArkUI_NodeHandle EmbeddedComponentMaker::BuildTextNode(ArkUI_NativeNodeAPI_1* nodeApi, const char* content) +{ + ArkUI_NodeHandle text = nodeApi->createNode(ARKUI_NODE_TEXT); + ArkUI_NumberValue textWidth[] = {{.f32 = TEXT_WIDTH_PX}}; + ArkUI_AttributeItem textWidthItem = { textWidth, sizeof(textWidth) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_WIDTH, &textWidthItem); + ArkUI_NumberValue textHeight[] = {{.f32 = TEXT_HEIGHT_PX}}; + ArkUI_AttributeItem textHeightItem = { textHeight, sizeof(textHeight) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_HEIGHT, &textHeightItem); + ArkUI_AttributeItem valueItem = {.string = content}; + nodeApi->setAttribute(text, NODE_TEXT_CONTENT, &valueItem); + return text; +} + +EmbeddedComponentMaker::~EmbeddedComponentMaker() +{ + DisposeEmbeddedComponentOption(); +} + +ArkUI_NodeHandle EmbeddedComponentMaker::BuildEmbeddedComponentSection(ArkUI_NativeNodeAPI_1* nodeApi) +{ + // 创建嵌入式组件选项 + CreateEmbeddedComponentOption(); + // 设置错误回调 + SetEmbeddedComponentOnError(); + // 设置终止回调 + SetEmbeddedComponentOnTerminated(); + // 创建嵌入式组件节点 + ArkUI_NodeHandle embeddedNode = nodeApi->createNode(ARKUI_NODE_EMBEDDED_COMPONENT); + // 设置嵌入式组件的want + SetEmbeddedComponentWant(nodeApi, embeddedNode); + // 将嵌入式组件选项设置给嵌入式组件 + ArkUI_AttributeItem embeddedComponentOptionItem = { .object = embeddedComponentOption_ }; + nodeApi->setAttribute(embeddedNode, NODE_EMBEDDED_COMPONENT_OPTION, &embeddedComponentOptionItem); + ArkUI_NumberValue value[] = { EMBEDDED_COMPONENT_WIDTH }; + ArkUI_AttributeItem embeddedWidthItem = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(embeddedNode, NODE_WIDTH, &embeddedWidthItem); + nodeApi->setAttribute(embeddedNode, NODE_HEIGHT, &embeddedWidthItem); + return embeddedNode; +} + +void EmbeddedComponentMaker::CreateEmbeddedComponentOption() +{ + if (!embeddedComponentOption_) { + embeddedComponentOption_ = OH_ArkUI_EmbeddedComponentOption_Create(); + } +} + +void EmbeddedComponentMaker::DisposeEmbeddedComponentOption() +{ + if (embeddedComponentOption_) { + OH_ArkUI_EmbeddedComponentOption_Dispose(embeddedComponentOption_); + embeddedComponentOption_ = nullptr; + } +} + +void EmbeddedComponentMaker::SetEmbeddedComponentOnError() +{ + if (embeddedComponentOption_) { + OH_ArkUI_EmbeddedComponentOption_SetOnError(embeddedComponentOption_, OnErrorCallback); + } +} + +void EmbeddedComponentMaker::SetEmbeddedComponentOnTerminated() +{ + if (embeddedComponentOption_) { + OH_ArkUI_EmbeddedComponentOption_SetOnTerminated(embeddedComponentOption_, OnTerminatedCallback); + } +} + +void EmbeddedComponentMaker::SetEmbeddedComponentWant(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node) +{ + if (nodeApi && node) { + // 创建一个Want对象并设置相关属性 + AbilityBase_Element element = { + .bundleName = "com.example.native_node_napi", + .abilityName = "SampleEmbeddedAbility", + .moduleName = "" + }; + AbilityBase_Want* want = OH_AbilityBase_CreateWant(element); + ArkUI_AttributeItem itemObjWant = {.object = want}; + nodeApi->setAttribute(node, NODE_EMBEDDED_COMPONENT_WANT, &itemObjWant); + } +} + +void EmbeddedComponentMaker::OnErrorCallback(int32_t code, const char* name, const char* msg) +{ + // 用户自定义的错误处理逻辑 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnErrorCallback:\ + code=%{public}d, name=%{public}s, message=%{public}s", code, name, msg); +} + +void EmbeddedComponentMaker::OnTerminatedCallback(int32_t code, AbilityBase_Want* want) +{ + // 用户自定义的终止处理逻辑 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: code=%{public}d", code); + if (want == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: want is nullptr"); + return; + } + + AbilityBase_Element element; + auto error = OH_AbilityBase_GetWantElement(want, &element); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: bundleName=%{public}s,\ + abilityName=%{public}s, moduleName=%{public}s", element.bundleName, element.abilityName, element.moduleName); + int wantInt = 0; + error = OH_AbilityBase_GetWantInt32Param(want, "int", &wantInt); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: wantInt=%{public}d", wantInt); + bool wantBool = false; + error = OH_AbilityBase_GetWantBoolParam(want, "bool2", &wantBool); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: wantBool=%{public}d", + wantBool); + char wantString[WANT_STR_BUF_LEN]; + error = OH_AbilityBase_GetWantCharParam(want, "string", wantString, WANT_STR_COPY_LEN); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: wantString=%{public}s", + wantString); + char wantUri[WANT_URI_BUF_LEN]; + error = OH_AbilityBase_GetWantUri(want, wantUri, WANT_URI_COPY_LEN); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: wantUri=%{public}s", wantUri); + int wantFd = 0; + error = OH_AbilityBase_GetWantFd(want, "keyFd2", &wantFd); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Manager", "OnTerminatedCallback: wantFd=%{public}d", wantFd); +} diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/EmbeddedComponentMaker.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/EmbeddedComponentMaker.h new file mode 100644 index 0000000000000000000000000000000000000000..30602fb6fbe89d59d1fb2c82b2974bf307cdf0ef --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/EmbeddedComponentMaker.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_NODE_SAMPLE_EMBEDDED_COMPONENT_MAKER_H +#define NATIVE_NODE_SAMPLE_EMBEDDED_COMPONENT_MAKER_H + +#include +#include +#include +#include +#include "manager.h" + +class EmbeddedComponentMaker { +public: + EmbeddedComponentMaker(){}; + ~EmbeddedComponentMaker(); + static ArkUI_NodeHandle CreateNativeNode(); + static ArkUI_NodeHandle BuildEmbeddedComponentSection(ArkUI_NativeNodeAPI_1* nodeApi); + static ArkUI_NodeHandle BuildTextNode(ArkUI_NativeNodeAPI_1* nodeApi, const char* content); + static ArkUI_NodeHandle BuildColumnNode(ArkUI_NativeNodeAPI_1* nodeApi); + static void CreateEmbeddedComponentOption(); + static void DisposeEmbeddedComponentOption(); + static void SetEmbeddedComponentOnError(); + static void SetEmbeddedComponentOnTerminated(); + static void SetEmbeddedComponentWant(ArkUI_NativeNodeAPI_1* nodeApi, ArkUI_NodeHandle node); + static void OnErrorCallback(int32_t code, const char* name, const char* message); + static void OnTerminatedCallback(int32_t code, AbilityBase_Want* want); +}; + +#endif // NATIVE_NODE_SAMPLE_EMBEDDED_COMPONENT_MAKER_H diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NativeModule.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NativeModule.h new file mode 100644 index 0000000000000000000000000000000000000000..a46cd0b117e1efe682eacd358878e16c555360b9 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NativeModule.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_NATIVEMODULE_H +#define MYAPPLICATION_NATIVEMODULE_H + +#include +#include +#include +#include + +namespace NativeModule { + +class NativeModuleInstance { +public: + static NativeModuleInstance *GetInstance() + { + static NativeModuleInstance instance; + return &instance; + } + + NativeModuleInstance() + { + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, arkUINativeNodeApi_); + } + ArkUI_NativeNodeAPI_1 *GetNativeNodeAPI() { return arkUINativeNodeApi_; } + +private: + ArkUI_NativeNodeAPI_1 *arkUINativeNodeApi_ = nullptr; +}; +} // namespace NativeModule +#endif // MYAPPLICATION_NATIVEMODULE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NavigationContext.cpp b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NavigationContext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8701af226fbe96a75607c4d199655c4692001d60 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NavigationContext.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "NavigationContext.h" + +constexpr int32_t BUFFER_LEN = 50; +constexpr int32_t SMALL_BUFFER_LEN = 1; +constexpr int32_t INIT_VAL = -10; + +void NavigationContext::NavigationInfoTest1(ArkUI_NodeHandle node) +{ + char buffer[BUFFER_LEN]; + int32_t resLen = INIT_VAL; + int32_t ret = INIT_VAL; + // case 1 + ret = OH_ArkUI_GetNavigationId(node, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "NavigationId %{public}s , ret: %{public}d, writeLen: %{public}d", buffer, ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; + // case 2 + ret = OH_ArkUI_GetNavDestinationName(node, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "NavDestinationName %{public}s , ret: %{public}d, writeLen: %{public}d", buffer, ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; + // case 3 + int32_t stackLen = -100; + ret = OH_ArkUI_GetNavStackLength(node, &stackLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "OH_ArkUI_GetNavStackLength ret: %{public}d, stackLen: %{public}d", ret, stackLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; + // case 4 + ret = OH_ArkUI_GetNavDestinationNameByIndex(node, 0, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "OH_ArkUI_GetNavDestinationNameByIndex %{public}s , ret: %{public}d, writeLen: %{public}d", buffer, + ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; +} + +void NavigationContext::NavigationInfoTest2(ArkUI_NodeHandle node) +{ + char buffer[BUFFER_LEN]; + int32_t resLen = INIT_VAL; + int32_t ret = INIT_VAL; + // case 5 + ret = OH_ArkUI_GetNavDestinationId(node, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "NavDestinationId %{public}s , ret: %{public}d, writeLen: %{public}d", buffer, ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; + // case 6 + ArkUI_NavDestinationState navDesState; + ret = OH_ArkUI_GetNavDestinationState(node, &navDesState); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "OH_ArkUI_GetNavDestinationState ret: %{public}d, state: %{public}d", ret, navDesState); + ret = INIT_VAL; + // case 7 + int32_t index; + ret = OH_ArkUI_GetNavDestinationIndex(node, &index); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "OH_ArkUI_GetNavDestinationIndex index: %{public}d ret: %{public}d", index, ret); + // case 8 + napi_value param = nullptr; + param = OH_ArkUI_GetNavDestinationParam(node); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", "OH_ArkUI_GetNavDestinationParam isEmpty: %{public}d", + (param == nullptr)); +} + +void NavigationContext::RouterPageInfoTest(ArkUI_NodeHandle node) +{ + char buffer[BUFFER_LEN]; + int32_t resLen = INIT_VAL; + int32_t ret = INIT_VAL; + // case 1 + int32_t index; + ret = OH_ArkUI_GetRouterPageIndex(node, &index); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "OH_ArkUI_GetRouterPageIndex index: %{public}d ret: %{public}d", index, ret); + // case 2 + ret = OH_ArkUI_GetRouterPageName(node, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "RouterPageName %{public}s, ret: %{public}d, writeLen: %{public}d", buffer, ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; + // case 3 + ret = OH_ArkUI_GetRouterPagePath(node, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "RouterPagePath %{public}s, ret: %{public}d, writeLen: %{public}d", buffer, ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; + // case 4 + ArkUI_RouterPageState pageState; + ret = OH_ArkUI_GetRouterPageState(node, &pageState); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "OH_ArkUI_GetNavDestinationState ret: %{public}d, state: %{public}d", ret, pageState); + ret = INIT_VAL; + // case 5 + ret = OH_ArkUI_GetRouterPageId(node, buffer, BUFFER_LEN, &resLen); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "case", + "GetRouterPageId %{public}s, ret: %{public}d, writeLen: %{public}d", buffer, ret, resLen); + std::fill(std::begin(buffer), std::end(buffer), '\0'); + resLen = INIT_VAL; + ret = INIT_VAL; +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NavigationContext.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NavigationContext.h new file mode 100644 index 0000000000000000000000000000000000000000..a601bc750ab8650ea49dcf1af26ca7d360255ccc --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/NavigationContext.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_NODE_NAPI_NAVIGATIONCONTEXT_H +#define NATIVE_NODE_NAPI_NAVIGATIONCONTEXT_H + +#include "manager.h" + +class NavigationContext { +public: + NavigationContext() {} + ~NavigationContext() {} + static void NavigationInfoTest1(ArkUI_NodeHandle node); + static void NavigationInfoTest2(ArkUI_NodeHandle node); + static void RouterPageInfoTest(ArkUI_NodeHandle node); +}; + +#endif //NATIVE_NODE_NAPI_NAVIGATIONCONTEXT_H diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/manager.cpp b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da9ee4d9526e5d2f35dffa8354073fa8f4027665 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/manager.cpp @@ -0,0 +1,423 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "manager.h" +#include "ArkUIAnimationNode.h" +#include "ArkUIVisualEffectsNode.h" +#include "NavigationContext.h" +#include "AccessibilityMaker.h" +#include "EmbeddedComponentMaker.h" +#include "napi/native_api.h" +#include +#include +#include +#include +#include +#include +#include +#include + +Manager Manager::manager_; +ArkUI_NativeNodeAPI_1 *Manager::nodeAPI_ = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + +napi_value Manager::CreateNativeNaviNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode BEGIN"); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode env or info is null"); + return nullptr; + } + size_t argCnt = 1; + napi_value args[1] = {nullptr}; + if (napi_get_cb_info(env, info, &argCnt, args, nullptr, nullptr) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode napi_get_cb_info failed"); + } + + ArkUI_NodeContentHandle nodeContentHandle = nullptr; + + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &nodeContentHandle); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "OH_ArkUI_GetBasicNodeAPI after"); + if (nodeAPI_ != nullptr) { + if (nodeAPI_->createNode != nullptr && nodeAPI_->addChild != nullptr) { + auto columnNode = Manager::nodeAPI_->createNode(ARKUI_NODE_COLUMN); + OH_ArkUI_NodeContent_AddNode(nodeContentHandle, columnNode); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", + "******************NavigationInfoTest******************"); + NavigationContext::NavigationInfoTest1(columnNode); + NavigationContext::NavigationInfoTest2(columnNode); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", + "******************RouterPageInfoTest******************"); + NavigationContext::RouterPageInfoTest(columnNode); + } + } + return nullptr; +} + +napi_value Manager::ProcessDrawable(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + // 获取JS层传入的参数 + napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (status != napi_ok || argc < 1) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "获取参数失败"); + return nullptr; + } + napi_value resourceValue = args[0]; // 这是ArkTS侧传入的Resource对象 + // 核心接口:将napi_value转换为DrawableDescriptor + ArkUI_DrawableDescriptor* drawable = nullptr; + int32_t res = OH_ArkUI_GetDrawableDescriptorFromNapiValue(env, resourceValue, &drawable); + // 处理转换结果 + if (res != ArkUI_ErrorCode::ARKUI_ERROR_CODE_NO_ERROR) { + // 转换失败:根据错误码处理(参数无效等) + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "Failed to get drawable descriptor"); + napi_throw_error(env, nullptr, "Failed to get drawable descriptor"); + return nullptr; + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "success to get drawable descriptor"); + // 返回处理结果给JS层 + napi_value result; + napi_create_int32(env, res, &result); + return result; +} + +napi_value Manager::ProcessDrawable2(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + // 获取JS层传入的参数 + napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (status != napi_ok || argc < 1) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "获取参数失败"); + return nullptr; + } + napi_value resourceValue = args[0]; // 这是ArkTS侧传入的Resource对象 + // 核心接口:将napi_value转换为DrawableDescriptor + ArkUI_DrawableDescriptor* drawable = nullptr; + int32_t res = OH_ArkUI_GetDrawableDescriptorFromResourceNapiValue (env, resourceValue, &drawable); + // 3. 处理转换结果 + if (res != ArkUI_ErrorCode::ARKUI_ERROR_CODE_NO_ERROR) { + // 转换失败:根据错误码处理(参数无效等) + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "Failed to get drawable descriptor"); + return nullptr; + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "success to get drawable descriptor"); + // 返回处理结果给JS层 + napi_value result; + napi_create_int32(env, res, &result); + return result; +} + +napi_value Manager::CreateNativeAccessibilityNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode BEGIN"); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode env or info is null"); + return nullptr; + } + size_t argCnt = 1; + napi_value args[1] = {nullptr}; + if (napi_get_cb_info(env, info, &argCnt, args, nullptr, nullptr) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode napi_get_cb_info failed"); + } + + ArkUI_NodeContentHandle nodeContentHandle = nullptr; + + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &nodeContentHandle); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "OH_ArkUI_GetBasicNodeAPI after"); + if (nodeAPI_ != nullptr) { + if (nodeAPI_->createNode != nullptr && nodeAPI_->addChild != nullptr) { + ArkUI_NodeHandle testNode = AccessibilityMaker::CreateNativeNode(); + OH_ArkUI_NodeContent_AddNode(nodeContentHandle, testNode); + } + } + return nullptr; +} + +napi_value Manager::CreateNativeEmbeddedComponentNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode BEGIN"); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode env or info is null"); + return nullptr; + } + size_t argCnt = 1; + napi_value args[1] = {nullptr}; + if (napi_get_cb_info(env, info, &argCnt, args, nullptr, nullptr) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "CreateNativeNode napi_get_cb_info failed"); + } + + ArkUI_NodeContentHandle nodeContentHandle = nullptr; + + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &nodeContentHandle); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager", "OH_ArkUI_GetBasicNodeAPI after"); + if (nodeAPI_ != nullptr) { + if (nodeAPI_->createNode != nullptr && nodeAPI_->addChild != nullptr) { + ArkUI_NodeHandle testNode = EmbeddedComponentMaker::CreateNativeNode(); + OH_ArkUI_NodeContent_AddNode(nodeContentHandle, testNode); + } + } + return nullptr; +} + +napi_value createAnimationCenter(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationCenter(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createAnimationOpacity(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationOpacity(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createAnimationTranslate(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationTranslate(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createAnimationFit(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFit(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createAnimationGeometry(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationGeometry(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsScale(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsScale(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsBlur(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsBlur(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsShape(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsShape(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsShadow(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsShadow(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsSepia(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsSepia(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsMask(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsMask(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsCont(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsCont(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsAngle(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsAngle(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsStyle(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsStyle(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createVisualEffectsGroup(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsGroup(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value DestroyNativeRoot(napi_env env, napi_callback_info info) +{ + Manager::GetInstance()->DisposeRootNode(); + return nullptr; +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/manager.h b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/manager.h new file mode 100644 index 0000000000000000000000000000000000000000..e2e3d5c8deb01667c3caa923aed9d50bd5ce820b --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/manager.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_NODE_NAPI_SAMPLE_MANAGER_H +#define NATIVE_NODE_NAPI_SAMPLE_MANAGER_H + +#include "ArkUIBaseNode.h" +#include +#include +#include +#include +#include +#include +#include +#include + +napi_value createAnimationCenter(napi_env env, napi_callback_info info); +napi_value createAnimationOpacity(napi_env env, napi_callback_info info); +napi_value createAnimationTranslate(napi_env env, napi_callback_info info); +napi_value createAnimationFit(napi_env env, napi_callback_info info); +napi_value createAnimationGeometry(napi_env env, napi_callback_info info); +napi_value createVisualEffectsScale(napi_env env, napi_callback_info info); +napi_value createVisualEffectsBlur(napi_env env, napi_callback_info info); +napi_value createVisualEffectsShape(napi_env env, napi_callback_info info); +napi_value createVisualEffectsShadow(napi_env env, napi_callback_info info); +napi_value createVisualEffectsSepia(napi_env env, napi_callback_info info); +napi_value createVisualEffectsMask(napi_env env, napi_callback_info info); +napi_value createVisualEffectsCont(napi_env env, napi_callback_info info); +napi_value createVisualEffectsAngle(napi_env env, napi_callback_info info); +napi_value createVisualEffectsStyle(napi_env env, napi_callback_info info); +napi_value createVisualEffectsGroup(napi_env env, napi_callback_info info); +napi_value DestroyNativeRoot(napi_env env, napi_callback_info info); + +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +const int32_t CNT_NUMBER = 1; +class Manager { +public: + static ArkUI_NativeNodeAPI_1 *nodeAPI_; + ~Manager(){}; + + static Manager *GetInstance() + { + static Manager nativeEntry; + return &nativeEntry; + } + + void SetContentHandle(ArkUI_NodeContentHandle handle) + { + handle_ = handle; + } + + void SetRootNode(const std::shared_ptr &baseNode) + { + cnt++; + root_ = baseNode; + OH_ArkUI_NodeContent_AddNode(handle_, root_->GetHandle()); + } + void DisposeRootNode() + { + if (cnt != CNT_NUMBER) { + cnt--; + return; + } + OH_ArkUI_NodeContent_RemoveNode(handle_, root_->GetHandle()); + root_.reset(); + } + + static napi_value CreateNativeNaviNode(napi_env env, napi_callback_info info); + static napi_value ProcessDrawable(napi_env env, napi_callback_info info); + static napi_value ProcessDrawable2(napi_env env, napi_callback_info info); + static napi_value CreateNativeAccessibilityNode(napi_env env, napi_callback_info info); + static napi_value CreateNativeEmbeddedComponentNode(napi_env env, napi_callback_info info); + +private: + int32_t cnt = 0; + static Manager manager_; + std::shared_ptr root_; + ArkUI_NodeContentHandle handle_; +}; + +#endif // NATIVE_NODE_NAPI_SAMPLE_MANAGER_H diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06bba142dbb776ffd938975c730365707f6af6f4 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "manager.h" + +EXTERN_C_START +napi_property_descriptor desc[] = { + {"createNativeNaviNode", nullptr, Manager::CreateNativeNaviNode, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"createNativeAccessibilityNode", nullptr, Manager::CreateNativeAccessibilityNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"createNativeEmbeddedComponentNode", nullptr, Manager::CreateNativeEmbeddedComponentNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + // 参考Navigation新增其他createNative方法和Context类 + {"createAnimationCenter", nullptr, createAnimationCenter, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createAnimationOpacity", nullptr, createAnimationOpacity, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createAnimationTranslate", nullptr, createAnimationTranslate, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createAnimationFit", nullptr, createAnimationFit, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createAnimationGeometry", nullptr, createAnimationGeometry, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsScale", nullptr, createVisualEffectsScale, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsBlur", nullptr, createVisualEffectsBlur, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsShape", nullptr, createVisualEffectsShape, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsShadow", nullptr, createVisualEffectsShadow, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsSepia", nullptr, createVisualEffectsSepia, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsMask", nullptr, createVisualEffectsMask, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsCont", nullptr, createVisualEffectsCont, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsAngle", nullptr, createVisualEffectsAngle, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsStyle", nullptr, createVisualEffectsStyle, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createVisualEffectsGroup", nullptr, createVisualEffectsGroup, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyNativeRoot", nullptr, DestroyNativeRoot, nullptr, nullptr, nullptr, napi_default, nullptr}, + { "processDrawable", nullptr, Manager::ProcessDrawable, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "processDrawable2", nullptr, Manager::ProcessDrawable2, nullptr, nullptr, nullptr, napi_default, nullptr }, +}; + +static napi_value Init(napi_env env, napi_value exports) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "Init begins"); + if ((env == nullptr) || (exports == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "env or exports is null"); + return nullptr; + } + + if (napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "napi_define_properties failed"); + return nullptr; + } + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..333ce4deb1b6b2a937402a329bcb842446257d93 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { DrawableDescriptor } from "@kit.ArkUI"; + +export const createNativeNaviNode: (content: Object) =>void; +export const processDrawable: (a: DrawableDescriptor) => number; +export const processDrawable2: (a: DrawableDescriptor) => number; +export const createNativeAccessibilityNode: (content: Object) => void; +export const createNativeEmbeddedComponentNode: (content: Object) => void; +export const createAnimationCenter: (content: Object) => void; +export const createAnimationOpacity: (content: Object) => void; +export const createAnimationTranslate: (content: Object) => void; +export const createAnimationFit: (content: Object) => void; +export const createAnimationGeometry: (content: Object) => void; +export const createVisualEffectsScale: (content: Object) => void; +export const createVisualEffectsBlur: (content: Object) => void; +export const createVisualEffectsShape: (content: Object) => void; +export const createVisualEffectsShadow: (content: Object) => void; +export const createVisualEffectsSepia: (content: Object) => void; +export const createVisualEffectsMask: (content: Object) => void; +export const createVisualEffectsCont: (content: Object) => void; +export const createVisualEffectsAngle: (content: Object) => void; +export const createVisualEffectsStyle: (content: Object) => void; +export const createVisualEffectsGroup: (content: Object) => void; +export const destroyNativeRoot: () => void; diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b81656fe96ca09694282eed65e33f57ddc1d2a05 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..79e55422a4c269db8c49fcd84222a9ccafe8f177 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +import { BusinessError } from '@kit.BasicServicesKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#2aa1a6b1', + navigationBarColor: '#2aa1a6b1', + //以下两个属性从API Version8开始支持 + }; + try { + let promise = windowClass.setWindowSystemBarProperties(systemBarProperties); + promise.then(() => { + console.info('Succeeded in setting the system bar properties.'); + }).catch((err: BusinessError) => { + console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + }); + } catch (exception) { + console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/extensionAbility/SampleEmbeddedAbility.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/extensionAbility/SampleEmbeddedAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5198683956ff5596a6c1f50c4d3753453d2ee889 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/extensionAbility/SampleEmbeddedAbility.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { EmbeddedUIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit' + +export default class SampleEmbeddedAbility extends EmbeddedUIExtensionAbility { + onForeground() { + this.context.terminateSelf() + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/Index.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..910e33f574cb67cfcf22cf467d400f3d520026ee --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { router } from '@kit.ArkUI'; + +interface ListCategories { + title: string, + url: string +} + +@Entry +@Component +struct MenuIndex { + private items: ListCategories[] = + [ + { title: 'Navigation', url: 'pages/page_navigation' }, + { title: 'add your router', url: 'pages/page_navigation' }, + { title: 'Mapping DrawableDescriptor', url: 'pages/page_getDrawableDescriptor' }, + { title: 'accessibility', url: 'pages/page_accessibility' }, + { title: 'embedded component', url: 'pages/page_embedded_component' }, + { title: 'Animation', url: 'pages/page_animation' }, + { title: 'Visual Effects', url: 'pages/page_visual_effects' }, + ]; + + build() { + Scroll(new Scroller()) { + Column() { + Text('native_node_napi_sample') + .fontWeight(FontWeight.Bold) + .fontSize(20) + .textAlign(TextAlign.Center) + .height('5%') + .margin($r('sys.float.titlebar_title_margin_right')) + List() { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Row() { + Text(item.title) + .fontSize($r('sys.float.text_button_font_size')) + .fontColor(Color.Black) + .textAlign(TextAlign.Start) + .height('100%') + .width('70%') + .padding($r('sys.float.padding_level10')) + Text('>') + .fontSize('25vp') + .fontColor(Color.Black) + .textAlign(TextAlign.End) + .fontColor(Color.Gray) + .height('100%') + .width('30%') + .padding($r('sys.float.padding_level10')) + } + .width('100%') + .height('10%') + .borderRadius($r('sys.float.select_border_radius_default')) + .backgroundColor(Color.White) + .onClick(() => { + router.pushUrl({ url: item.url }) + }) + } + .margin($r('sys.float.menu_item_content_align')) + }) + }.width('95%').height('90%').alignListItem(ListItemAlign.Center) + }.width('100%') + }.height('100%').backgroundColor('#2aa1a6b1') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexCenter.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexCenter.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9eaf6b2ba5ab6e68632c730dbbbc45ec7fad6be --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexCenter.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createAnimationCenter(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexGeometry.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexGeometry.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5ec63d0f3ac851f1354c69481e5a10a6273e900 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexGeometry.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createAnimationGeometry(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexOpacity.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexOpacity.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0c42831dde87050acd605a570ca7b035e4c38e7 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexOpacity.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createAnimationOpacity(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexRenderFit.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexRenderFit.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4ed3543c87b6c9f915efc25ab9a4eb97987cf12 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexRenderFit.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createAnimationFit(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexTranslate.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexTranslate.ets new file mode 100644 index 0000000000000000000000000000000000000000..66e189f0b9a44f2584c7461f1a453cbcdd1cba1e --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/animation/AnimationIndexTranslate.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createAnimationTranslate(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_accessibility.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_accessibility.ets new file mode 100644 index 0000000000000000000000000000000000000000..9368bede5d6e3160cbddc45f7bd9235d4d4efeac --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_accessibility.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + private nodeContent = new NodeContent(); + aboutToAppear() { + // 通过C-API创建节点,并添加到管理器nodeContent上 + Napi.createNativeAccessibilityNode(this.nodeContent); + } + build() { + Column() { + ContentSlot(this.nodeContent) + } + .width('100%') + .height('100%') + } +} diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_animation.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_animation.ets new file mode 100644 index 0000000000000000000000000000000000000000..3950289d01c53e1627b641dc1326076af90914ec --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_animation.ets @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface ListCategories { + title:string, + url:string +} + +@Entry +@Component +struct AnimationIndex { + @State message: string = 'CApi'; + @State isShow: boolean = false; + private items : ListCategories[] = [ + {title:'NODE_TRANSFORM_CENTER, NODE_TRANSITION',url:'pages/animation/AnimationIndexCenter'}, + {title:'NODE_OPACITY_TRANSITION,NODE_ROTATE_TRANSITION,NODE_SCALE_TRANSITION',url:'pages/animation/AnimationIndexOpacity'}, + {title:'NODE_TRANSLATE_TRANSITION,NODE_MOVE_TRANSITION,',url:'pages/animation/AnimationIndexTranslate'}, + {title:'NODE_RENDER_FIT',url:'pages/animation/AnimationIndexRenderFit'}, + {title:'NODE_GEOMETRY_TRANSITION',url:'pages/animation/AnimationIndexGeometry'}, + ]; + + @Builder cApiMenu() { + Grid() { + ForEach(this.items, (item: ListCategories) => { + GridItem() { + Button(item.title) + .key(item.title) + .width('100%') + .height('100%') + .fontSize(10) + .padding(1) + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: item.url }); + }) + } + }) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr') + .columnsGap(8) + .rowsGap(8) + .width('100%') + } + + build() { + Scroll(new Scroller()) { + Column() { + Stack() { + Row() { + Text(this.message) + .fontSize(22) + .fontColor(0xFFFFFF) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width('100%') + .height(50) + .backgroundColor('#FF08528A') + }.width('100%') + Button('menu') + .key('menu') + .onClick(() => { + this.isShow = true; + }) + .fontSize(10) + .position({top: 5, right: 5}) + .backgroundColor(Color.Transparent) + .fontColor(Color.Transparent) + .bindSheet($$this.isShow, this.cApiMenu(), { + showClose: false, + preferType: SheetType.BOTTOM + }) + } + + List({ space: '20vp' }) { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Button(item.title) + .fontSize(15) + .labelStyle({ maxLines: 10 }) + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: item.url }); + }) + } + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('90%').height('90%') + }.width('100%').height('100%').backgroundColor('#FFDDE7F6') + } + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_embedded_component.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_embedded_component.ets new file mode 100644 index 0000000000000000000000000000000000000000..040bd81c11fdffac89c05193b2125d60d09e20aa --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_embedded_component.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + private nodeContent = new NodeContent(); + aboutToAppear() { + // 通过C-API创建节点,并添加到管理器nodeContent上 + Napi.createNativeEmbeddedComponentNode(this.nodeContent); + } + build() { + Column() { + ContentSlot(this.nodeContent) + } + .width('100%') + .height('100%') + } +} diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_getDrawableDescriptor.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_getDrawableDescriptor.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee230c856ebe1f52c13a6242fec1f4189f469628 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_getDrawableDescriptor.ets @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { DrawableDescriptor } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State sr1:Resource = $r('app.string.GetDrawableDescriptor_result0'); + @State sr2:Resource = $r('app.string.GetDrawableDescriptor_result0'); + build() { + Row() { + Column() { + Button($r('app.string.GetDrawableDescriptor_return')).onClick(() => { + this.getUIContext().getRouter().back() + }) + + Text($r('app.string.GetDrawableDescriptor_label')) + .fontSize(20) + .margin(20) + + Text($r('app.string.GetDrawableDescriptor_label2')) + .fontSize(20) + .margin(20) + + Button($r('app.string.GetDrawableDescriptor_button1')) + .onClick(() => { + let resManager = this.getUIContext().getHostContext()?.resourceManager + let imageRes: DrawableDescriptor = (resManager?.getDrawableDescriptor($r('app.media.foreground').id, 120)) as DrawableDescriptor; + + let res1 = Napi.processDrawable(imageRes); + if (res1 === 0) { + this.sr1 = $r('app.string.GetDrawableDescriptor_result1'); + } else { + this.sr1 = $r('app.string.GetDrawableDescriptor_result2'); + } + }) + .margin({top:40,bottom:20}) + + Text(this.sr1) + .fontSize(16) + .margin(20) + + Button($r('app.string.GetDrawableDescriptor_button2')) + .onClick(() => { + let resManager = this.getUIContext().getHostContext()?.resourceManager + let imageRes: DrawableDescriptor = (resManager?.getDrawableDescriptor($r('app.media.foreground').id)) as DrawableDescriptor; + let res2 = Napi.processDrawable2(imageRes); + if (res2 === 0) { + this.sr2 = $r('app.string.GetDrawableDescriptor_result3'); + } else { + this.sr2 = $r('app.string.GetDrawableDescriptor_result4'); + } + }) + Text(this.sr2) + .fontSize(16) + .margin(20) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_navigation.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_navigation.ets new file mode 100644 index 0000000000000000000000000000000000000000..94567a56f7fe2aec5630b57481aaa2ba2f7a3801 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_navigation.ets @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @Provide('pageStack') pageStack: NavPathStack = new NavPathStack(); + + @Builder + PagesMap(name: string) { + if (name === 'PageOne') { + PageOne(); + } else if (name === 'PageTwo') { + PageTwo(); + } + } + + build() { + Navigation(this.pageStack) { + Column() { + Button('pushPath').onClick(() => { + this.pageStack.pushPath({ name: 'PageOne' }); + }).margin('sys.float.menu_item_content_align') + Button('pushPath with param').onClick(() => { + this.pageStack.pushPath({ name: 'PageOne', param: 'param' }); + }).margin('sys.float.menu_item_content_align') + Button('pushPath Two').onClick(() => { + this.pageStack.pushPath({ name: 'PageTwo', param: 'param' }); + }).margin('sys.float.menu_item_content_align') + Button('pop').onClick(() => { + this.pageStack.pop(); + }).margin('sys.float.menu_item_content_align') + } + } + .title('NavIndex') + .id('This is Navigation ID') + .mode(NavigationMode.Split) + .navDestination(this.PagesMap) + .navBarWidth('50%') + } +} + +@Component +export struct PageOne { + @Consume('pageStack') pageStack: NavPathStack; + private nodeContent = new NodeContent(); + + build() { + NavDestination(){ + Column(){ + Text('This is PageOne') + .fontSize(20) + ContentSlot(this.nodeContent) + }.width('100%').height('100%') + }.title('NavDestination') + .onWillShow(()=>{ + Napi.createNativeNaviNode(this.nodeContent); + }) + .id('This is NavDestination ID1') + } +} + +@Component +export struct PageTwo { + @Consume('pageStack') pageStack: NavPathStack; + private nodeContent = new NodeContent(); + + build() { + NavDestination(){ + Column(){ + Text('This is PageTwo') + .fontSize(20) + ContentSlot(this.nodeContent) + }.width('100%').height('100%') + }.title('NavDestination') + .onWillShow(()=>{ + Napi.createNativeNaviNode(this.nodeContent); + }) + .id('This is NavDestination ID2') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_visual_effects.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_visual_effects.ets new file mode 100644 index 0000000000000000000000000000000000000000..ceb13143ce4476c50252c470e218a401647b613b --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/page_visual_effects.ets @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface ListCategoriesTwo { + title:string, + url:string +} + +@Entry +@Component +struct VisualEffectsIndex { + @State message: string = 'CApi'; + @State isShow: boolean = false; + private items : ListCategoriesTwo[] = [ + {title:'NODE_TRANSLATE,NODE_SCALE,NODE_ROTATE',url:'pages/visualEffects/VisualEffectsIndexScale'}, + {title:'NODE_BRIGHTNESS,NODE_SATURATION,NODE_BLUR',url:'pages/visualEffects/VisualEffectsIndexBlur'}, + {title:'NODE_LINEAR_GRADIENT,NODE_OPACITY,NODE_CLIP',url:'pages/visualEffects/VisualEffectsIndexShape'}, + {title:'NODE_CLIP_SHAPE,NODE_TRANSFORM,NODE_SHADOW',url:'pages/visualEffects/VisualEffectsIndexShadow'}, + {title:'NODE_SWEEP_GRADIENT,NODE_RADIAL_GRADIENT,NODE_MASK',url:'pages/visualEffects/VisualEffectsIndexSepia'}, + {title:'NODE_GRAY_SCALE,NODE_INVERT,NODE_SEPIA',url:'pages/visualEffects/VisualEffectsIndexMask'}, + {title:'NODE_CONTRAST,NODE_FOREGROUND_COLOR,NODE_MARK_ANCHOR',url:'pages/visualEffects/VisualEffectsIndexCont'}, + {title:'NODE_TRANSLATE_WITH_PERCENT,NODE_ROTATE_ANGLE,NODE_CUSTOM_SHADOW', + url:'pages/visualEffects/VisualEffectsIndexAngle'}, + {title:'NODE_BACKGROUND_BLUR_STYLE,NODE_FOREGROUND_BLUR_STYLE,NODE_COLOR_BLEND', + url:'pages/visualEffects/VisualEffectsIndexStyle'}, + {title:'NODE_BACKDROP_BLUR,NODE_RENDER_GROUP',url:'pages/visualEffects/VisualEffectsIndexGroup'}, + ]; + + @Builder cApiMenu() { + Grid() { + ForEach(this.items, (item: ListCategoriesTwo) => { + GridItem() { + Button(item.title) + .key(item.title) + .width('100%') + .height('100%') + .fontSize(10) + .padding(1) + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: item.url }); + }) + } + }) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr') + .columnsGap(8) + .rowsGap(8) + .width('100%') + } + + build() { + Scroll(new Scroller()) { + Column() { + Stack() { + Row() { + Text(this.message) + .fontSize(22) + .fontColor(0xFFFFFF) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width('100%') + .height(50) + .backgroundColor('#FF08528A') + }.width('100%') + Button('menu') + .key('menu') + .onClick(() => { + this.isShow = true; + }) + .fontSize(10) + .position({top: 5, right: 5}) + .backgroundColor(Color.Transparent) + .fontColor(Color.Transparent) + .bindSheet($$this.isShow, this.cApiMenu(), { + showClose: false, + preferType: SheetType.BOTTOM + }) + } + + List({ space: '20vp' }) { + ForEach(this.items, (item: ListCategoriesTwo) => { + ListItem() { + Button(item.title) + .fontSize(15) + .labelStyle({ maxLines: 10 }) + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: item.url }); + }) + } + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('90%').height('90%') + }.width('100%').height('100%').backgroundColor('#FFDDE7F6') + } + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexAngle.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexAngle.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3b124525a4dd88f2b316e94b2cf66b2101eef26 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexAngle.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsAngle(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexBlur.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexBlur.ets new file mode 100644 index 0000000000000000000000000000000000000000..3666d21db8fc2353fc51b6fb3e9bd40d55f5d8f0 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexBlur.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsBlur(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexCont.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexCont.ets new file mode 100644 index 0000000000000000000000000000000000000000..b520bf3855040bb91ce6e66ef79c04bde66af7fa --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexCont.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsCont(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexGroup.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexGroup.ets new file mode 100644 index 0000000000000000000000000000000000000000..5480833994eda630084e8dd0543b23c779938aaf --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexGroup.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsGroup(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexMask.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexMask.ets new file mode 100644 index 0000000000000000000000000000000000000000..18f32d3a995d99390b2aa8c7ed3d1f839f794af9 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexMask.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsMask(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexScale.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexScale.ets new file mode 100644 index 0000000000000000000000000000000000000000..0bce4f0d54aa617b91e942ad301dc3d9e1a74709 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexScale.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsScale(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexSepia.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexSepia.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c6ab46df46946fff9670cdc3a8b9e10f7531d32 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexSepia.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsSepia(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexShadow.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexShadow.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab06d4e5d52a506d0b95a639bff3ba1c7e396e7b --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexShadow.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsShadow(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexShape.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexShape.ets new file mode 100644 index 0000000000000000000000000000000000000000..155d3662d680771fde21a38859d739574712aad5 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexShape.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsShape(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexStyle.ets b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexStyle.ets new file mode 100644 index 0000000000000000000000000000000000000000..63def79fc2462c06f443aa4f65fa6febed7a213d --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/ets/pages/visualEffects/VisualEffectsIndexStyle.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createVisualEffectsStyle(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/module.json5 b/ArkUIKit/NativeNodeNapi/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c5be971e98a651c460b6e756939f1f5a6572f0c3 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/module.json5 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + }, + { + "name": "SampleEmbeddedAbility", + "srcEntry": "./ets/extensionAbility/SampleEmbeddedAbility.ets", + "type": "embeddedUI" + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/color.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/float.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/string.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3f6f2c480ac3a78f7d66e37568e34858c8820aec --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/element/string.json @@ -0,0 +1,56 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "GetDrawableDescriptor_label", + "value": "映射 Drawable 示例" + }, + { + "name": "GetDrawableDescriptor_label2", + "value": "ArkTS侧创建的DrawableDescriptor映射到Native侧" + }, + { + "name": "GetDrawableDescriptor_button1", + "value": "方式1:GetDrawableDescriptorFromNapiValue" + }, + { + "name": "GetDrawableDescriptor_result1", + "value": "测试结果:方式1映射DrawableDescriptor成功" + }, + { + "name": "GetDrawableDescriptor_result2", + "value": "测试结果:方式1映射DrawableDescriptor失败" + }, + { + "name": "GetDrawableDescriptor_button2", + "value": "方式2:GetDrawableDescriptorFromResourceNapiValue" + }, + { + "name": "GetDrawableDescriptor_result3", + "value": "测试结果:方式2映射DrawableDescriptor成功" + }, + { + "name": "GetDrawableDescriptor_result4", + "value": "测试结果:方式2映射DrawableDescriptor失败" + }, + { + "name": "GetDrawableDescriptor_result0", + "value": "测试结果:" + }, + { + "name": "GetDrawableDescriptor_return", + "value": " 返回上页 " + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/background.png b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..7579e04edbb851566cf3a6817db2b085ddaad2aa --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,26 @@ +{ + "src": [ + "pages/Index", + "pages/page_navigation", + "pages/page_getDrawableDescriptor", + "pages/page_accessibility", + "pages/page_embedded_component", + "pages/page_animation", + "pages/animation/AnimationIndexCenter", + "pages/animation/AnimationIndexOpacity", + "pages/animation/AnimationIndexTranslate", + "pages/animation/AnimationIndexRenderFit", + "pages/animation/AnimationIndexGeometry", + "pages/page_visual_effects", + "pages/visualEffects/VisualEffectsIndexScale", + "pages/visualEffects/VisualEffectsIndexBlur", + "pages/visualEffects/VisualEffectsIndexShape", + "pages/visualEffects/VisualEffectsIndexShadow", + "pages/visualEffects/VisualEffectsIndexSepia", + "pages/visualEffects/VisualEffectsIndexMask", + "pages/visualEffects/VisualEffectsIndexCont", + "pages/visualEffects/VisualEffectsIndexAngle", + "pages/visualEffects/VisualEffectsIndexStyle", + "pages/visualEffects/VisualEffectsIndexGroup" + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/main/resources/dark/element/color.json b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/module.json5 b/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..69026872775eebd0844900b225c411959ae5608b --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/ohosTest/module.json5 @@ -0,0 +1,12 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/NativeNodeNapi/entry/src/test/List.test.ets b/ArkUIKit/NativeNodeNapi/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/entry/src/test/LocalUnit.test.ets b/ArkUIKit/NativeNodeNapi/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/hvigor/hvigor-config.json5 b/ArkUIKit/NativeNodeNapi/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c46181e346e0b1a9f966305a9164616bd2db470e --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/NativeNodeNapi/hvigorfile.ts b/ArkUIKit/NativeNodeNapi/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..de06c780c9687a49f0161e161816f18af7354ff0 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/oh-package.json5 b/ArkUIKit/NativeNodeNapi/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c1f77ef1fa70a9ffe74e46cdf21b6e0bda81aed5 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/NativeNodeNapi/ohosTest.md b/ArkUIKit/NativeNodeNapi/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ce07d4701371b9c7f1c0208911a586279ac86bb9 --- /dev/null +++ b/ArkUIKit/NativeNodeNapi/ohosTest.md @@ -0,0 +1,14 @@ +# 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期显示 | 是否自动 | 测试结果 | +| ---------------------------------------- | ------------ | ------------------------------------------------------------ | --------------------------------------- | -------- | -------- | +| 启动应用 | 设备正常运行 | 1.开启开发板
2.编译hap包并将hap包及环境烧录进开发板,运行测试用例
| 成功拉起应用。 | 否 | 验证通过 | +| swiper正确获取navigation和router相关信息 | 应用位于首页 | 1.点击首页navigation按钮
2.点击pushPath按钮 | 1.获取到以A0ff00/Manager为tag的相关日志 | 否 | 验证通过 | +| 测试ArkTS侧创建的DrawableDescriptor对象映射到Native侧接口1 | 应用位于首页 | 1.点击首页Mapping DrawableDescriptor按钮
2.点击方式1:GetDrawableDescriptorFromNapiValue按钮 | 1.界面显示 测试结果: 方式1映射DrawableDescriptor成功 | 否 | 验证通过 | +| 测试ArkTS侧创建的DrawableDescriptor对象映射到Native侧接口2 | 应用位于首页 | 1.点击首页Mapping DrawableDescriptor按钮
2.点击方式2:GetDrawableDescriptorFromResourceNapiValue按钮 | 1.界面显示 测试结果: 方式2映射DrawableDescriptor成功 | 否 | 验证通过 | + +| EmbeddedComponent OnErrorCallback回调成功 | 执行 hdc shell param set persist.sys.abilityms.multi_process_model false 后重启,应用位于首页 | 1.点击首页embedded component按钮 | EmbeddedComponent onError回调被触发,打印日志{OnErrorCallback: code=100018, name=start_ability_fail, message=Start ui extension ability failed, please check the want of UIextensionAbility.} | 否 | 验证通过 | +| EmbeddedComponent OnTerminatedCallback回调成功 | 执行 hdc shell param set persist.sys.abilityms.multi_process_model true 后重启,应用位于首页 | 1.点击首页embedded component按钮 | EmbeddedComponent onError回调被触发,打印日志{OnTerminatedCallback: code=0} | 否 | 验证通过 | +| 文本无障碍属性设置 | 应用位于首页 | 1.点击首页Accessibility按钮 | 观测Get日志设置属性值与Set函数一致 | 否 | 验证通过 | \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapi/screenshots/mappingDescriptor.jpeg b/ArkUIKit/NativeNodeNapi/screenshots/mappingDescriptor.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..99fa8aa23aeb90336e549952611a9cc7af3727ab Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/screenshots/mappingDescriptor.jpeg differ diff --git a/ArkUIKit/NativeNodeNapi/screenshots/page_navigation.jpeg b/ArkUIKit/NativeNodeNapi/screenshots/page_navigation.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..97685c5acafa997593cb64eecba028c391b8fb4b Binary files /dev/null and b/ArkUIKit/NativeNodeNapi/screenshots/page_navigation.jpeg differ diff --git a/ArkUIKit/ShapeDrawing/build-profile.json5 b/ArkUIKit/ShapeDrawing/build-profile.json5 index 847c893100921479d8fe53766092640bfdf87021..1e71c80934c45f8b51e8fbcb4c66e4d5b212df12 100644 --- a/ArkUIKit/ShapeDrawing/build-profile.json5 +++ b/ArkUIKit/ShapeDrawing/build-profile.json5 @@ -19,10 +19,10 @@ { "name": "default", "signingConfig": "default", - "targetSdkVersion": 20, - "compatibleSdkVersion": 20, - "compileSdkVersion": 20, - "runtimeOS": "OpenHarmony", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { "caseSensitiveCheck": true, diff --git a/ArkUIKit/ShapeDrawing/entry/src/main/syscap.json b/ArkUIKit/ShapeDrawing/entry/src/main/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..598552fb33d0f5c27fed37e607d9163f836ac5af --- /dev/null +++ b/ArkUIKit/ShapeDrawing/entry/src/main/syscap.json @@ -0,0 +1,24 @@ + +{ + "devices": { + "general": [ + "default" + ] + }, + "production": { + "removedSysCaps": [ + "SystemCapability.HiviewDFX.HiDumper", + "SystemCapability.Security.DeviceAuth", + "SystemCapability.Multimedia.Media.AVTranscoder", + "SystemCapability.Tee.TeeClient", + "SystemCapability.Communication.Bluetooth.Core", + "SystemCapability.ArkUi.Graphics3D", + "SystemCapability.DistributedHardware.DeviceManager", + "SystemCapability.Multimedia.Drm.Core", + "SystemCapability.Advertising.Ads", + "SystemCapability.Customization.EnterpriseDeviceManager", + "SystemCapability.Security.DeviceSecurityLevel", + "SystemCapability.UserIAM.UserAuth.PinAuth" + ] + } +} diff --git a/ArkUIKit/ShapeDrawing/entry/src/ohosTest/syscap.json b/ArkUIKit/ShapeDrawing/entry/src/ohosTest/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..598552fb33d0f5c27fed37e607d9163f836ac5af --- /dev/null +++ b/ArkUIKit/ShapeDrawing/entry/src/ohosTest/syscap.json @@ -0,0 +1,24 @@ + +{ + "devices": { + "general": [ + "default" + ] + }, + "production": { + "removedSysCaps": [ + "SystemCapability.HiviewDFX.HiDumper", + "SystemCapability.Security.DeviceAuth", + "SystemCapability.Multimedia.Media.AVTranscoder", + "SystemCapability.Tee.TeeClient", + "SystemCapability.Communication.Bluetooth.Core", + "SystemCapability.ArkUi.Graphics3D", + "SystemCapability.DistributedHardware.DeviceManager", + "SystemCapability.Multimedia.Drm.Core", + "SystemCapability.Advertising.Ads", + "SystemCapability.Customization.EnterpriseDeviceManager", + "SystemCapability.Security.DeviceSecurityLevel", + "SystemCapability.UserIAM.UserAuth.PinAuth" + ] + } +} diff --git a/ArkUIKit/checkpage/AppScope/app.json5 b/ArkUIKit/checkpage/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..47144ed8fbeb93744fed70e5c1a230e430d129c0 --- /dev/null +++ b/ArkUIKit/checkpage/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.samples.checkpage", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/checkpage/AppScope/resources/base/element/string.json b/ArkUIKit/checkpage/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..294030c43d7f92e04efe9705f0e1ec19f8fd16f7 --- /dev/null +++ b/ArkUIKit/checkpage/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "checkpage" + } + ] +} diff --git a/ArkUIKit/checkpage/AppScope/resources/base/media/background.png b/ArkUIKit/checkpage/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/checkpage/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/checkpage/AppScope/resources/base/media/foreground.png b/ArkUIKit/checkpage/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/ArkUIKit/checkpage/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/checkpage/AppScope/resources/base/media/layered_image.json b/ArkUIKit/checkpage/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/checkpage/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/README_zh.md b/ArkUIKit/checkpage/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..4032a34eafdbf019a63462012cf1780c3fd84312 --- /dev/null +++ b/ArkUIKit/checkpage/README_zh.md @@ -0,0 +1,77 @@ +# ArkUI页面检查指南文档示例 + +## 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-inspector-overview.md) +中各场景的开发示例,展示在工程中,帮助开发者更好的理解并合理使用inspectorDe双向定位能力,在DevEco +Studio中快速定位组件、修改属性和调试组件,以提高开发效率。 + +### 效果预览 + +| ![image](screenshot/img2.png) | + +| ![image](screenshot/img3.png) | + +| ![image](screenshot/img4.png) | + +## 使用说明 + +1. 安装编译生成的hap包,并打开应用; +2. 进入首页,可选择不同模块页面; +3. 点击按钮(UIContext查询组件树和组件信息能力)进入ComponentPage,通过点击不同的按钮来触发不同的事件,具体结果在log中查看; +4. 点击按钮(布局回调的基本用法)进入ComponentPage1,通过点击不同的按钮来触发不同的事件,具体结果在log中查看; +5. 点击按钮(组件标识属性的扩展能力)进入ImagePage,显示图片; + +## 工程目录 + +``` + +entry/src/main/ets/ +└── pages + └── ComponentPage.ets (显示UIContext查询组件树和组件信息能力页面) + └── ComponentPage1.ets (显示布局回调页面) + └── ImagePage.ets (显示组件标识属性的扩展能力页面) + └── Index.ets (显示主页面) +└── resources + ├── base + │ ├── element + │ │ ├── color.json + │ │ ├── float.json + │ │ └── string.json + │ └── media + +``` + +## 具体实现 + +1. 在 ArkTS 页面中,可借助 UIContext 与 inspector 接口实现组件树查询与布局监听。例如,先通过 getUIContext() 获取上下文,点击按钮调用 + getFilteredInspectorTree 筛选组件属性,或用 getFilteredInspectorTreeById 精准查询指定 ID 组件(如示例中 “TEXT” + 文本组件),并通过循环打印组件类型、ID 及子组件结构。 +2. 也能注册布局回调,像为图片组件创建 ComponentObserver,在 aboutToAppear 中监听 + layout(布局完成)、draw(绘制完成)等事件,触发时执行自定义逻辑,同时支持通过 off 方法取消监听,快速实现组件调试与布局验证。 + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1.本示例支持标准系统上运行, 支持设备:RK3568等。 + +2.本示例需要使用DevEco Studio 6.0.0 Canary1 (Build Version: 6.0.0.858, built on September 24, 2025)及以上版本才可编译运行。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/Checkpage > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkUIKit/checkpage/build-profile.json5 b/ArkUIKit/checkpage/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3ca5a93fb814017ac4c398aacbdf17b1d8b0a237 --- /dev/null +++ b/ArkUIKit/checkpage/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/code-linter.json5 b/ArkUIKit/checkpage/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/ArkUIKit/checkpage/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/build-profile.json5 b/ArkUIKit/checkpage/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/ArkUIKit/checkpage/entry/build-profile.json5 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/hvigorfile.ts b/ArkUIKit/checkpage/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/checkpage/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/oh-package.json5 b/ArkUIKit/checkpage/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/ArkUIKit/checkpage/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/checkpage/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/checkpage/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/checkpage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/ets/pages/ComponentPage.ets b/ArkUIKit/checkpage/entry/src/main/ets/pages/ComponentPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..5315f0b3b247b0f93fab55346cfd2f38d63babe5 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/ets/pages/ComponentPage.ets @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start uiContextTree_start] +import { UIContext } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +@Entry +@Component +struct ComponentPage { + loopConsole(inspectorStr: string, i: string) { + hilog.info(0x0000, `InsTree ${i}| type: ${JSON.parse(inspectorStr).$type}, ID: ${JSON.parse(inspectorStr).$ID}`, + 'InsTree'); + if (JSON.parse(inspectorStr).$children) { + i += '-'; + for (let index = 0; index < JSON.parse(inspectorStr).$children.length; index++) { + this.loopConsole(JSON.stringify(JSON.parse(inspectorStr).$children[index]), i); + } + } + } + + build() { + Column() { + Text('Hello World') + .fontSize(20) + .id('TEXT') + Button('content').onClick(() => { + const uiContext: UIContext = this.getUIContext(); + let inspectorStr = uiContext.getFilteredInspectorTree(['content']); + hilog.info(0x0000,`InsTree : ${inspectorStr}`, 'InsTree'); + inspectorStr = JSON.stringify(JSON.parse(inspectorStr)); + this.loopConsole(inspectorStr, '-'); + }) + Button('isLayoutInspector').onClick(() => { + const uiContext: UIContext = this.getUIContext(); + let inspectorStr = uiContext.getFilteredInspectorTree(['isLayoutInspector']); + hilog.info(0x0000,`InsTree : ${inspectorStr}`, 'InsTree'); + inspectorStr = JSON.stringify(JSON.parse(inspectorStr).content); + this.loopConsole(inspectorStr, '-'); + }) + Button('getFilteredInspectorTreeById').onClick(() => { + const uiContext: UIContext = this.getUIContext(); + try { + let inspectorStr = uiContext.getFilteredInspectorTreeById('TEXT', 1, ['id', 'src']); + hilog.info(0x0000,`result1: ${inspectorStr}`, 'result1'); + inspectorStr = JSON.stringify(JSON.parse(inspectorStr)['$children'][0]); + hilog.info(0x0000,`result2: ${inspectorStr}`, 'result2'); + inspectorStr = uiContext.getFilteredInspectorTreeById('TEXT', 1, ['src']); + inspectorStr = JSON.stringify(JSON.parse(inspectorStr)['$children'][0]); + hilog.info(0x0000,`result3: ${inspectorStr}`, 'result13'); + } catch (e) { + hilog.error(0x0000, `getFilteredInspectorTreeById error: ${e}`, 'error'); + } + }) + + } + .width('100%') + .height('100%') + } +} + +// [End uiContextTree_start] \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/ets/pages/ComponentPage1.ets b/ArkUIKit/checkpage/entry/src/main/ets/pages/ComponentPage1.ets new file mode 100644 index 0000000000000000000000000000000000000000..123cd6ee7a1ab742867b89e01c18ab18405b714c --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/ets/pages/ComponentPage1.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; + +//[Start componentIdentifier_start] +@Entry +@Component +struct ComponentPage { + build() { + Column() { + Text('Hello World') + .fontSize(20) + .id('TEXT') + .onClick(() => { + hilog.info(0x0000,`Text is clicked`, 'isClicked'); + }) + Button('getInspectorByKey').onClick(() => { + let result = getInspectorByKey('TEXT'); + hilog.info(0x0000,`result is ${result}`, 'result'); + }) + Button('getInspectorTree').onClick(() => { + let result = getInspectorTree(); + hilog.info(0x0000,`result is ${JSON.stringify(result)}`, 'result'); + }) + Button('sendEventByKey').onClick(() => { + sendEventByKey('TEXT', 10, ''); + }) + } + .width('100%') + .height('100%') + } +} + +//[End componentIdentifier_start] \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/ets/pages/ImagePage.ets b/ArkUIKit/checkpage/entry/src/main/ets/pages/ImagePage.ets new file mode 100644 index 0000000000000000000000000000000000000000..8724a825415f16bd5120f9d987e29f08ead4c1ac --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/ets/pages/ImagePage.ets @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start uiContextInspector_start] +import { inspector } from '@kit.ArkUI'; + +@Entry +@Component +struct ImageExample { + build() { + Column() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { + Row({ space: 5 }) { + // 可以替换成本地存在的图片 + Image($r('app.media.startIcon')) + .width(110) + .height(110) + .border({ width: 1 }) + .id('IMAGE_ID') + } + } + }.height(320).width(360).padding({ right: 10, top: 10 }) + } + + listener: inspector.ComponentObserver = this.getUIContext().getUIInspector().createComponentObserver('IMAGE_ID'); + + aboutToAppear() { + let onLayoutComplete: () => void = (): void => { + // 补充待实现的功能 + }; + let onDrawComplete: () => void = (): void => { + // 补充待实现的功能 + }; + let onDrawChildrenComplete: () => void = (): void => { + // 补充待实现的功能 + }; + let funcLayout = onLayoutComplete; // 绑定当前js对象 + let funcDraw = onDrawComplete; // 绑定当前js对象 + let funcDrawChildren = onDrawChildrenComplete; // 绑定当前js对象 + let offFuncLayout = onLayoutComplete; // 绑定当前js对象 + let offFuncDraw = onDrawComplete; // 绑定当前js对象 + let offFuncDrawChildren = onDrawChildrenComplete; // 绑定当前js对象 + + this.listener.on('layout', funcLayout); + this.listener.on('draw', funcDraw); + this.listener.on('drawChildren', funcDrawChildren); + + // 通过句柄向对应的查询条件取消注册回调,由开发者自行决定在何时调用。 + // this.listener.off('layout', OffFuncLayout) + // this.listener.off('draw', OffFuncDraw) + // this.listener.off('drawChildren', OffFuncDrawChildren) + } +} +// [End uiContextInspector_start] \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/ets/pages/Index.ets b/ArkUIKit/checkpage/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..191e6ba43ba7074650369cba176a20cd19695a3a --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { UIContext } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Column(){ + // $r('app.media.text1')需要替换为开发者所需的文本资源文件 + Button($r('app.string.text1')) + .onClick(()=>{ + const uiContext: UIContext = this.getUIContext(); + const router = uiContext.getRouter(); + router.pushUrl({ + url:'pages/ComponentPage' + }) + }) + // $r('app.media.text2')需要替换为开发者所需的文本资源文件 + Button($r('app.string.text2')) + .onClick(()=>{ + const uiContext: UIContext = this.getUIContext(); + const router = uiContext.getRouter(); + router.pushUrl({ + url:'pages/ComponentPage1' + }) + }) + // $r('app.media.text3')需要替换为开发者所需的文本资源文件 + Button($r('app.string.text3')) + .onClick(()=>{ + const uiContext: UIContext = this.getUIContext(); + const router = uiContext.getRouter(); + router.pushUrl({ + url:'pages/ImagePage' + }) + }) + } + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/module.json5 b/ArkUIKit/checkpage/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..476f4f508edb44dc9edfe115808545c33b284e0b --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/module.json5 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/element/color.json b/ArkUIKit/checkpage/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/element/float.json b/ArkUIKit/checkpage/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a0a93dd91fd48f08f3a9532c76e9b26e68d4c034 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/element/string.json b/ArkUIKit/checkpage/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4424da75cb3d6770ba520c3bd7313879d871b11b --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "text1", + "value": "UIContext查询组件树和组件信息能力" + }, + { + "name": "text2", + "value": "布局回调的基本用法" + }, + { + "name": "text3", + "value": "组件标识属性的扩展能力" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/media/background.png b/ArkUIKit/checkpage/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/checkpage/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/checkpage/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/checkpage/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/checkpage/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/checkpage/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/checkpage/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/checkpage/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/checkpage/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..4a4da5aca17a1b8fa2ec346f846fb4fdbf1940b2 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/ComponentPage", + "pages/ComponentPage1", + "pages/ImagePage" + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/resources/dark/element/color.json b/ArkUIKit/checkpage/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/main/syscap.json b/ArkUIKit/checkpage/entry/src/main/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..d14edde4277db282075a6639d65e40ddbbf0f2a2 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/main/syscap.json @@ -0,0 +1,20 @@ +{ + "devices": { + "general": [ + "default" + ], + "custom": [ + { + "xts": [ + "SystemCapability.ArkUI.ArkUI.Full", + "SystemCapability.ArkUI.ArkUI.Circle", + "SystemCapability.Test.UiTest", + "SystemCapability.Ability.AbilityRuntime.Core", + "SystemCapability.Notification.Emitter", + "SystemCapability.MiscServices.Time", + "SystemCapability.FileManagement.File.FileIO" + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f30942b81554a399e89aa253c7089eca4f8d8d1 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a663e288364a56b0ea2245e47f9af9468864e2e --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; +import CheckPage from './checkPage/CheckPage.test'; + +export default function testsuite() { + abilityTest(); + CheckPage(); +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/checkPage/CheckPage.test.ets b/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/checkPage/CheckPage.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..37da84f290244a383d5ab25ad10d5a2e2ab8adcb --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/ohosTest/ets/test/checkPage/CheckPage.test.ets @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Want } from '@kit.AbilityKit'; +import { abilityDelegatorRegistry, Driver ,Component, Point, On, ON } from '@kit.TestKit'; + +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); +async function getResourceString(resource: Resource): Promise { + let manage = delegator.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; +} +export default function CheckPage() { + describe('CheckPage', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + let driver = Driver.create(); + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + beforeAll(async () => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + const want: Want = { + bundleName: 'com.sample.checkpage', + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(async (done:Function) => { + const driver = Driver.create(); + await driver.pressBack(); + await driver.delayMs(2000); + done() + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /** + * @tc.number ArkUI_CheckPage001 + * @tc.name CheckPageTest_001 + * @tc.desc 自定义组件节点操作节点树 + * @tc.level: Level 1 + */ + it('CheckPageTest_001', 0, async (done:Function) => { + const driver = Driver.create(); + const button = await driver.findComponent((ON.text(await getResourceString($r('app.string.text1'))))); + await button.click(); + await driver.delayMs(500); + const button1 = await driver.findComponent(ON.text('content')); + await button1.click(); + await driver.delayMs(500); + const button2 = await driver.findComponent(ON.text('isLayoutInspector')); + await button2.click(); + await driver.delayMs(500); + const button3 = await driver.findComponent(ON.text('getFilteredInspectorTreeById')); + await button3.click(); + await driver.delayMs(500); + done() + }) + + /** + * @tc.number ArkUI_CheckPage002 + * @tc.name CheckPageTest_002 + * @tc.desc 自定义组件节点操作节点树 + * @tc.level: Level 1 + */ + it('CheckPageTest_002', 0, async (done:Function) => { + const driver = Driver.create(); + const button = await driver.findComponent((ON.text(await getResourceString($r('app.string.text2'))))); + await button.click(); + await driver.delayMs(500); + const button1 = await driver.findComponent(ON.text('getInspectorByKey')); + await button1.click(); + await driver.delayMs(500); + const button2 = await driver.findComponent(ON.text('getInspectorTree')); + await button2.click(); + await driver.delayMs(500); + const button3 = await driver.findComponent(ON.text('sendEventByKey')); + await button3.click(); + await driver.delayMs(500); + done() + }) + + /** + * @tc.number ArkUI_CheckPage003 + * @tc.name CheckPageTest_003 + * @tc.desc 自定义组件节点操作节点树 + * @tc.level: Level 1 + */ + it('CheckPageTest_003', 0, async (done:Function) => { + const driver = Driver.create(); + const button = await driver.findComponent((ON.text(await getResourceString($r('app.string.text3'))))); + await button.click(); + await driver.delayMs(500); + done() + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/ohosTest/module.json5 b/ArkUIKit/checkpage/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f6bdce9946cb02c0385e5a8836c133c93945013d --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/checkpage/entry/src/ohosTest/syscap.json b/ArkUIKit/checkpage/entry/src/ohosTest/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..4fcf7cc73094301809bb72d47cd9857354e6c3dc --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/ohosTest/syscap.json @@ -0,0 +1,21 @@ +{ + "devices": { + "general": [ + "default", + "tablet" + ], + "custom": [ + { + "xts": [ + "SystemCapability.ArkUI.ArkUI.Full", + "SystemCapability.ArkUI.ArkUI.Circle", + "SystemCapability.Test.UiTest", + "SystemCapability.Ability.AbilityRuntime.Core", + "SystemCapability.Notification.Emitter", + "SystemCapability.MiscServices.Time", + "SystemCapability.FileManagement.File.FileIO" + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/test/List.test.ets b/ArkUIKit/checkpage/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/entry/src/test/LocalUnit.test.ets b/ArkUIKit/checkpage/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/checkpage/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/hvigor/hvigor-config.json5 b/ArkUIKit/checkpage/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/ArkUIKit/checkpage/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/checkpage/hvigorfile.ts b/ArkUIKit/checkpage/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/ArkUIKit/checkpage/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/checkpage/oh-package.json5 b/ArkUIKit/checkpage/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/ArkUIKit/checkpage/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/checkpage/ohosTest.md b/ArkUIKit/checkpage/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..24ee5bc97f949b6c82910f900fa533b4e81bebb9 --- /dev/null +++ b/ArkUIKit/checkpage/ohosTest.md @@ -0,0 +1,5 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +|------------------------------| ------------ |--------------------------|-----------| -------- | +| 组件页面 | 设备正常运行 | 点击"UIContext查询组件树和组件信息能力" | 页面加载成功 | Pass | +| 组件页面 | 设备正常运行 | 点击"布局回调的基本用法" | 页面加载成功 | Pass | +| 图片示例页面 | 设备正常运行 | 点击"组件标识属性的扩展能力" | 页面加载成功 | Pass | \ No newline at end of file diff --git a/ArkUIKit/checkpage/screenshot/img1.png b/ArkUIKit/checkpage/screenshot/img1.png new file mode 100644 index 0000000000000000000000000000000000000000..722c8f02569d817a9c0f8feb1f6551087caf68bd Binary files /dev/null and b/ArkUIKit/checkpage/screenshot/img1.png differ diff --git a/ArkUIKit/checkpage/screenshot/img2.png b/ArkUIKit/checkpage/screenshot/img2.png new file mode 100644 index 0000000000000000000000000000000000000000..443662cc97ad4085f407dd9f60a5157fc3338cb6 Binary files /dev/null and b/ArkUIKit/checkpage/screenshot/img2.png differ diff --git a/ArkUIKit/checkpage/screenshot/img3.png b/ArkUIKit/checkpage/screenshot/img3.png new file mode 100644 index 0000000000000000000000000000000000000000..9aecd87eed61cae2cc75e80d708a17fe306352d3 Binary files /dev/null and b/ArkUIKit/checkpage/screenshot/img3.png differ diff --git a/ArkUIKit/checkpage/screenshot/img4.png b/ArkUIKit/checkpage/screenshot/img4.png new file mode 100644 index 0000000000000000000000000000000000000000..baf2b56fbd01c8c7110c0a4a593a2f71da41b943 Binary files /dev/null and b/ArkUIKit/checkpage/screenshot/img4.png differ