diff --git a/function/ui_compare/capidemo/.gitignore b/function/ui_compare/capidemo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..fbabf771011fe78f9919db0b1195ab6cadffc2b0 --- /dev/null +++ b/function/ui_compare/capidemo/.gitignore @@ -0,0 +1,11 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test \ No newline at end of file diff --git a/function/ui_compare/capidemo/AppScope/app.json5 b/function/ui_compare/capidemo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5ff6b7cabfbd38de7eb8e5bef44b341c6f1c979b --- /dev/null +++ b/function/ui_compare/capidemo/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.openharmony.arkui_capi_demo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/function/ui_compare/capidemo/AppScope/resources/base/element/string.json b/function/ui_compare/capidemo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0053930df2a5d99cd3bcd6bbd91defc4995799c4 --- /dev/null +++ b/function/ui_compare/capidemo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ArkUI_CAPI_Demo" + } + ] +} diff --git a/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png b/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png differ diff --git a/function/ui_compare/capidemo/README.md b/function/ui_compare/capidemo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8058e141d8a0ef2bd0f9fd4d99fea071078e3e6d --- /dev/null +++ b/function/ui_compare/capidemo/README.md @@ -0,0 +1,3 @@ +# capidemo + +c api demo project \ No newline at end of file diff --git a/function/ui_compare/capidemo/code-linter.json5 b/function/ui_compare/capidemo/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eff2dbc9b8a447e5a99b0aab08ca2b766d786bf6 --- /dev/null +++ b/function/ui_compare/capidemo/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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": { + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/.gitignore b/function/ui_compare/capidemo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/build-profile.json5 b/function/ui_compare/capidemo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b4ebac31a62c3558f1b1e4558eea73ed0ad99cf --- /dev/null +++ b/function/ui_compare/capidemo/entry/build-profile.json5 @@ -0,0 +1,20 @@ +{ + "apiType": 'stageMode', + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "armeabi-v7a", "x86_64"], + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/hvigorfile.ts b/function/ui_compare/capidemo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/function/ui_compare/capidemo/entry/oh-package-lock.json5 b/function/ui_compare/capidemo/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4a60c8988b7b15f7e5cd94314fb18ff527b409f8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/oh-package-lock.json5 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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. + */ + +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@types/libnativerender.so@src/main/cpp/types/libnativerender": "@types/libnativerender.so@src/main/cpp/types/libnativerender" + }, + "packages": { + "@types/libnativerender.so@src/main/cpp/types/libnativerender": { + "name": "libnativerender.so", + "version": "0.1.0", + "resolved": "src/main/cpp/types/libnativerender", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/oh-package.json5 b/function/ui_compare/capidemo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9ea702bf2dc637bf9377c165e3d0f99065d50903 --- /dev/null +++ b/function/ui_compare/capidemo/entry/oh-package.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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. + */ + +{ + "license": "", + "devDependencies": { + "@types/libnativerender.so": "file:./src/main/cpp/types/libnativerender" + }, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt b/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f13e38b237bf042f043eec7d1b4a3db3233a1c8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,99 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(XComponent) + +# Automatically refresh source files +file(GLOB_RECURSE ALL_CPP_FILES ${PROJECT_SOURCE_DIR}/*.cpp) +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +add_definitions(-DOHOS_PLATFORM) + + +function(getAllCpp path parentDir exclude) + set(LOCAL_LIST) + file(GLOB ALL_DIR RELATIVE ${parentDir} ${parentDir}/*) + foreach(ITEM ${ALL_DIR}) + set(ITEM_DIR ${parentDir}/${ITEM}) + set(FIND_BOOL FALSE) + foreach(dir ${exclude}) + if("${dir}" STREQUAL "${ITEM}") + set(FIND_BOOL TRUE) + break() + endif() + endforeach() + if ("${FIND_BOOL}" STREQUAL "FALSE") + if(EXISTS ${ITEM_DIR}) + file(GLOB ALL_FILE ${ITEM_DIR}/*.cpp) + list(APPEND LOCAL_LIST ${ALL_FILE}) + endif() + endif () + endforeach() + set(path ${LOCAL_LIST} PARENT_SCOPE) +endfunction() + +set(path) +set(exclude "types") +set(CMAKE_CXX_STANDARD 17) +getAllCpp("${path}" ${PROJECT_SOURCE_DIR} "${exclude}") + +add_library(nativerender SHARED + napi_init.cpp + ${path} +) +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + +find_library( + # Sets the name of the path variable. + libace-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_ndk.z +) + +find_library( + # Sets the name of the path variable. + libnapi-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_napi.z +) + +find_library( + # Sets the name of the path variable. + libuv-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + uv +) + +find_library( + # Sets the name of the path variable. + EGL-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + EGL +) + +find_library( + # Sets the name of the path variable. + GLES-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + GLESv3 +) + +target_include_directories(nativerender PUBLIC + ${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include + PUBLIC component +) + +target_link_libraries(nativerender PUBLIC + libnative_drawing.so ${EGL-lib} ${GLES-lib} ${hilog-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib}) +target_link_libraries(nativerender PUBLIC libhilog_ndk.z.so libpixelmap.so libudmf.so) + diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h new file mode 100644 index 0000000000000000000000000000000000000000..b347ab879e54d4c471a2c45b9f0456b2ddcb6df1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMON_TEST_H +#define ARKUI_CAPI_DEMO_COMMON_TEST_H + +#include +#include + +namespace ArkUICApiDemo { + +#define PARAM_0 0 +#define PARAM_1 1 +#define PARAM_2 2 +#define PARAM_3 3 +#define PARAM_4 4 +#define PARAM_5 5 +#define PARAM_6 6 +#define PARAM_7 7 +#define PARAM_8 8 +#define PARAM_9 9 +#define PARAM_10 10 +#define PARAM_11 11 +#define PARAM_12 12 +#define PARAM_64 64 +#define DEFAULT_MARGIN 10 +#define SIZE_5 5 +#define SIZE_10 10 +#define SIZE_30 30 +#define SIZE_50 50 +#define SIZE_100 100 +#define SIZE_150 150 +#define SIZE_180 180 +#define SIZE_200 200 +#define SIZE_230 230 +#define SIZE_250 250 +#define SIZE_300 300 +#define SIZE_350 350 +#define SIZE_400 400 +#define SIZE_450 450 +#define SIZE_500 500 +#define SIZE_600 600 +#define DEFAULT_VALUE_TAG 7000 +#define ENUM_ABNORMAL_VALUE 500 +#define INVALID_PARAM 401 +#define COLOR_RED 0xFFFF0000 +#define COLOR_GREEN 0xFF00FF00 +#define COLOR_BLUE 0xFF0000FF +#define COLOR_YELLOW 0xFFFFFF00 +#define COLOR_PURPLE 0xFFFF11FF +#define COLOR_PINK 0xFFFFC0CB +#define COLOR_GRAY 0xFFDDDDDD +#define COLOR_TRANSPARENT 0x00000000 +#define COLOR_BLACK 0xFF000000 +#define COLOR_WHITE 0xFFFFFFFF +#define COLOR_LIGHT_BLUE 0xFF00FFFF +#define ON_CLICK_EVENT_ID 6001 +#define ON_FOCUS_EVENT_ID 6002 +#define ON_TOUCH_EVENT_ID 6003 +#define ON_AREA_CHANGE_EVENT_ID 6004 +#define ON_APPEAR_EVENT_ID 6005 +#define ON_BLUR_EVENT_ID 6006 +#define ON_CHANGE_EVENT_ID 6007 +#define ON_SUBMIT_EVENT_ID 6008 +#define ON_CUT_EVENT_ID 6009 +#define ON_PASTE_EVENT_ID 6010 +#define ON_MEASURE_EVENT_ID 6011 +#define ON_LAYOUT_EVENT_ID 6012 +#define ON_DRAW_EVENT_ID 6013 +#define ON_CUSTOM_EVENT_1_ID 9001 +#define ON_CUSTOM_EVENT_2_ID 9002 +#define ON_CUSTOM_EVENT_3_ID 9003 +#define ON_CUSTOM_EVENT_4_ID 9004 +#define ON_CUSTOM_EVENT_5_ID 9005 +#define ON_CUSTOM_EVENT_6_ID 9006 +#define PARAM_NEGATIVE_1 (-1) +#define PARAM_NEGATIVE_100 (-100) + +/** + * Log print domain. + */ +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMON_TEST_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityrole_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityrole_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d10b7918ab0f7e5d011e5e6d91d1d0bffb6d216 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityrole_test.cpp @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2024 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 "commonattrs_accessibilityrole_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto GetAccessibilityRole( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, ArkUI_AttributeItem item) +{ + const ArkUI_AttributeItem* role_item_ptr = nodeAPI->getAttribute(nodeHandle, NODE_ACCESSIBILITY_ROLE); + if (role_item_ptr->value[0].u32 == item.value[0].u32) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + return nodeHandle; +} + +static auto SetAccessibilityRole(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t role) +{ + ArkUI_NumberValue role_value[] = { { .u32 = role } }; + ArkUI_AttributeItem role_item = { role_value, sizeof(role_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_ROLE, &role_item); + nodeHandle = GetAccessibilityRole(nodeAPI, nodeHandle, role_item); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t role) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetAccessibilityRole(nodeAPI, nodeHandle, role); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateChildNode( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type, uint32_t role) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + childNode = SetText(nodeAPI, childNode, role); + return childNode; +} + +static auto CreateCaseNodeOne(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_CUSTOM); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_TEXT); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_SPAN); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_IMAGE_SPAN); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_IMAGE); + return parentNode; +} + +static auto CreateCaseNodeTwo(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_TOGGLE); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_LOADING_PROGRESS); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_TEXT_INPUT); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_TEXT_AREA); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_BUTTON); + return parentNode; +} + +static auto CreateCaseNodeThree(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_PROGRESS); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_CHECKBOX); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_XCOMPONENT); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_DATE_PICKER); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_TIME_PICKER); + return parentNode; +} + +static auto CreateCaseNodeFour(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_TEXT_PICKER); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_CALENDAR_PICKER); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_SLIDER); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_RADIO); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_IMAGE_ANIMATOR); + return parentNode; +} + +static auto CreateCaseNodeFive(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_STACK); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_SWIPER); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_SCROLL); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_LIST); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_LIST_ITEM); + return parentNode; +} + +static auto CreateCaseNodeSix(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_LIST_ITEM_GROUP); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_COLUMN); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_ROW); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_FLEX); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_REFRESH); + return parentNode; +} + +static auto CreateCaseNodeSeven(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_WATER_FLOW); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_FLOW_ITEM); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_RELATIVE_CONTAINER); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_GRID); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_GRID_ITEM); + return parentNode; +} + +static auto CreateCaseNodeEight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto text1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, ARKUI_NODE_CUSTOM_SPAN); + auto text2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, PARAM_NEGATIVE_100); + auto text3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, SIZE_20); + auto text4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, SIZE_999); + auto text5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_TEXT, SIZE_1016); + return parentNode; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row5 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row6 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row7 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row8 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + row1 = CreateCaseNodeOne(nodeAPI, row1); + row2 = CreateCaseNodeTwo(nodeAPI, row2); + row3 = CreateCaseNodeThree(nodeAPI, row3); + row4 = CreateCaseNodeFour(nodeAPI, row4); + row5 = CreateCaseNodeFive(nodeAPI, row5); + row6 = CreateCaseNodeSix(nodeAPI, row6); + row7 = CreateCaseNodeSeven(nodeAPI, row7); + row8 = CreateCaseNodeEight(nodeAPI, row8); + return column; +} + +napi_value CommonAttrsAccessibilityRoleTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityRoleTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityRoleTest", + "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityRoleTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityrole_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityrole_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b772ded8e72da64dd2aee0cb37a8697d244eb7d1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityrole_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYROLE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYROLE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_20 20 +#define SIZE_999 999 +#define SIZE_1016 1016 + +class CommonAttrsAccessibilityRoleTest { +public: + ~CommonAttrsAccessibilityRoleTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYROLE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilitystate_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilitystate_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..905973f8df0199a2460f6e4f98e2c6d32a939b01 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilitystate_test.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2024 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 "commonattrs_accessibilitystate_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetDisabledAccessibilityState( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t isDisabled) +{ + ArkUI_AccessibilityState* state = OH_ArkUI_AccessibilityState_Create(); + ArkUI_AttributeItem item = {}; + item.object = state; + OH_ArkUI_AccessibilityState_SetDisabled(state, isDisabled); + if (OH_ArkUI_AccessibilityState_IsDisabled(state) == isDisabled) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_STATE, &item); + return nodeHandle; +} + +static auto SetSelectedAccessibilityState( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t isSelected) +{ + ArkUI_AccessibilityState* state = OH_ArkUI_AccessibilityState_Create(); + ArkUI_AttributeItem item = {}; + item.object = state; + OH_ArkUI_AccessibilityState_SetSelected(state, isSelected); + if (OH_ArkUI_AccessibilityState_IsSelected(state) == isSelected) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_STATE, &item); + return nodeHandle; +} + +static auto SetCheckedStateAccessibilityState( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t isCheckedState) +{ + ArkUI_AccessibilityState* state = OH_ArkUI_AccessibilityState_Create(); + ArkUI_AttributeItem item = {}; + item.object = state; + OH_ArkUI_AccessibilityState_SetCheckedState(state, isCheckedState); + if (OH_ArkUI_AccessibilityState_GetCheckedState(state) == isCheckedState) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_STATE, &item); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateChildNodeText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + childNode = SetText(nodeAPI, childNode); + return childNode; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto text1 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text2 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text3 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text4 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text5 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text6 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text7 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text8 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text9 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text10 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text11 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text12 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + + text1 = SetDisabledAccessibilityState(nodeAPI, text1, PARAM_1); + text2 = SetDisabledAccessibilityState(nodeAPI, text2, PARAM_0); + text3 = SetDisabledAccessibilityState(nodeAPI, text3, PARAM_2); + text4 = SetDisabledAccessibilityState(nodeAPI, text4, PARAM_NEGATIVE_1); + text5 = SetSelectedAccessibilityState(nodeAPI, text5, PARAM_1); + text6 = SetSelectedAccessibilityState(nodeAPI, text6, PARAM_0); + text7 = SetSelectedAccessibilityState(nodeAPI, text7, PARAM_2); + text8 = SetSelectedAccessibilityState(nodeAPI, text8, PARAM_NEGATIVE_1); + text9 = SetCheckedStateAccessibilityState(nodeAPI, text9, PARAM_1); + text10 = SetCheckedStateAccessibilityState(nodeAPI, text10, PARAM_0); + text11 = SetCheckedStateAccessibilityState(nodeAPI, text11, PARAM_2); + text12 = SetCheckedStateAccessibilityState(nodeAPI, text12, PARAM_NEGATIVE_1); + return column; +} + +napi_value CommonAttrsAccessibilityStateTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityStateTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityStateTest", + "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityStateTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilitystate_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilitystate_test.h new file mode 100644 index 0000000000000000000000000000000000000000..2e3b271e981af06f5530b24d5f8299eaef4980c1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilitystate_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYSTATE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYSTATE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsAccessibilityStateTest { +public: + ~CommonAttrsAccessibilityStateTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYSTATE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityvalue_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityvalue_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12b0f624e047621994311dd6e34f7bb3fc04921d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityvalue_test.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2024 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 "commonattrs_accessibilityvalue_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetMinAccessibilityValue(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t min) +{ + ArkUI_AccessibilityValue* value = OH_ArkUI_AccessibilityValue_Create(); + ArkUI_AttributeItem item = {}; + item.object = value; + OH_ArkUI_AccessibilityValue_SetMin(value, min); + if (OH_ArkUI_AccessibilityValue_GetMin(value) == min) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_VALUE, &item); + return nodeHandle; +} + +static auto SetMaxAccessibilityValue(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t max) +{ + ArkUI_AccessibilityValue* value = OH_ArkUI_AccessibilityValue_Create(); + ArkUI_AttributeItem item = {}; + item.object = value; + OH_ArkUI_AccessibilityValue_SetMax(value, max); + if (OH_ArkUI_AccessibilityValue_GetMax(value) == max) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_VALUE, &item); + return nodeHandle; +} + +static auto SetCurrentAccessibilityValue(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t current) +{ + ArkUI_AccessibilityValue* value = OH_ArkUI_AccessibilityValue_Create(); + ArkUI_AttributeItem item = {}; + item.object = value; + OH_ArkUI_AccessibilityValue_SetCurrent(value, current); + if (OH_ArkUI_AccessibilityValue_GetCurrent(value) == current) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_VALUE, &item); + return nodeHandle; +} + +static auto SetTextAccessibilityValue(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* text) +{ + ArkUI_AccessibilityValue* value = OH_ArkUI_AccessibilityValue_Create(); + ArkUI_AttributeItem item = {}; + item.object = value; + OH_ArkUI_AccessibilityValue_SetText(value, text); + const char* getText = OH_ArkUI_AccessibilityValue_GetText(value); + if (strcmp(text, getText) == 0) { + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + } + nodeAPI->setAttribute(nodeHandle, NODE_ACCESSIBILITY_VALUE, &item); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateChildNodeText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + childNode = SetText(nodeAPI, childNode); + return childNode; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto text1 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text2 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text3 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text4 = CreateChildNodeText(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text5 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text6 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text7 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text8 = CreateChildNodeText(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text9 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text10 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text11 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text12 = CreateChildNodeText(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text13 = CreateChildNodeText(nodeAPI, row4, ARKUI_NODE_TEXT); + auto text14 = CreateChildNodeText(nodeAPI, row4, ARKUI_NODE_TEXT); + + text1 = SetMinAccessibilityValue(nodeAPI, text1, SIZE_100); + text2 = SetMinAccessibilityValue(nodeAPI, text2, PARAM_0); + text3 = SetMinAccessibilityValue(nodeAPI, text3, PARAM_NEGATIVE_100); + text4 = SetMinAccessibilityValue(nodeAPI, text4, SIZE_20000); + text5 = SetMaxAccessibilityValue(nodeAPI, text5, SIZE_100); + text6 = SetMaxAccessibilityValue(nodeAPI, text6, PARAM_0); + text7 = SetMaxAccessibilityValue(nodeAPI, text7, PARAM_NEGATIVE_100); + text8 = SetMaxAccessibilityValue(nodeAPI, text8, SIZE_20000); + text9 = SetCurrentAccessibilityValue(nodeAPI, text9, SIZE_100); + text10 = SetCurrentAccessibilityValue(nodeAPI, text10, PARAM_0); + text11 = SetCurrentAccessibilityValue(nodeAPI, text11, PARAM_NEGATIVE_100); + text12 = SetCurrentAccessibilityValue(nodeAPI, text12, SIZE_20000); + text13 = SetTextAccessibilityValue(nodeAPI, text13, + "Hello, World!,h e l l o,!@#$%^&*()_+,1234567890,你好,世界,'example', " + "\"example\"Carriage return: \r,Newline character:\n, tab character: \t"); + text14 = SetTextAccessibilityValue(nodeAPI, text14, ""); + + return column; +} + +napi_value CommonAttrsAccessibilityValueTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityValueTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityValueTest", + "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityValueTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityvalue_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityvalue_test.h new file mode 100644 index 0000000000000000000000000000000000000000..846552e1b920f6b28e94b9dc75982d4ab226f7f4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_accessibilityvalue_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYVALUE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYVALUE_TEST_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_20000 20000 + +class CommonAttrsAccessibilityValueTest { +public: + ~CommonAttrsAccessibilityValueTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ACCESSIBILITYVALUE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_alignment_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_alignment_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f29fe9cf1a65cd309c67e945c0d4799d936640f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_alignment_test.cpp @@ -0,0 +1,381 @@ + +/* + * Copyright (c) 2024 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 "commonattrs_alignment_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetAlignment(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ALIGNMENT, &item); + return nodeHandle; +} + +static auto SetContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_CONTENT, &content_item); + return nodeHandle; +} + +static auto SetStack(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t align) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_90); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_90); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetAlignment(nodeAPI, nodeHandle, align); + return nodeHandle; +} + +static auto SetButton(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_30); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_30); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float size) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, size); + nodeHandle = SetHeight(nodeAPI, nodeHandle, size); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float size, int32_t align) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, size); + nodeHandle = SetHeight(nodeAPI, nodeHandle, size); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetAlignment(nodeAPI, nodeHandle, align); + nodeHandle = SetContent(nodeAPI, nodeHandle, "AA"); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateChildNodeButton(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + childNode = SetButton(nodeAPI, childNode); + return childNode; +} + +static auto CreateChildNodeText( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type, float size) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + childNode = SetText(nodeAPI, childNode, size); + return childNode; +} + +static auto CreateParentNodePage1(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto stack1 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_STACK); + auto stack2 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_STACK); + auto stack3 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_STACK); + auto stack4 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_STACK); + auto stack5 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_STACK); + auto stack6 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_STACK); + auto stack7 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_STACK); + auto stack8 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_STACK); + auto stack9 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_STACK); + auto stack10 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_STACK); + auto stack11 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_STACK); + auto stack12 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_STACK); + auto button1 = CreateChildNodeButton(nodeAPI, stack1, ARKUI_NODE_BUTTON); + auto button2 = CreateChildNodeButton(nodeAPI, stack2, ARKUI_NODE_BUTTON); + auto button3 = CreateChildNodeButton(nodeAPI, stack3, ARKUI_NODE_BUTTON); + auto button4 = CreateChildNodeButton(nodeAPI, stack4, ARKUI_NODE_BUTTON); + auto button5 = CreateChildNodeButton(nodeAPI, stack5, ARKUI_NODE_BUTTON); + auto button6 = CreateChildNodeButton(nodeAPI, stack6, ARKUI_NODE_BUTTON); + auto button7 = CreateChildNodeButton(nodeAPI, stack7, ARKUI_NODE_BUTTON); + auto button8 = CreateChildNodeButton(nodeAPI, stack8, ARKUI_NODE_BUTTON); + auto button9 = CreateChildNodeButton(nodeAPI, stack9, ARKUI_NODE_BUTTON); + auto button10 = CreateChildNodeButton(nodeAPI, stack10, ARKUI_NODE_BUTTON); + auto button11 = CreateChildNodeButton(nodeAPI, stack11, ARKUI_NODE_BUTTON); + auto button12 = CreateChildNodeButton(nodeAPI, stack12, ARKUI_NODE_BUTTON); + stack1 = SetStack(nodeAPI, stack1, ARKUI_ALIGNMENT_TOP_START); + stack2 = SetStack(nodeAPI, stack2, ARKUI_ALIGNMENT_TOP); + stack3 = SetStack(nodeAPI, stack3, ARKUI_ALIGNMENT_TOP_END); + stack4 = SetStack(nodeAPI, stack4, ARKUI_ALIGNMENT_START); + stack5 = SetStack(nodeAPI, stack5, ARKUI_ALIGNMENT_CENTER); + stack6 = SetStack(nodeAPI, stack6, ARKUI_ALIGNMENT_END); + stack7 = SetStack(nodeAPI, stack7, ARKUI_ALIGNMENT_BOTTOM_START); + stack8 = SetStack(nodeAPI, stack8, ARKUI_ALIGNMENT_BOTTOM); + stack9 = SetStack(nodeAPI, stack9, ARKUI_ALIGNMENT_BOTTOM_END); + stack10 = SetStack(nodeAPI, stack10, PARAM_NEGATIVE_1); + stack11 = SetStack(nodeAPI, stack11, PARAM_9); + stack12 = SetStack(nodeAPI, stack12, ARKUI_ALIGNMENT_TOP_START); + nodeAPI->resetAttribute(stack12, NODE_ALIGNMENT); + return column; +} + +static auto CreateParentNodePage2(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto stack1 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_STACK); + auto stack2 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_STACK); + auto stack3 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_STACK); + auto stack4 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_STACK); + auto stack5 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_STACK); + auto stack6 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_STACK); + auto stack7 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_STACK); + auto stack8 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_STACK); + auto stack9 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_STACK); + auto stack10 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_STACK); + auto stack11 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_STACK); + auto stack12 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_STACK); + auto text1 = CreateChildNodeText(nodeAPI, stack1, ARKUI_NODE_TEXT, SIZE_30); + auto text2 = CreateChildNodeText(nodeAPI, stack2, ARKUI_NODE_TEXT, SIZE_30); + auto text3 = CreateChildNodeText(nodeAPI, stack3, ARKUI_NODE_TEXT, SIZE_30); + auto text4 = CreateChildNodeText(nodeAPI, stack4, ARKUI_NODE_TEXT, SIZE_30); + auto text5 = CreateChildNodeText(nodeAPI, stack5, ARKUI_NODE_TEXT, SIZE_30); + auto text6 = CreateChildNodeText(nodeAPI, stack6, ARKUI_NODE_TEXT, SIZE_30); + auto text7 = CreateChildNodeText(nodeAPI, stack7, ARKUI_NODE_TEXT, SIZE_30); + auto text8 = CreateChildNodeText(nodeAPI, stack8, ARKUI_NODE_TEXT, SIZE_30); + auto text9 = CreateChildNodeText(nodeAPI, stack9, ARKUI_NODE_TEXT, SIZE_30); + auto text10 = CreateChildNodeText(nodeAPI, stack10, ARKUI_NODE_TEXT, SIZE_30); + auto text11 = CreateChildNodeText(nodeAPI, stack11, ARKUI_NODE_TEXT, SIZE_30); + auto text12 = CreateChildNodeText(nodeAPI, stack12, ARKUI_NODE_TEXT, SIZE_30); + stack1 = SetStack(nodeAPI, stack1, ARKUI_ALIGNMENT_TOP_START); + stack2 = SetStack(nodeAPI, stack2, ARKUI_ALIGNMENT_TOP); + stack3 = SetStack(nodeAPI, stack3, ARKUI_ALIGNMENT_TOP_END); + stack4 = SetStack(nodeAPI, stack4, ARKUI_ALIGNMENT_START); + stack5 = SetStack(nodeAPI, stack5, ARKUI_ALIGNMENT_CENTER); + stack6 = SetStack(nodeAPI, stack6, ARKUI_ALIGNMENT_END); + stack7 = SetStack(nodeAPI, stack7, ARKUI_ALIGNMENT_BOTTOM_START); + stack8 = SetStack(nodeAPI, stack8, ARKUI_ALIGNMENT_BOTTOM); + stack9 = SetStack(nodeAPI, stack9, ARKUI_ALIGNMENT_BOTTOM_END); + stack10 = SetStack(nodeAPI, stack10, PARAM_NEGATIVE_1); + stack11 = SetStack(nodeAPI, stack11, PARAM_9); + stack12 = SetStack(nodeAPI, stack12, ARKUI_ALIGNMENT_TOP_START); + nodeAPI->resetAttribute(stack12, NODE_ALIGNMENT); + return column; +} + +static auto CreateParentNodePage3(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto text1 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text2 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text3 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_TEXT); + auto text4 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text5 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text6 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_TEXT); + auto text7 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text8 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text9 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_TEXT); + auto text10 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_TEXT); + auto text11 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_TEXT); + auto text12 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_TEXT); + text1 = SetText(nodeAPI, text1, SIZE_90, ARKUI_ALIGNMENT_TOP_START); + text2 = SetText(nodeAPI, text2, SIZE_90, ARKUI_ALIGNMENT_TOP); + text3 = SetText(nodeAPI, text3, SIZE_90, ARKUI_ALIGNMENT_TOP_END); + text4 = SetText(nodeAPI, text4, SIZE_90, ARKUI_ALIGNMENT_START); + text5 = SetText(nodeAPI, text5, SIZE_90, ARKUI_ALIGNMENT_CENTER); + text6 = SetText(nodeAPI, text6, SIZE_90, ARKUI_ALIGNMENT_END); + text7 = SetText(nodeAPI, text7, SIZE_90, ARKUI_ALIGNMENT_BOTTOM_START); + text8 = SetText(nodeAPI, text8, SIZE_90, ARKUI_ALIGNMENT_BOTTOM); + text9 = SetText(nodeAPI, text9, SIZE_90, ARKUI_ALIGNMENT_BOTTOM_END); + text10 = SetText(nodeAPI, text10, SIZE_90, PARAM_NEGATIVE_1); + text11 = SetText(nodeAPI, text11, SIZE_90, PARAM_9); + text12 = SetText(nodeAPI, text12, SIZE_90, ARKUI_ALIGNMENT_TOP_START); + nodeAPI->resetAttribute(text12, NODE_ALIGNMENT); + return column; +} + +napi_value CommonAttrsAlignmentTest::CreateNativeNodePage1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNodePage1(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsAlignmentTest::CreateNativeNodePage2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNodePage2(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsAlignmentTest::CreateNativeNodePage3(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNodePage3(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAlignmentTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_alignment_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_alignment_test.h new file mode 100644 index 0000000000000000000000000000000000000000..3bc803f6df044cb873e11732158c0589321e0821 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_alignment_test.h @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ALIGNMENT_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ALIGNMENT_TEST_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_90 90 + +class CommonAttrsAlignmentTest { +public: + ~CommonAttrsAlignmentTest(); + static napi_value CreateNativeNodePage1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage2(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage3(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ALIGNMENT_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_aspectratio_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_aspectratio_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bb1355a38f59c21356c1fb6e9b1b9cde935e529 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_aspectratio_test.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 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 "commonattrs_aspectratio_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateColumnWithAspectRatio(float aspectRatio) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsAspectRatioTest", "CreateColumnWithAspectRatio"); + + auto column = std::make_shared(); + column->SetWidth(SIZE_100); + column->SetHeight(SIZE_100); + column->SetBackgroundColor(COLOR_RED); + column->SetMargin(DEFAULT_MARGIN); + ArkUI_NumberValue aspectratio_value[] = { { .f32 = aspectRatio } }; + ArkUI_AttributeItem aspectratio_item = { aspectratio_value, + sizeof(aspectratio_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_ASPECT_RATIO, &aspectratio_item); + + return column; +} + +napi_value CommonAttrsAspectRatioTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsAspectRatioTest", "CreateNativeNode"); + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAspectRatioTest", "GetContext env or info is null"); + return nullptr; + } + + auto column1 = CreateColumnWithAspectRatio(-5); + auto column2 = CreateColumnWithAspectRatio(0); + auto column3 = CreateColumnWithAspectRatio(0.5); + auto column4 = CreateColumnWithAspectRatio(2); + auto column5 = CreateColumnWithAspectRatio(20); + auto column6 = CreateColumnWithAspectRatio(2); + column6->resetAttribute(NODE_ASPECT_RATIO); + + auto column = new ColumnComponent(); + column->AddChild(column1); + column->AddChild(column2); + column->AddChild(column3); + column->AddChild(column4); + column->AddChild(column5); + column->AddChild(column6); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAspectRatioTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_aspectratio_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_aspectratio_test.h new file mode 100644 index 0000000000000000000000000000000000000000..579c3dfaf30e51436a236bcf3be44368fd5a243f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_aspectratio_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ASPECT_RATIO_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ASPECT_RATIO_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsAspectRatioTest { +public: + ~CommonAttrsAspectRatioTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ASPECT_RATIO_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundblurstyle_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundblurstyle_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..80586d5e5a7813cfe9b753bf015253078838597f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundblurstyle_test.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024 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 "commonattrs_backgroundblurstyle_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateChildWithBlurStyle(int32_t blurStyle, int32_t colorMode, int32_t adaptiveColor, + float blurDegree, const std::vector& floatValues) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundBlurStyleTest", "CreateChildWithBlurStyle"); + + auto column = std::make_shared(); + column->SetWidth(80); + column->SetHeight(80); + column->SetBackgroundImage("resource://media/icon.png"); + column->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + if (colorMode != PARAM_NEGATIVE_100 && adaptiveColor != PARAM_NEGATIVE_100) { + ArkUI_NumberValue blurstyle_value[] = { { .i32 = blurStyle }, { .i32 = colorMode }, { .i32 = adaptiveColor } }; + ArkUI_AttributeItem blurstyle_item = { blurstyle_value, sizeof(blurstyle_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_BACKGROUND_BLUR_STYLE, &blurstyle_item); + } else if (blurDegree != PARAM_NEGATIVE_100) { + ArkUI_NumberValue blurstyle_value[] = { { .i32 = blurStyle }, {}, {}, { .f32 = blurDegree } }; + ArkUI_AttributeItem blurstyle_item = { blurstyle_value, sizeof(blurstyle_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_BACKGROUND_BLUR_STYLE, &blurstyle_item); + } else if (floatValues[0] != PARAM_NEGATIVE_100 && floatValues[1] != PARAM_NEGATIVE_100) { + ArkUI_NumberValue blurstyle_value[] = { { .i32 = blurStyle }, { .i32 = ARKUI_COLOR_MODE_LIGHT }, + { .i32 = ARKUI_ADAPTIVE_COLOR_DEFAULT }, { .f32 = 1 }, { .f32 = floatValues[0] }, + { .f32 = floatValues[1] } }; + ArkUI_AttributeItem blurstyle_item = { blurstyle_value, sizeof(blurstyle_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_BACKGROUND_BLUR_STYLE, &blurstyle_item); + } else { + ArkUI_NumberValue blurstyle_value[] = { { .i32 = blurStyle } }; + ArkUI_AttributeItem blurstyle_item = { blurstyle_value, sizeof(blurstyle_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_BACKGROUND_BLUR_STYLE, &blurstyle_item); + } + + return column; +} + +static void AddBlurStyleChild(GridComponent* grid) +{ + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_REGULAR, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THICK, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_BACKGROUND_THIN, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_BACKGROUND_REGULAR, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_BACKGROUND_THICK, -100, -100, -100, { -100, -100 })); + grid->AddChild( + CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_BACKGROUND_ULTRA_THICK, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_NONE, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_COMPONENT_ULTRA_THIN, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_COMPONENT_THIN, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_COMPONENT_REGULAR, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_COMPONENT_THICK, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_COMPONENT_ULTRA_THICK, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(-1, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(13, -100, -100, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_SYSTEM, ARKUI_ADAPTIVE_COLOR_DEFAULT, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_LIGHT, ARKUI_ADAPTIVE_COLOR_DEFAULT, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_DARK, ARKUI_ADAPTIVE_COLOR_DEFAULT, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_SYSTEM, ARKUI_ADAPTIVE_COLOR_AVERAGE, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_LIGHT, ARKUI_ADAPTIVE_COLOR_AVERAGE, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_DARK, ARKUI_ADAPTIVE_COLOR_AVERAGE, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_SYSTEM, -1, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_SYSTEM, 2, -100, { -100, -100 })); + grid->AddChild( + CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -1, ARKUI_ADAPTIVE_COLOR_DEFAULT, -100, { -100, -100 })); + grid->AddChild( + CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, 3, ARKUI_ADAPTIVE_COLOR_DEFAULT, -100, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -1, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, 0, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, 0.5, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, 1, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, 2, { -100, -100 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { 0, 127 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { 0, 64 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { 64, 0 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { 64, 127 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { -1, 127 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { 127, -1 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { -1, -1 })); + grid->AddChild(CreateChildWithBlurStyle(ARKUI_BLUR_STYLE_THIN, -100, -100, -100, { 0, 150 })); +} + +napi_value CommonAttrsBackgroundBlurStyleTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundBlurStyleTest", "CreateNativeNode"); + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundBlurStyleTest", + "GetContext env or info is null"); + return nullptr; + } + + auto grid = new GridComponent(); + grid->SetGridColumnsGap(5); + grid->SetGridRowsGap(5); + AddBlurStyleChild(grid); + auto column39 = CreateChildWithBlurStyle( + ARKUI_BLUR_STYLE_THIN, ARKUI_COLOR_MODE_SYSTEM, ARKUI_ADAPTIVE_COLOR_DEFAULT, 0.5, { 0, 127 }); + column39->resetAttribute(NODE_BACKGROUND_BLUR_STYLE); + grid->AddChild(column39); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), grid->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundBlurStyleTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundblurstyle_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundblurstyle_test.h new file mode 100644 index 0000000000000000000000000000000000000000..1996dde8737b27fb2810c161193ceefdc5a3c130 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundblurstyle_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDBLURSTYLE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDBLURSTYLE_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" +#include "grid_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsBackgroundBlurStyleTest { +public: + ~CommonAttrsBackgroundBlurStyleTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDBLURSTYLE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimage_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimage_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9f8fbb4fbe45ab47d5c6a80be33e78f14da76a8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimage_test.cpp @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2024 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 "commonattrs_backgroundimage_test.h" + +#include + +#include "../manager/plugin_manager.h" +#include "multimedia/image_framework/image/pixelmap_native.h" + +namespace ArkUICApiDemo { + +static auto CreateChildWithResourceStr( + ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height, const char* resourceStr, int imageRepeat) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "CreateChildWithResourceStr"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = PARAM_2 } }; + ArkUI_AttributeItem borderWidth_value_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BORDER_WIDTH, &borderWidth_value_item); + + if (imageRepeat != PARAM_NEGATIVE_100) { + ArkUI_NumberValue repeat_value[] = { { .i32 = imageRepeat } }; + ArkUI_AttributeItem repeat_value_item = { repeat_value, sizeof(repeat_value) / sizeof(ArkUI_NumberValue) }; + repeat_value_item.string = resourceStr; + nodeAPI->setAttribute(column, NODE_BACKGROUND_IMAGE, &repeat_value_item); + } else { + ArkUI_AttributeItem imageStr_item = {}; + imageStr_item.string = resourceStr; + nodeAPI->setAttribute(column, NODE_BACKGROUND_IMAGE, &imageStr_item); + } + return column; +} + +static auto CreateChildWithPixelMap( + ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height, OH_PixelmapNative* pixelMap, int imageRepeat) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "CreateChildWithPixelMap"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = PARAM_2 } }; + ArkUI_AttributeItem borderWidth_value_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BORDER_WIDTH, &borderWidth_value_item); + + if (imageRepeat != PARAM_NEGATIVE_100) { + ArkUI_NumberValue repeat_value[] = { { .i32 = imageRepeat } }; + ArkUI_AttributeItem repeat_value_item = { repeat_value, sizeof(repeat_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_DrawableDescriptor* drawableDescriptor = OH_ArkUI_DrawableDescriptor_CreateFromPixelMap(pixelMap); + repeat_value_item.object = drawableDescriptor; + nodeAPI->setAttribute(column, NODE_BACKGROUND_IMAGE, &repeat_value_item); + } else { + ArkUI_AttributeItem imagePixelMap_item = {}; + ArkUI_DrawableDescriptor* drawableDescriptor = OH_ArkUI_DrawableDescriptor_CreateFromPixelMap(pixelMap); + imagePixelMap_item.object = drawableDescriptor; + nodeAPI->setAttribute(column, NODE_BACKGROUND_IMAGE, &imagePixelMap_item); + } + return column; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "CreateParentNode"); + + auto grid = nodeAPI->createNode(ARKUI_NODE_GRID); + ArkUI_NumberValue gap_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem gap_item = { gap_value, sizeof(gap_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(grid, NODE_GRID_COLUMN_GAP, &gap_item); + nodeAPI->setAttribute(grid, NODE_GRID_ROW_GAP, &gap_item); + + return grid; +} + +static OH_PixelmapNative* CreatePixelMap() +{ + OH_Pixelmap_InitializationOptions* options = nullptr; + Image_ErrorCode ret = OH_PixelmapInitializationOptions_Create(&options); + if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", + "OH_PixelmapInitializationOptions_Create failed"); + return nullptr; + } + OH_PixelmapInitializationOptions_SetWidth(options, 64); + OH_PixelmapInitializationOptions_SetHeight(options, 64); + OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_BGRA_8888); + size_t dataLength = 64 * 64 * 4; + uint8_t* data = (uint8_t*)malloc(dataLength); + if (data == nullptr) { + OH_PixelmapInitializationOptions_Release(options); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "GetContext data is null"); + return nullptr; + } + for (int i = 0; i < dataLength;) { + data[i++] = 0; // Blue + data[i++] = 0; // Green + data[i++] = 255; // Red + data[i++] = 255; // Alpha + } + OH_PixelmapNative* pixelmap = nullptr; + ret = OH_PixelmapNative_CreatePixelmap(data, dataLength, options, &pixelmap); + if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", + "OH_PixelmapNative_CreatePixelmap failed"); + return nullptr; + } + free(data); + OH_PixelmapInitializationOptions_Release(options); + return pixelmap; +} + +static void AddResourceStrChild(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle grid) +{ + const char* imageStr = "resource://media/icon.png"; + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, PARAM_NEGATIVE_100)); + auto column2 = CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, PARAM_NEGATIVE_100); + ArkUI_NumberValue red_color_value[] = { { .u32 = COLOR_RED } }; + ArkUI_AttributeItem red_color_item = { red_color_value, sizeof(red_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column2, NODE_BACKGROUND_COLOR, &red_color_item); + nodeAPI->addChild(grid, column2); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, "", PARAM_NEGATIVE_100)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, "abcdef", PARAM_NEGATIVE_100)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, -1)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, ARKUI_IMAGE_REPEAT_NONE)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, ARKUI_IMAGE_REPEAT_XY)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, 4)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 60, imageStr, -1)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 60, imageStr, ARKUI_IMAGE_REPEAT_NONE)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 60, imageStr, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 60, imageStr, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 60, imageStr, ARKUI_IMAGE_REPEAT_XY)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 60, imageStr, 4)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 60, imageStr, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 60, imageStr, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 100, 60, imageStr, ARKUI_IMAGE_REPEAT_XY)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 100, imageStr, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 100, imageStr, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithResourceStr(nodeAPI, 60, 100, imageStr, ARKUI_IMAGE_REPEAT_XY)); + auto column23 = CreateChildWithResourceStr(nodeAPI, 100, 100, imageStr, ARKUI_IMAGE_REPEAT_X); + nodeAPI->resetAttribute(column23, NODE_BACKGROUND_IMAGE); + nodeAPI->addChild(grid, column23); +} + +static void AddPixelMapChild(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle grid) +{ + auto pixelmap = CreatePixelMap(); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, nullptr, PARAM_NEGATIVE_100)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, PARAM_NEGATIVE_100)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, -1)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, ARKUI_IMAGE_REPEAT_NONE)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, ARKUI_IMAGE_REPEAT_XY)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, 4)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 40, pixelmap, -1)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 40, pixelmap, ARKUI_IMAGE_REPEAT_NONE)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 40, pixelmap, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 40, pixelmap, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 40, pixelmap, ARKUI_IMAGE_REPEAT_XY)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 40, pixelmap, 4)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 40, pixelmap, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 40, pixelmap, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 100, 40, pixelmap, ARKUI_IMAGE_REPEAT_XY)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 100, pixelmap, ARKUI_IMAGE_REPEAT_X)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 100, pixelmap, ARKUI_IMAGE_REPEAT_Y)); + nodeAPI->addChild(grid, CreateChildWithPixelMap(nodeAPI, 40, 100, pixelmap, ARKUI_IMAGE_REPEAT_XY)); + auto column21 = CreateChildWithPixelMap(nodeAPI, 100, 100, pixelmap, ARKUI_IMAGE_REPEAT_X); + nodeAPI->resetAttribute(column21, NODE_BACKGROUND_IMAGE); + nodeAPI->addChild(grid, column21); + OH_PixelmapNative_Release(pixelmap); +} + +napi_value CommonAttrsBackgroundImageTest::CreateNativeNodeResourceStr(napi_env env, napi_callback_info info) +{ + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "CreateNativeNodeResourceStr"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto grid = CreateParentNode(nodeAPI); + AddResourceStrChild(nodeAPI, grid); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), grid) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsBackgroundImageTest::CreateNativeNodePixelMap(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "CreateNativeNodePixelMap"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto grid = CreateParentNode(nodeAPI); + AddPixelMapChild(nodeAPI, grid); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), grid) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimage_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimage_test.h new file mode 100644 index 0000000000000000000000000000000000000000..00759c350e6a64ea86dba8d71c92c1fcfad03f12 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimage_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGE_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsBackgroundImageTest { +public: + ~CommonAttrsBackgroundImageTest(); + static napi_value CreateNativeNodeResourceStr(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePixelMap(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimageposition_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimageposition_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..88382fa4f5798218e1e1ccc759a4bbc6ca5f0dcd --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimageposition_test.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 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 "commonattrs_backgroundimageposition_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateChildWithPosition(float axisX, float axisY) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImagePositionTest", "CreateChildWithSizeOptions"); + + auto column = std::make_shared(); + column->SetWidth(200); + column->SetHeight(150); + column->SetBorderWidth(2); + column->SetBackgroundImage("resource://media/icon.png"); + ArkUI_NumberValue position_value[] = { { .f32 = axisX }, { .f32 = axisY } }; + ArkUI_AttributeItem position_item = { position_value, sizeof(position_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_BACKGROUND_IMAGE_POSITION, &position_item); + + return column; +} + +napi_value CommonAttrsBackgroundImagePositionTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImagePositionTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImagePositionTest", + "GetContext env or info is null"); + return nullptr; + } + + auto grid = new GridComponent(); + grid->SetGridColumnsGap(10); + grid->SetGridRowsGap(10); + grid->AddChild(CreateChildWithPosition(30, 30)); + grid->AddChild(CreateChildWithPosition(-30, 30)); + grid->AddChild(CreateChildWithPosition(30, -30)); + grid->AddChild(CreateChildWithPosition(-30, -30)); + grid->AddChild(CreateChildWithPosition(100, 100)); + grid->AddChild(CreateChildWithPosition(500, 500)); + grid->AddChild(CreateChildWithPosition(0, 0)); + auto column8 = CreateChildWithPosition(30, 30); + column8->resetAttribute(NODE_BACKGROUND_IMAGE_POSITION); + grid->AddChild(column8); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), grid->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImagePositionTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimageposition_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimageposition_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b167dcc3cc9d04a2628d79f5d34c7336a61a56ae --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimageposition_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGEPOSITION_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGEPOSITION_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" +#include "grid_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsBackgroundImagePositionTest { +public: + ~CommonAttrsBackgroundImagePositionTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGEPOSITION_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimagesize_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimagesize_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd9f61ce2c7f359aafde694331e7f09cc871a494 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimagesize_test.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2024 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 "commonattrs_backgroundimagesize_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateChildWithSizeOptions(float width, float height) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageSizeTest", "CreateChildWithSizeOptions"); + + auto column = std::make_shared(); + column->SetWidth(140); + column->SetHeight(120); + column->SetBorderWidth(2); + column->SetBackgroundImage("resource://media/icon.png"); + ArkUI_NumberValue sizeoptions_value[] = { { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem sizeoptions_item = { sizeoptions_value, + sizeof(sizeoptions_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_BACKGROUND_IMAGE_SIZE, &sizeoptions_item); + + return column; +} + +std::shared_ptr CreateChildWithImageSize(int32_t imageSize) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageSizeTest", "CreateChildWithImageSize"); + + auto column = std::make_shared(); + column->SetWidth(140); + column->SetHeight(120); + column->SetBorderWidth(2); + column->SetBackgroundImage("resource://media/icon.png"); + column->SetBackgroundImageSizeWithStyle(imageSize); + + return column; +} + +napi_value CommonAttrsBackgroundImageSizeTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageSizeTest", "CreateNativeNode"); + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageSizeTest", + "GetContext env or info is null"); + return nullptr; + } + + auto grid = new GridComponent(); + grid->SetGridColumnsGap(5); + grid->SetGridRowsGap(5); + grid->AddChild(CreateChildWithSizeOptions(100, 100)); + grid->AddChild(CreateChildWithSizeOptions(-100, -100)); + grid->AddChild(CreateChildWithSizeOptions(300, 300)); + auto column4 = CreateChildWithSizeOptions(100, 100); + column4->resetAttribute(NODE_BACKGROUND_IMAGE_SIZE); + grid->AddChild(column4); + grid->AddChild(CreateChildWithImageSize(ARKUI_IMAGE_SIZE_AUTO)); + grid->AddChild(CreateChildWithImageSize(ARKUI_IMAGE_SIZE_COVER)); + grid->AddChild(CreateChildWithImageSize(ARKUI_IMAGE_SIZE_CONTAIN)); + grid->AddChild(CreateChildWithImageSize(3)); + grid->AddChild(CreateChildWithImageSize(-1)); + grid->AddChild(CreateChildWithImageSize(4)); + auto column11 = CreateChildWithImageSize(ARKUI_IMAGE_SIZE_COVER); + column11->resetAttribute(NODE_BACKGROUND_IMAGE_SIZE_WITH_STYLE); + grid->AddChild(column11); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), grid->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBackgroundImageSizeTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimagesize_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimagesize_test.h new file mode 100644 index 0000000000000000000000000000000000000000..2171ea596547e0da686ffe70829d3b126f9b61d5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_backgroundimagesize_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGESIZE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGESIZE_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" +#include "grid_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsBackgroundImageSizeTest { +public: + ~CommonAttrsBackgroundImageSizeTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_BACKGROUNDIMAGESIZE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_blur_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_blur_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19e2bade9ee52c92ed79783656dbec449654e2c9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_blur_test.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 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 "commonattrs_blur_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateImageWithBlur(float blur) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", "CreateImageNode"); + + auto image = std::make_shared(ARKUI_NODE_IMAGE); + image->SetWidth(SIZE_100); + image->SetHeight(SIZE_100); + image->SetMargin(DEFAULT_MARGIN); + image->SetBackgroundImage("resource://media/icon.png"); + image->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + ArkUI_NumberValue blur_value[] = { { .f32 = blur } }; + ArkUI_AttributeItem blur_item = { blur_value, sizeof(blur_value) / sizeof(ArkUI_NumberValue) }; + image->setAttribute(NODE_BLUR, &blur_item); + + return image; +} + +napi_value CommonAttrsBlurTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", "GetContext env or info is null"); + return nullptr; + } + + auto image1 = CreateImageWithBlur(0); + auto image2 = CreateImageWithBlur(30); + auto image3 = CreateImageWithBlur(50); + auto image4 = CreateImageWithBlur(100); + auto image5 = CreateImageWithBlur(-100); + auto image6 = CreateImageWithBlur(50); + image6->resetAttribute(NODE_BLUR); + + auto column = new ColumnComponent(); + column->AddChild(image1); + column->AddChild(image2); + column->AddChild(image3); + column->AddChild(image4); + column->AddChild(image5); + column->AddChild(image6); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_blur_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_blur_test.h new file mode 100644 index 0000000000000000000000000000000000000000..1805875543ebff2cf855aedcf9c1a4add121935d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_blur_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_BLUR_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_BLUR_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsBlurTest { +public: + ~CommonAttrsBlurTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_BLUR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_brightness_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_brightness_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18852b349f660791bfba17e581c133b171f894bf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_brightness_test.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 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 "commonattrs_brightness_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateImageWithBrightness(float brightness) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBrightnessTest", "CreateImageNode"); + + auto image = std::make_shared(ARKUI_NODE_IMAGE); + image->SetWidth(70); + image->SetHeight(70); + image->SetMargin(DEFAULT_MARGIN); + image->SetBackgroundColor(COLOR_RED); + ArkUI_NumberValue brightness_value[] = { { .f32 = brightness } }; + ArkUI_AttributeItem brightness_item = { brightness_value, sizeof(brightness_value) / sizeof(ArkUI_NumberValue) }; + image->setAttribute(NODE_BRIGHTNESS, &brightness_item); + + return image; +} + +static void AddBrightnessChild(ColumnComponent* column) +{ + auto image1 = CreateImageWithBrightness(0); + auto image2 = CreateImageWithBrightness(0.5); + auto image3 = CreateImageWithBrightness(1); + auto image4 = CreateImageWithBrightness(1.5); + auto image5 = CreateImageWithBrightness(2); + auto image6 = CreateImageWithBrightness(-1); + auto image7 = CreateImageWithBrightness(3); + auto image8 = CreateImageWithBrightness(2); + image8->resetAttribute(NODE_BRIGHTNESS); + column->AddChild(image1); + column->AddChild(image2); + column->AddChild(image3); + column->AddChild(image4); + column->AddChild(image5); + column->AddChild(image6); + column->AddChild(image7); + column->AddChild(image8); +} + +napi_value CommonAttrsBrightnessTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBrightnessTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBrightnessTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + AddBrightnessChild(column); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBrightnessTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_brightness_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_brightness_test.h new file mode 100644 index 0000000000000000000000000000000000000000..acfb8c2f768308350300528b6ca52e784d3598ca --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_brightness_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_BRIGHTNESS_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_BRIGHTNESS_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsBrightnessTest { +public: + ~CommonAttrsBrightnessTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_BRIGHTNESS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_chainmode_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_chainmode_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb66230b55fa2e5f5a585c58e32beb0fa93d7e93 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_chainmode_test.cpp @@ -0,0 +1,526 @@ +/* + * Copyright (c) 2024 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 "commonattrs_chainmode_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateChainModeRelativeContainerNode(std::vector> rows) +{ + auto column = std::make_shared(); + column->SetMargin(5); + auto relativeContainer = std::make_shared(); + relativeContainer->SetWidth(200); + relativeContainer->SetHeight(200); + relativeContainer->SetBorderWidth(1); + for (auto Row : rows) { + relativeContainer->AddChild(Row); + } + column->AddChild(relativeContainer); + return column; +} + +std::shared_ptr CreateChainModeRelativeContainerNode1( + std::vector> columns) +{ + auto column = std::make_shared(); + column->SetMargin(5); + auto relativeContainer = std::make_shared(); + relativeContainer->SetWidth(200); + relativeContainer->SetHeight(200); + relativeContainer->SetBorderWidth(1); + for (auto Column : columns) { + relativeContainer->AddChild(Column); + } + column->AddChild(relativeContainer); + return column; +} + +std::shared_ptr CreateChainModeRowNode( + const std::string& id, uint32_t color, std::shared_ptr ruleOption = nullptr) +{ + auto row = std::make_shared(); + row->SetWidth(50); + row->SetHeight(50); + row->SetId(id); + row->SetAlignRules(ruleOption->GetOption()); + row->SetBackgroundColor(color); + row->SetJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + return row; +} + +std::shared_ptr CreateChainModeColumnNode( + const std::string& id, uint32_t color, std::shared_ptr ruleOption = nullptr) +{ + auto column = std::make_shared(); + column->SetWidth(50); + column->SetHeight(50); + column->SetId(id); + column->SetAlignRules(ruleOption->GetOption()); + column->SetBackgroundColor(color); + column->SetJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + return column; +} + +napi_value CommonAttrsChainModeTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create ruleOption + auto rule1 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule1 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + HorizontalAlignRule horizontalAlignRule2 { .anchor = "row2", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule1 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption1 { + .left = horizontalAlignRule1, .right = horizontalAlignRule2, .top = verticalAlignRule1 + }; + rule1->SetAlignOption(ruleOption1); + + auto rule2 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule3 { .anchor = "row1", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + HorizontalAlignRule horizontalAlignRule4 { .anchor = "row3", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule2 { .anchor = "row1", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption2 { + .left = horizontalAlignRule3, .right = horizontalAlignRule4, .top = verticalAlignRule2 + }; + rule2->SetAlignOption(ruleOption2); + + auto rule3 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule5 { .anchor = "row2", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + HorizontalAlignRule horizontalAlignRule6 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + VerticalAlignRule verticalAlignRule3 { .anchor = "row1", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption3 { + .left = horizontalAlignRule5, .right = horizontalAlignRule6, .top = verticalAlignRule3 + }; + rule3->SetAlignOption(ruleOption3); + + auto rule4 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule7 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + HorizontalAlignRule horizontalAlignRule8 { .anchor = "row5", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule4 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_CENTER }; + AlignmentRuleOption ruleOption4 { + .left = horizontalAlignRule7, .right = horizontalAlignRule8, .center = verticalAlignRule4 + }; + rule4->SetAlignOption(ruleOption4); + + auto rule5 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule9 { .anchor = "row4", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + HorizontalAlignRule horizontalAlignRule10 { .anchor = "row6", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule5 { .anchor = "row4", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption5 { + .left = horizontalAlignRule9, .right = horizontalAlignRule10, .top = verticalAlignRule5 + }; + rule5->SetAlignOption(ruleOption5); + + auto rule6 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule11 { .anchor = "row5", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + HorizontalAlignRule horizontalAlignRule12 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + VerticalAlignRule verticalAlignRule6 { .anchor = "row4", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption6 { + .left = horizontalAlignRule11, .right = horizontalAlignRule12, .top = verticalAlignRule6 + }; + rule6->SetAlignOption(ruleOption6); + + auto rule7 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule13 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + HorizontalAlignRule horizontalAlignRule14 { .anchor = "row8", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule7 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption7 { + .left = horizontalAlignRule13, .right = horizontalAlignRule14, .bottom = verticalAlignRule7 + }; + rule7->SetAlignOption(ruleOption7); + + auto rule8 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule15 { .anchor = "row7", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + HorizontalAlignRule horizontalAlignRule16 { .anchor = "row9", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule8 { .anchor = "row7", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption8 { + .left = horizontalAlignRule15, .right = horizontalAlignRule16, .top = verticalAlignRule8 + }; + rule8->SetAlignOption(ruleOption8); + + auto rule9 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule17 { .anchor = "row8", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + HorizontalAlignRule horizontalAlignRule18 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + VerticalAlignRule verticalAlignRule9 { .anchor = "row7", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption9 { + .left = horizontalAlignRule17, .right = horizontalAlignRule18, .top = verticalAlignRule9 + }; + rule9->SetAlignOption(ruleOption9); + + // create row + auto row1 = CreateChainModeRowNode("row1", COLOR_RED, rule1); + auto row2 = CreateChainModeRowNode("row2", COLOR_BLUE, rule2); + auto row3 = CreateChainModeRowNode("row3", COLOR_YELLOW, rule3); + auto row4 = CreateChainModeRowNode("row4", COLOR_LIGHT_BLUE, rule4); + auto row5 = CreateChainModeRowNode("row5", COLOR_PURPLE, rule5); + auto row6 = CreateChainModeRowNode("row6", COLOR_BLACK, rule6); + auto row7 = CreateChainModeRowNode("row7", COLOR_GRAY, rule7); + auto row8 = CreateChainModeRowNode("row8", COLOR_PINK, rule8); + auto row9 = CreateChainModeRowNode("row9", COLOR_GREEN, rule9); + + // set chainMode + ArkUI_NumberValue chainMode1_value[] = { { .i32 = ARKUI_AXIS_HORIZONTAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_SPREAD } }; + ArkUI_AttributeItem chainMode1_item = { chainMode1_value, sizeof(chainMode1_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(row1->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode1_item); + ArkUI_NumberValue chainMode2_value[] = { { .i32 = ARKUI_AXIS_HORIZONTAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_SPREAD_INSIDE } }; + ArkUI_AttributeItem chainMode2_item = { chainMode2_value, sizeof(chainMode2_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(row4->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode2_item); + ArkUI_NumberValue chainMode3_value[] = { { .i32 = ARKUI_AXIS_HORIZONTAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_PACKED } }; + ArkUI_AttributeItem chainMode3_item = { chainMode3_value, sizeof(chainMode3_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(row7->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode3_item); + + // add child + auto column = CreateChainModeRelativeContainerNode({ row1, row2, row3, row4, row5, row6, row7, row8, row9 }); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +napi_value CommonAttrsChainModeTest::CreateNativeNode1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", "CreateNativeNode1"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create ruleOption + auto rule1 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule1 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule1 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + VerticalAlignRule verticalAlignRule2 { .anchor = "column2", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption1 { + .left = horizontalAlignRule1, .top = verticalAlignRule1, .bottom = verticalAlignRule2 + }; + rule1->SetAlignOption(ruleOption1); + + auto rule2 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule2 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule3 { .anchor = "column1", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule4 { .anchor = "column3", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption2 { + .left = horizontalAlignRule2, .top = verticalAlignRule3, .bottom = verticalAlignRule4 + }; + rule2->SetAlignOption(ruleOption2); + + auto rule3 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule3 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_START }; + VerticalAlignRule verticalAlignRule5 { .anchor = "column2", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule6 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption3 { + .left = horizontalAlignRule3, .top = verticalAlignRule5, .bottom = verticalAlignRule6 + }; + rule3->SetAlignOption(ruleOption3); + + auto rule4 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule4 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule7 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + VerticalAlignRule verticalAlignRule8 { .anchor = "column5", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption4 { + .middle = horizontalAlignRule4, .top = verticalAlignRule7, .bottom = verticalAlignRule8 + }; + rule4->SetAlignOption(ruleOption4); + + auto rule5 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule5 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule9 { .anchor = "column4", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule10 { .anchor = "column6", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption5 { + .middle = horizontalAlignRule5, .top = verticalAlignRule9, .bottom = verticalAlignRule10 + }; + rule5->SetAlignOption(ruleOption5); + + auto rule6 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule6 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule11 { .anchor = "column5", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule12 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption6 { + .middle = horizontalAlignRule6, .top = verticalAlignRule11, .bottom = verticalAlignRule12 + }; + rule6->SetAlignOption(ruleOption6); + + auto rule7 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule7 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + VerticalAlignRule verticalAlignRule13 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + VerticalAlignRule verticalAlignRule14 { .anchor = "column8", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption7 { + .right = horizontalAlignRule7, .top = verticalAlignRule13, .bottom = verticalAlignRule14 + }; + rule7->SetAlignOption(ruleOption7); + + auto rule8 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule8 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + VerticalAlignRule verticalAlignRule15 { .anchor = "column7", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule16 { .anchor = "column9", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption8 { + .right = horizontalAlignRule8, .top = verticalAlignRule15, .bottom = verticalAlignRule16 + }; + rule8->SetAlignOption(ruleOption8); + + auto rule9 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule9 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_END }; + VerticalAlignRule verticalAlignRule17 { .anchor = "column8", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule18 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption9 { + .right = horizontalAlignRule9, .top = verticalAlignRule17, .bottom = verticalAlignRule18 + }; + rule9->SetAlignOption(ruleOption9); + + // create column + auto column1 = CreateChainModeColumnNode("column1", COLOR_RED, rule1); + auto column2 = CreateChainModeColumnNode("column2", COLOR_BLUE, rule2); + auto column3 = CreateChainModeColumnNode("column3", COLOR_YELLOW, rule3); + auto column4 = CreateChainModeColumnNode("column4", COLOR_LIGHT_BLUE, rule4); + auto column5 = CreateChainModeColumnNode("column5", COLOR_PURPLE, rule5); + auto column6 = CreateChainModeColumnNode("column6", COLOR_BLACK, rule6); + auto column7 = CreateChainModeColumnNode("column7", COLOR_GRAY, rule7); + auto column8 = CreateChainModeColumnNode("column8", COLOR_PINK, rule8); + auto column9 = CreateChainModeColumnNode("column9", COLOR_GREEN, rule9); + + // set chainMode + ArkUI_NumberValue chainMode1_value[] = { { .i32 = ARKUI_AXIS_VERTICAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_SPREAD } }; + ArkUI_AttributeItem chainMode1_item = { chainMode1_value, sizeof(chainMode1_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column1->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode1_item); + ArkUI_NumberValue chainMode2_value[] = { { .i32 = ARKUI_AXIS_VERTICAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_SPREAD_INSIDE } }; + ArkUI_AttributeItem chainMode2_item = { chainMode2_value, sizeof(chainMode2_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column4->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode2_item); + ArkUI_NumberValue chainMode3_value[] = { { .i32 = ARKUI_AXIS_VERTICAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_PACKED } }; + ArkUI_AttributeItem chainMode3_item = { chainMode3_value, sizeof(chainMode3_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column7->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode3_item); + + // add child + auto column = CreateChainModeRelativeContainerNode1( + { column1, column2, column3, column4, column5, column6, column7, column8, column9 }); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +napi_value CommonAttrsChainModeTest::CreateNativeNode2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", "CreateNativeNode2"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create ruleOption + auto rule1 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule1 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule1 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + VerticalAlignRule verticalAlignRule2 { .anchor = "row2", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption1 { + .top = verticalAlignRule1, .bottom = verticalAlignRule2, .middle = horizontalAlignRule1 + }; + rule1->SetAlignOption(ruleOption1); + + auto rule2 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule2 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule3 { .anchor = "row1", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule4 { .anchor = "row3", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption2 { + .top = verticalAlignRule3, .bottom = verticalAlignRule4, .middle = horizontalAlignRule2 + }; + rule2->SetAlignOption(ruleOption2); + + auto rule3 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule3 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule5 { .anchor = "row2", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule6 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption3 { + .top = verticalAlignRule5, .bottom = verticalAlignRule6, .middle = horizontalAlignRule3 + }; + rule3->SetAlignOption(ruleOption3); + + auto rule4 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule4 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule7 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + VerticalAlignRule verticalAlignRule8 { .anchor = "row5", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption4 { + .top = verticalAlignRule7, .bottom = verticalAlignRule8, .middle = horizontalAlignRule4 + }; + rule4->SetAlignOption(ruleOption4); + + auto rule5 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule5 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule9 { .anchor = "row4", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule10 { .anchor = "row6", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption5 { + .top = verticalAlignRule9, .bottom = verticalAlignRule10, .middle = horizontalAlignRule5 + }; + rule5->SetAlignOption(ruleOption5); + + auto rule6 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule6 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule11 { .anchor = "row5", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule12 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption6 { + .top = verticalAlignRule11, .bottom = verticalAlignRule12, .middle = horizontalAlignRule6 + }; + rule6->SetAlignOption(ruleOption6); + + auto rule7 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule7 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule13 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + VerticalAlignRule verticalAlignRule14 { .anchor = "row8", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption7 { + .top = verticalAlignRule13, .bottom = verticalAlignRule14, .middle = horizontalAlignRule7 + }; + rule7->SetAlignOption(ruleOption7); + + auto rule8 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule8 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule15 { .anchor = "row7", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule16 { .anchor = "row9", .align = ARKUI_VERTICAL_ALIGNMENT_TOP }; + AlignmentRuleOption ruleOption8 { + .top = verticalAlignRule15, .bottom = verticalAlignRule16, .middle = horizontalAlignRule8 + }; + rule8->SetAlignOption(ruleOption8); + + auto rule9 = std::make_shared(); + HorizontalAlignRule horizontalAlignRule9 { .anchor = "__container__", .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER }; + VerticalAlignRule verticalAlignRule17 { .anchor = "row8", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + VerticalAlignRule verticalAlignRule18 { .anchor = "__container__", .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM }; + AlignmentRuleOption ruleOption9 { + .top = verticalAlignRule17, .bottom = verticalAlignRule18, .middle = horizontalAlignRule9 + }; + rule9->SetAlignOption(ruleOption9); + + // create row + auto row1 = CreateChainModeRowNode("row1", COLOR_RED, rule1); + auto row2 = CreateChainModeRowNode("row2", COLOR_BLUE, rule2); + auto row3 = CreateChainModeRowNode("row3", COLOR_YELLOW, rule3); + auto row4 = CreateChainModeRowNode("row4", COLOR_LIGHT_BLUE, rule4); + auto row5 = CreateChainModeRowNode("row5", COLOR_PURPLE, rule5); + auto row6 = CreateChainModeRowNode("row6", COLOR_BLACK, rule6); + auto row7 = CreateChainModeRowNode("row7", COLOR_GRAY, rule7); + auto row8 = CreateChainModeRowNode("row8", COLOR_PINK, rule8); + auto row9 = CreateChainModeRowNode("row9", COLOR_GREEN, rule9); + + // set chainMode + ArkUI_NumberValue chainMode1_value[] = { { .i32 = ARKUI_AXIS_VERTICAL }, + { .i32 = ARKUI_RELATIVE_LAYOUT_CHAIN_STYLE_SPREAD } }; + ArkUI_AttributeItem chainMode1_item = { chainMode1_value, sizeof(chainMode1_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(row1->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode1_item); + nodeAPI->resetAttribute(row1->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE); + ArkUI_NumberValue chainMode2_value[] = { { .i32 = -1 }, { .i32 = -1 } }; + ArkUI_AttributeItem chainMode2_item = { chainMode2_value, sizeof(chainMode2_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(row4->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode2_item); + ArkUI_NumberValue chainMode3_value[] = { { .i32 = 2 }, { .i32 = 3 } }; + ArkUI_AttributeItem chainMode3_item = { chainMode3_value, sizeof(chainMode3_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(row7->GetComponent(), NODE_RELATIVE_LAYOUT_CHAIN_MODE, &chainMode3_item); + + // add child + auto columnP1 = CreateChainModeRelativeContainerNode({ row1, row2, row3 }); + auto columnP2 = CreateChainModeRelativeContainerNode({ row4, row5, row6 }); + auto columnP3 = CreateChainModeRelativeContainerNode({ row7, row8, row9 }); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(column, columnP1->GetComponent()); + nodeAPI->addChild(column, columnP2->GetComponent()); + nodeAPI->addChild(column, columnP3->GetComponent()); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsChainModeTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_chainmode_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_chainmode_test.h new file mode 100644 index 0000000000000000000000000000000000000000..a426abad0c6ae05737606cfa8556bd479e24d9eb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_chainmode_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_CHAINMODE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_CHAINMODE_TEST_H + +#include + +#include "../common/common.h" +#include "../component/relativecontainer_component.h" +#include "arkui/native_node.h" +#include "component/column_component.h" +#include "component/row_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsChainModeTest { +public: + ~CommonAttrsChainModeTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + static napi_value CreateNativeNode1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNode2(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_CHAINMODE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_clipshape_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_clipshape_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1d06d5debc05e8bee16edcbfd5d7c8bb1bb8ca0c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_clipshape_test.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2024 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 "commonattrs_clipshape_test.h" + +#include +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateNodeRect( + ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height, float cornerWidth, float cornerHeight) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "createNodeRect"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue clipshape_value[] = { { .i32 = ARKUI_CLIP_TYPE_RECTANGLE }, { .f32 = width }, { .f32 = height }, + { .f32 = cornerWidth }, { .f32 = cornerHeight } }; + ArkUI_AttributeItem clipshape_item = { clipshape_value, sizeof(clipshape_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipshape_item); + + return column; +} + +static auto CreateNodeRectDiffCornerRadius(ArkUI_NativeNodeAPI_1* nodeAPI, const std::vector& floatValues) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "createNodeRectDiffCornerRadius"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + std::vector clipshape_value; + clipshape_value.push_back({ .i32 = ARKUI_CLIP_TYPE_RECTANGLE }); + clipshape_value.push_back({ .f32 = 100 }); + clipshape_value.push_back({ .f32 = 100 }); + for (auto floatValue : floatValues) { + clipshape_value.push_back({ .f32 = floatValue }); + } + ArkUI_AttributeItem clipshape_item = { clipshape_value.data(), sizeof(clipshape_value) }; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipshape_item); + + return column; +} + +static auto CreateNodeCircle(ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "createNodeCircle"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue clipshape_value[] = { { .i32 = ARKUI_CLIP_TYPE_CIRCLE }, { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem clipshape_item = { clipshape_value, sizeof(clipshape_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipshape_item); + + return column; +} + +static auto CreateNodeEllipse(ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "createNodeEllipse"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue clipshape_value[] = { { .i32 = ARKUI_CLIP_TYPE_ELLIPSE }, { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem clipshape_item = { clipshape_value, sizeof(clipshape_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipshape_item); + + return column; +} + +static auto CreateNodePath(ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height, const char* command) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "createNodePath"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue clipshape_value[] = { { .i32 = ARKUI_CLIP_TYPE_PATH }, { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem clipshape_item = { clipshape_value, sizeof(clipshape_value) / sizeof(ArkUI_NumberValue) }; + clipshape_item.string = command; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipshape_item); + + return column; +} + +static auto CreateNodeOutliers(ArkUI_NativeNodeAPI_1* nodeAPI, int outliers, const std::vector& floatValues) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "createNodeOutliers"); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = 100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + std::vector clipshape_value; + clipshape_value.push_back({ .i32 = outliers }); + for (auto floatValue : floatValues) { + clipshape_value.push_back({ .f32 = floatValue }); + } + ArkUI_AttributeItem clipshape_item = { clipshape_value.data(), sizeof(clipshape_value) }; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipshape_item); + + return column; +} + +static void AddClipShapeChild(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle grid) +{ + const char* command1 = "M60 0 L120 100 L0 100 Z"; + const char* command2 = ""; + nodeAPI->addChild(grid, CreateNodeRect(nodeAPI, 100, 100, 30, 10)); + nodeAPI->addChild(grid, CreateNodeRect(nodeAPI, 70, 100, 30, 10)); + nodeAPI->addChild(grid, CreateNodeRect(nodeAPI, 100, 100, -1, -1)); + nodeAPI->addChild(grid, CreateNodeRect(nodeAPI, 500, 300, 30, 10)); + nodeAPI->addChild(grid, CreateNodeCircle(nodeAPI, 100, 100)); + nodeAPI->addChild(grid, CreateNodeCircle(nodeAPI, 70, 100)); + nodeAPI->addChild(grid, CreateNodeCircle(nodeAPI, -1, -1)); + nodeAPI->addChild(grid, CreateNodeCircle(nodeAPI, 500, 300)); + nodeAPI->addChild(grid, CreateNodeEllipse(nodeAPI, 100, 100)); + nodeAPI->addChild(grid, CreateNodeEllipse(nodeAPI, 70, 100)); + nodeAPI->addChild(grid, CreateNodeEllipse(nodeAPI, -1, -1)); + nodeAPI->addChild(grid, CreateNodeEllipse(nodeAPI, 500, 300)); + nodeAPI->addChild(grid, CreateNodePath(nodeAPI, 100, 100, command1)); + nodeAPI->addChild(grid, CreateNodePath(nodeAPI, 100, 100, command2)); + nodeAPI->addChild(grid, CreateNodePath(nodeAPI, -1, -1, command1)); + nodeAPI->addChild(grid, CreateNodePath(nodeAPI, 500, 300, command1)); + nodeAPI->addChild(grid, CreateNodeRectDiffCornerRadius(nodeAPI, { 30, 10, 10, 10, 10, 10 })); + nodeAPI->addChild(grid, CreateNodeRectDiffCornerRadius(nodeAPI, { 30, 10, 10, 10, 0, 0 })); + nodeAPI->addChild(grid, CreateNodeRectDiffCornerRadius(nodeAPI, { 30, 10, -1, -1, -1, -1 })); + nodeAPI->addChild(grid, CreateNodeOutliers(nodeAPI, -1, { 100, 100, 30, 10 })); + nodeAPI->addChild(grid, CreateNodeOutliers(nodeAPI, 4, { 100, 100, 30, 10 })); + auto column22 = CreateNodeRect(nodeAPI, 100, 100, 30, 10); + nodeAPI->resetAttribute(column22, NODE_CLIP_SHAPE); + nodeAPI->addChild(grid, column22); +} + +napi_value CommonAttrsClipShapeTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto grid = nodeAPI->createNode(ARKUI_NODE_GRID); + ArkUI_NumberValue gap_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem gap_item = { gap_value, sizeof(gap_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(grid, NODE_GRID_COLUMN_GAP, &gap_item); + nodeAPI->setAttribute(grid, NODE_GRID_ROW_GAP, &gap_item); + AddClipShapeChild(nodeAPI, grid); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), grid) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsClipShapeTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_clipshape_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_clipshape_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8265e00990229c7020a6ec3605b73576bbda022e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_clipshape_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_CLIPSHAPE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_CLIPSHAPE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsClipShapeTest { +public: + ~CommonAttrsClipShapeTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_CLIPSHAPE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_colorblend_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_colorblend_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18514ffbbf4a3567f58db7f9fcc45f1633b02bb3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_colorblend_test.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024 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 "commonattrs_colorblend_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t colorBackground, uint32_t colorBlend) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue image_value[] = {}; + ArkUI_AttributeItem image_item = { image_value, sizeof(image_value) / sizeof(ArkUI_NumberValue) }; + image_item.string = "resource://media/icon.png"; + nodeAPI->setAttribute(column, NODE_BACKGROUND_IMAGE, &image_item); + + ArkUI_NumberValue image_size_value[] = { { .i32 = ARKUI_IMAGE_SIZE_COVER } }; + ArkUI_AttributeItem image_size_item = { image_size_value, sizeof(image_size_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_IMAGE_SIZE_WITH_STYLE, &image_size_item); + + ArkUI_NumberValue color_background_value[] = { { .u32 = colorBackground } }; + ArkUI_AttributeItem color_background_item = { color_background_value, + sizeof(color_background_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &color_background_item); + + ArkUI_NumberValue color_blend_value[] = { { .u32 = colorBlend } }; + ArkUI_AttributeItem color_blend_item = { color_blend_value, + sizeof(color_blend_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_COLOR_BLEND, &color_blend_item); + + return column; +} + +napi_value CommonAttrsColorBlendTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsColorBlendTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsColorBlendTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column and set colorBlend + auto column1 = CreateChildNode(nodeAPI, COLOR_GREEN, COLOR_RED); + auto column2 = CreateChildNode(nodeAPI, COLOR_GREEN, COLOR_RED); + auto column3 = CreateChildNode(nodeAPI, COLOR_GREEN, COLOR_TRANSPARENT); + auto column4 = CreateChildNode(nodeAPI, COLOR_GREEN, COLOR_RED); + nodeAPI->resetAttribute(column2, NODE_COLOR_BLEND); + ArkUI_NumberValue color_blend_value[] = { { .u32 = COLOR_GRAY } }; + ArkUI_AttributeItem color_blend_item = { color_blend_value, + sizeof(color_blend_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column4, NODE_COLOR_BLEND, &color_blend_item); + + // add child + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(column, column1); + nodeAPI->addChild(column, column2); + nodeAPI->addChild(column, column3); + nodeAPI->addChild(column, column4); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsColorBlendTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_colorblend_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_colorblend_test.h new file mode 100644 index 0000000000000000000000000000000000000000..9a2b104830e596288540fc048dcd97feab11d8e9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_colorblend_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_COLORBLEND_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_COLORBLEND_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsColorBlendTest { +public: + ~CommonAttrsColorBlendTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_COLORBLEND_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_customshadow_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_customshadow_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48b2bc4e12fd7cbe2a6168f112b6f6fae5a3611c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_customshadow_test.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 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 "commonattrs_customshadow_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +struct CustomShadowParams { + float blurRadius; + int32_t coloringStrategy; + float offsetX; + float offsetY; + int32_t type; + uint32_t color; + uint32_t fill; +}; + +std::shared_ptr CreateCustomShadow(const CustomShadowParams& params) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsCustomShadowTest", "CreateCustomShadow"); + + auto column = std::make_shared(); + column->SetWidth(70); + column->SetHeight(70); + column->SetMargin(20); + column->SetBackgroundColor(COLOR_GRAY); + ArkUI_NumberValue customshadow_value[] = { { .f32 = params.blurRadius }, { .i32 = params.coloringStrategy }, + { .f32 = params.offsetX }, { .f32 = params.offsetY }, { .i32 = params.type }, { .u32 = params.color }, + { .u32 = params.fill } }; + ArkUI_AttributeItem customshadow_item = { customshadow_value, + sizeof(customshadow_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_CUSTOM_SHADOW, &customshadow_item); + + return column; +} + +static void AddCustomShadowChild(ColumnComponent* column) +{ + auto row1 = std::make_shared(); + auto row2 = std::make_shared(); + auto row3 = std::make_shared(); + auto row4 = std::make_shared(); + column->AddChild(row1); + column->AddChild(row2); + column->AddChild(row3); + column->AddChild(row4); + + row1->AddChild(CreateCustomShadow({ -30, {}, {}, {}, {}, COLOR_RED, 100 })); + row1->AddChild(CreateCustomShadow({ 0, {}, {}, {}, {}, COLOR_RED, 100 })); + row1->AddChild(CreateCustomShadow({ 30, {}, {}, {}, {}, COLOR_RED, 100 })); + row1->AddChild(CreateCustomShadow({ 30, true, {}, {}, {}, COLOR_GREEN, 100 })); + row2->AddChild(CreateCustomShadow({ 30, false, {}, {}, {}, COLOR_GREEN, 100 })); + row2->AddChild(CreateCustomShadow({ 30, -1, {}, {}, {}, COLOR_GREEN, 100 })); + row2->AddChild(CreateCustomShadow({ 30, {}, 20, 20, {}, COLOR_PINK, 100 })); + row2->AddChild(CreateCustomShadow({ 30, {}, 0, -100, {}, COLOR_PINK, 100 })); + row3->AddChild(CreateCustomShadow({ 30, {}, {}, {}, ARKUI_SHADOW_TYPE_COLOR, COLOR_BLUE, 100 })); + row3->AddChild(CreateCustomShadow({ 30, {}, {}, {}, ARKUI_SHADOW_TYPE_BLUR, COLOR_BLUE, 100 })); + row3->AddChild(CreateCustomShadow({ 30, {}, {}, {}, -1, COLOR_BLUE, 100 })); + row3->AddChild(CreateCustomShadow({ 30, {}, {}, {}, 2, COLOR_BLUE, 100 })); + row4->AddChild(CreateCustomShadow({ 30, {}, {}, {}, {}, {}, 100 })); + row4->AddChild(CreateCustomShadow({ 30, {}, {}, {}, {}, COLOR_BLACK, true })); + row4->AddChild(CreateCustomShadow({ 30, {}, {}, {}, {}, COLOR_BLACK, false })); + auto column16 = CreateCustomShadow({ 30, false, 10, 10, ARKUI_SHADOW_TYPE_COLOR, COLOR_RED, true }); + column16->resetAttribute(NODE_CUSTOM_SHADOW); + row4->AddChild(column16); +} + +napi_value CommonAttrsCustomShadowTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsCustomShadowTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsCustomShadowTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + column->SetBackgroundColor(COLOR_YELLOW); + AddCustomShadowChild(column); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsCustomShadowTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_customshadow_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_customshadow_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8e5347d90e4ad7abe38ac14e135dd8910397440e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_customshadow_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_CUSTOMSHADOW_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_CUSTOMSHADOW_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" +#include "row_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsCustomShadowTest { +public: + ~CommonAttrsCustomShadowTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_CUSTOMSHADOW_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_defaultfocus_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_defaultfocus_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..764596f869fca579072ba0034be12d5b8fec56aa --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_defaultfocus_test.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2024 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 "commonattrs_defaultfocus_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateNodeWithoutDefaultFocus(const std::string& id) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "CreateNodeWithoutDefaultFocus"); + auto radio = std::make_shared(ARKUI_NODE_RADIO); + radio->SetWidth(SIZE_100); + radio->SetHeight(SIZE_100); + radio->SetMargin(DEFAULT_MARGIN); + radio->SetId(id); + radio->RegisterOnFocus([radio]() { + ArkUI_NumberValue checked_value[] = { { .i32 = true } }; + ArkUI_AttributeItem checked_item = { checked_value, sizeof(checked_value) / sizeof(ArkUI_NumberValue) }; + radio->setAttribute(NODE_RADIO_CHECKED, &checked_item); + }); + + return radio; +} + +std::shared_ptr CreateNodeWithDefaultFocus(const std::string& id, int32_t defaultFocus) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "CreateNodeWithDefaultFocus"); + auto radio = CreateNodeWithoutDefaultFocus(id); + ArkUI_NumberValue textarea_value[] = { { .i32 = defaultFocus } }; + ArkUI_AttributeItem focus_item = { textarea_value, sizeof(textarea_value) / sizeof(ArkUI_NumberValue) }; + radio->setAttribute(NODE_DEFAULT_FOCUS, &focus_item); + + return radio; +} + +napi_value CommonAttrsDefaultFocusTest::CreateNativeNodeSingle(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "CreateNativeNodeSingle"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + column->AddChild(CreateNodeWithDefaultFocus("R1", false)); + column->AddChild(CreateNodeWithDefaultFocus("R2", true)); + column->AddChild(CreateNodeWithDefaultFocus("R3", false)); + column->AddChild(CreateNodeWithoutDefaultFocus("R4")); + column->AddChild(CreateNodeWithoutDefaultFocus("R5")); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsDefaultFocusTest::CreateNativeNodeNone(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "CreateNativeNodeNone"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + column->AddChild(CreateNodeWithoutDefaultFocus("R1")); + column->AddChild(CreateNodeWithDefaultFocus("R2", false)); + column->AddChild(CreateNodeWithoutDefaultFocus("R3")); + column->AddChild(CreateNodeWithDefaultFocus("R4", false)); + auto radio5 = CreateNodeWithDefaultFocus("R5", true); + radio5->resetAttribute(NODE_DEFAULT_FOCUS); + column->AddChild(radio5); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsDefaultFocusTest::CreateNativeNodeMulti(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "CreateNativeNodeMulti"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + column->AddChild(CreateNodeWithDefaultFocus("R1", false)); + column->AddChild(CreateNodeWithDefaultFocus("R2", false)); + column->AddChild(CreateNodeWithDefaultFocus("R3", true)); + column->AddChild(CreateNodeWithDefaultFocus("R4", true)); + column->AddChild(CreateNodeWithDefaultFocus("R5", true)); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsDefaultFocusTest::CreateNativeNodeAbnormal(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "CreateNativeNodeAbnormal"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + column->AddChild(CreateNodeWithDefaultFocus("R1", -1)); + column->AddChild(CreateNodeWithDefaultFocus("R2", -1)); + column->AddChild(CreateNodeWithDefaultFocus("R3", true)); + column->AddChild(CreateNodeWithDefaultFocus("R4", false)); + column->AddChild(CreateNodeWithDefaultFocus("R5", false)); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDefaultFocusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_defaultfocus_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_defaultfocus_test.h new file mode 100644 index 0000000000000000000000000000000000000000..94ff4678d1e69b68c6a2fef16a2f6224efd94347 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_defaultfocus_test.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_DEFAULT_FOCUS_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_DEFAULT_FOCUS_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "button_component.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsDefaultFocusTest { +public: + ~CommonAttrsDefaultFocusTest(); + static napi_value CreateNativeNodeSingle(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodeNone(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodeMulti(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodeAbnormal(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_DEFAULT_FOCUS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_displaypriority_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_displaypriority_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..29c4c418e0f72252eca27e58614d098f8b01f978 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_displaypriority_test.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2024 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 "commonattrs_displaypriority_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateColumnNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem borderWidth_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &borderWidth_item); + + return nodeHandle; +} + +static auto CreateFlexNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_FLEX); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem borderWidth_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &borderWidth_item); + + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t displayPriority, uint32_t color) +{ + auto button = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_HEIGHT, &height_item); + ArkUI_NumberValue displayPriority_value[] = { { .u32 = displayPriority } }; + ArkUI_AttributeItem displayPriority_item = { displayPriority_value, + sizeof(displayPriority_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_DISPLAY_PRIORITY, &displayPriority_item); + ArkUI_NumberValue background_color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_BACKGROUND_COLOR, &background_color_item); + + return button; +} + +napi_value CommonAttrsDisplayPriorityTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDisplayPriorityTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDisplayPriorityTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column and set displayPriority + auto column1 = CreateChildNode(nodeAPI, 3, COLOR_RED); + auto column2 = CreateChildNode(nodeAPI, 5, COLOR_YELLOW); + auto column3 = CreateChildNode(nodeAPI, 0, COLOR_BLUE); + auto column4 = CreateChildNode(nodeAPI, 1, COLOR_BLACK); + auto column5 = CreateChildNode(nodeAPI, 2, COLOR_GREEN); + nodeAPI->resetAttribute(column2, NODE_DISPLAY_PRIORITY); + + auto column6 = CreateChildNode(nodeAPI, 1, COLOR_RED); + auto column7 = CreateChildNode(nodeAPI, 2, COLOR_BLUE); + auto column8 = CreateChildNode(nodeAPI, 0, COLOR_BLACK); + auto column9 = CreateChildNode(nodeAPI, 2, COLOR_GREEN); + + // add child + auto columnP1 = CreateColumnNode(nodeAPI); + auto flexP2 = CreateFlexNode(nodeAPI); + nodeAPI->addChild(columnP1, column1); + nodeAPI->addChild(columnP1, column2); + nodeAPI->addChild(columnP1, column3); + nodeAPI->addChild(columnP1, column4); + nodeAPI->addChild(columnP1, column5); + nodeAPI->addChild(flexP2, column6); + nodeAPI->addChild(flexP2, column7); + nodeAPI->addChild(flexP2, column8); + nodeAPI->addChild(flexP2, column9); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(column, columnP1); + nodeAPI->addChild(column, flexP2); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsDisplayPriorityTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_displaypriority_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_displaypriority_test.h new file mode 100644 index 0000000000000000000000000000000000000000..944498146b372bffa8b2ada88153fa72e57ba219 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_displaypriority_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_DISPLAYPRIORITY_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_DISPLAYPRIORITY_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsDisplayPriorityTest { +public: + ~CommonAttrsDisplayPriorityTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_DISPLAYPRIORITY_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focus_on_touch_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focus_on_touch_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0190cb298ba0dbe1ad8d82161291845ae84ed35e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focus_on_touch_test.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2024 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 "commonattrs_focus_on_touch_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto SetCaretColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_AREA_CARET_COLOR, &color_item); + return nodeHandle; +} + +static auto SetEnableKeyboardOnFocus(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + ArkUI_NumberValue keyboard_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_AREA_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_AREA_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + return nodeHandle; +} + +static auto SetFocusOnTouch(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t focus) +{ + ArkUI_NumberValue value[] = { { .i32 = focus } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FOCUS_ON_TOUCH, &item); + return nodeHandle; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsFocusOnTouchTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsFocusOnTouchTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsFocusOnTouchTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + if (eventId == ON_FOCUS_EVENT_ID) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + } +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t focus, const char* id) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_200); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_100); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetEnableKeyboardOnFocus(nodeAPI, nodeHandle); + nodeHandle = SetFocusOnTouch(nodeAPI, nodeHandle, focus); + nodeHandle = SetId(nodeAPI, nodeHandle, id); + nodeHandle = SetCaretColor(nodeAPI, nodeHandle, COLOR_TRANSPARENT); + return nodeHandle; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto text1 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA); + auto text2 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA); + auto text3 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA); + auto text4 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA); + auto text5 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA); + + nodeAPI->addChild(column, text1); + nodeAPI->addChild(column, text2); + nodeAPI->addChild(column, text3); + nodeAPI->addChild(column, text4); + nodeAPI->addChild(column, text5); + + text1 = SetText(nodeAPI, text1, PARAM_1, "text1"); + text2 = SetText(nodeAPI, text2, PARAM_0, "text2"); + text3 = SetText(nodeAPI, text3, PARAM_2, "text3"); + text4 = SetText(nodeAPI, text4, PARAM_NEGATIVE_1, "text4"); + text5 = SetText(nodeAPI, text5, PARAM_1, "text5"); + nodeAPI->resetAttribute(text5, NODE_FOCUS_ON_TOUCH); + + nodeAPI->registerNodeEvent(text1, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(text2, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(text3, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(text4, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(text5, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + return column; +} + +napi_value CommonAttrsFocusOnTouchTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityRoleTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityRoleTest", + "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsAccessibilityRoleTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focus_on_touch_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focus_on_touch_test.h new file mode 100644 index 0000000000000000000000000000000000000000..bc259865b245bb95d87db286f09999168800b525 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focus_on_touch_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_FOCUS_ON_TOUCH_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_FOCUS_ON_TOUCH_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsFocusOnTouchTest { +public: + ~CommonAttrsFocusOnTouchTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_FOCUS_ON_TOUCH_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focusstatus_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focusstatus_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec57be275db759d2c363e662505f12f470fab6d2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focusstatus_test.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2024 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 "commonattrs_focusstatus_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateNodeWithoutFocusStatus(const std::string& id) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsFocusStatusTest", "CreateNodeWithoutFocusStatus"); + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto radio = std::make_shared(ARKUI_NODE_RADIO); + radio->SetWidth(SIZE_100); + radio->SetHeight(SIZE_100); + radio->SetMargin(DEFAULT_MARGIN); + radio->SetId(id); + radio->RegisterOnFocus([radio]() { + ArkUI_NumberValue checked_value[] = { { .i32 = true } }; + ArkUI_AttributeItem checked_item = { checked_value, sizeof(checked_value) / sizeof(ArkUI_NumberValue) }; + radio->setAttribute(NODE_RADIO_CHECKED, &checked_item); + }); + + return radio; +} + +std::shared_ptr CreateNodeWithFocusStatus(const std::string& id, int32_t focusStatus) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsFocusStatusTest", "CreateNodeWithFocusStatus"); + auto radio = CreateNodeWithoutFocusStatus(id); + ArkUI_NumberValue textarea_value[] = { { .i32 = focusStatus } }; + ArkUI_AttributeItem focus_item = { textarea_value, sizeof(textarea_value) / sizeof(ArkUI_NumberValue) }; + radio->setAttribute(NODE_FOCUS_STATUS, &focus_item); + + return radio; +} + +static void AddFocusStatusChild(ColumnComponent* column) +{ + auto button = std::make_shared(ARKUI_NODE_BUTTON); + button->SetWidth(50); + button->SetHeight(50); + button->SetMargin(10); + button->SetBackgroundColor(COLOR_TRANSPARENT); + button->SetId("Button"); + column->AddChild(button); + + auto radio1 = CreateNodeWithoutFocusStatus("R1"); + auto radio2 = CreateNodeWithFocusStatus("R2", -1); + auto radio3 = CreateNodeWithFocusStatus("R3", 0); + auto radio4 = CreateNodeWithFocusStatus("R4", 1); + column->AddChild(radio1); + column->AddChild(radio2); + column->AddChild(radio3); + column->AddChild(radio4); + + button->RegisterOnClick([radio1]() { + ArkUI_NumberValue focus_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem focus_item = { focus_value, sizeof(focus_value) / sizeof(ArkUI_NumberValue) }; + radio1->setAttribute(NODE_FOCUS_STATUS, &focus_item); + }); +} + +napi_value CommonAttrsFocusStatusTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsFocusStatusTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsFocusStatusTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + AddFocusStatusChild(column); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsFocusStatusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focusstatus_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focusstatus_test.h new file mode 100644 index 0000000000000000000000000000000000000000..445250b6ee7c8f88613fb68d40bb9ea8c3ce267a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_focusstatus_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_FOCUS_STATUS_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_FOCUS_STATUS_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsFocusStatusTest { +public: + ~CommonAttrsFocusStatusTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_FOCUS_STATUS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_foregroundcolor_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_foregroundcolor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2af0aeaaffb47006dbf022db968581bed1ccd6e8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_foregroundcolor_test.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2024 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 "commonattrs_foregroundcolor_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateColumnWithForegroundColor(uint32_t foregroundColor) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsForegroundColorTest", "CreateColumnWithForegroundColor"); + + auto column = std::make_shared(); + column->SetWidth(250); + column->SetHeight(140); + column->SetMargin(DEFAULT_MARGIN); + column->SetBorderWidth(2); + ArkUI_NumberValue foregroundcolor_value[] = { { .u32 = foregroundColor } }; + ArkUI_AttributeItem foregroundcolor_item = { foregroundcolor_value, + sizeof(foregroundcolor_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_FOREGROUND_COLOR, &foregroundcolor_item); + + return column; +} + +std::shared_ptr CreateButtonWithForegroundColor(uint32_t foregroundColor) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsForegroundColorTest", "CreateButtonWithForegroundColor"); + + auto button = std::make_shared(); + button->SetWidth(150); + button->SetHeight(50); + button->SetMargin(8); + button->SetFontSize(30); + ArkUI_NumberValue text_value[] = {}; + ArkUI_AttributeItem text_item = { text_value, sizeof(text_value) / sizeof(ArkUI_NumberValue) }; + text_item.string = "TEXT"; + button->setAttribute(NODE_BUTTON_LABEL, &text_item); + if (foregroundColor != NULL) { + ArkUI_NumberValue foregroundcolor_value[] = { { .u32 = foregroundColor } }; + ArkUI_AttributeItem foregroundcolor_item = { foregroundcolor_value, + sizeof(foregroundcolor_value) / sizeof(ArkUI_NumberValue) }; + button->setAttribute(NODE_FOREGROUND_COLOR, &foregroundcolor_item); + } + + return button; +} + +static void AddForegroundColorChild(ColumnComponent* column) +{ + auto column1 = CreateColumnWithForegroundColor({}); + column1->SetHeight(210); + auto column2 = CreateColumnWithForegroundColor(COLOR_GREEN); + auto column3 = CreateColumnWithForegroundColor(COLOR_GREEN); + auto column4 = CreateColumnWithForegroundColor(COLOR_GREEN); + ArkUI_NumberValue colorblend_value[] = { { .u32 = COLOR_BLUE } }; + ArkUI_AttributeItem colorblend_item = { colorblend_value, sizeof(colorblend_value) / sizeof(ArkUI_NumberValue) }; + column4->setAttribute(NODE_COLOR_BLEND, &colorblend_item); + + auto button1 = CreateButtonWithForegroundColor({}); + auto button2 = CreateButtonWithForegroundColor(COLOR_RED); + auto button3 = CreateButtonWithForegroundColor(COLOR_RED); + button3->resetAttribute(NODE_FOREGROUND_COLOR); + auto button4 = CreateButtonWithForegroundColor({}); + auto button5 = CreateButtonWithForegroundColor(COLOR_RED); + auto button6 = CreateButtonWithForegroundColor({}); + button6->SetBackgroundImage("resource://media/background_yellow.png"); + button6->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + auto button7 = CreateButtonWithForegroundColor(COLOR_RED); + button7->SetBackgroundImage("resource://media/background_yellow.png"); + button7->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + auto button8 = CreateButtonWithForegroundColor({}); + auto button9 = CreateButtonWithForegroundColor(COLOR_RED); + ArkUI_NumberValue colorblendgray_value[] = { { .u32 = COLOR_PURPLE } }; + colorblend_item = { colorblendgray_value, sizeof(colorblendgray_value) / sizeof(ArkUI_NumberValue) }; + button8->setAttribute(NODE_COLOR_BLEND, &colorblend_item); + button9->setAttribute(NODE_COLOR_BLEND, &colorblend_item); + + column->AddChild(column1); + column->AddChild(column2); + column->AddChild(column3); + column->AddChild(column4); + column1->AddChild(button1); + column1->AddChild(button2); + column1->AddChild(button3); + column2->AddChild(button4); + column2->AddChild(button5); + column3->AddChild(button6); + column3->AddChild(button7); + column4->AddChild(button8); + column4->AddChild(button9); +} + +napi_value CommonAttrsForegroundColorTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsForegroundColorTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsForegroundColorTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + AddForegroundColorChild(column); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsForegroundColorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_foregroundcolor_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_foregroundcolor_test.h new file mode 100644 index 0000000000000000000000000000000000000000..7e1f46f8409b53499d5910c1d2286f476cb1b14d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_foregroundcolor_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_FOREGROUND_COLOR_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_FOREGROUND_COLOR_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "button_component.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsForegroundColorTest { +public: + ~CommonAttrsForegroundColorTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_FOREGROUND_COLOR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_layoutweight_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_layoutweight_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23354d6278d3c70e1bc6f666d283bd0ac02c0fa3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_layoutweight_test.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2024 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 "commonattrs_layoutweight_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t layoutWeight, uint32_t color) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue background_color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue layoutWeight_value[] = { { .u32 = layoutWeight } }; + ArkUI_AttributeItem layoutWeight_item = { layoutWeight_value, + sizeof(layoutWeight_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_LAYOUT_WEIGHT, &layoutWeight_item); + + return nodeHandle; +} + +static auto CreateColumnNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem borderWidth_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &borderWidth_item); + + return nodeHandle; +} + +static auto CreateFlexNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_FLEX); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem borderWidth_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &borderWidth_item); + + return nodeHandle; +} + +napi_value CommonAttrsLayoutWeightTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsLayoutWeightTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsLayoutWeightTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column and set layoutWeight + auto column1 = CreateChildNode(nodeAPI, 1, COLOR_GREEN); + auto column2 = CreateChildNode(nodeAPI, 0, COLOR_BLUE); + auto column3 = CreateChildNode(nodeAPI, 2, COLOR_RED); + auto column4 = CreateChildNode(nodeAPI, 3, COLOR_GRAY); + nodeAPI->resetAttribute(column4, NODE_LAYOUT_WEIGHT); + auto column5 = CreateChildNode(nodeAPI, 1, COLOR_GREEN); + auto column6 = CreateChildNode(nodeAPI, 0, COLOR_BLUE); + auto column7 = CreateChildNode(nodeAPI, 2, COLOR_RED); + auto column8 = CreateChildNode(nodeAPI, 3, COLOR_GRAY); + nodeAPI->resetAttribute(column8, NODE_LAYOUT_WEIGHT); + + // add child + auto columnP1 = CreateColumnNode(nodeAPI); + auto flexP2 = CreateFlexNode(nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + nodeAPI->addChild(columnP1, column1); + nodeAPI->addChild(columnP1, column2); + nodeAPI->addChild(columnP1, column3); + nodeAPI->addChild(columnP1, column4); + nodeAPI->addChild(flexP2, column5); + nodeAPI->addChild(flexP2, column6); + nodeAPI->addChild(flexP2, column7); + nodeAPI->addChild(flexP2, column8); + nodeAPI->addChild(column, columnP1); + nodeAPI->addChild(column, flexP2); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsLayoutWeightTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_layoutweight_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_layoutweight_test.h new file mode 100644 index 0000000000000000000000000000000000000000..bca15bf3bfc013fda45fafb79731097a92880cb9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_layoutweight_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_LAYOUTWEIGHT_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_LAYOUTWEIGHT_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsLayoutWeightTest { +public: + ~CommonAttrsLayoutWeightTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_LAYOUTWEIGHT_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_markanchor_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_markanchor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8332d216de387cadc72410d717e59e5c90440fd9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_markanchor_test.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2024 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 "commonattrs_markanchor_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateWithMarkAnchor(uint32_t color, float markAnchorX, float markAnchorY) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsMarkAnchorTest", "CreateWithMarkAnchor"); + + auto column = std::make_shared(); + column->SetWidth(SIZE_200); + column->SetHeight(SIZE_100); + column->SetBackgroundColor(color); + ArkUI_NumberValue markanchor_value[] = { { .f32 = markAnchorX }, { .f32 = markAnchorY } }; + ArkUI_AttributeItem markanchor_item = { markanchor_value, sizeof(markanchor_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_MARK_ANCHOR, &markanchor_item); + + return column; +} + +std::shared_ptr CreateWithPositionAndMarkAnchor( + uint32_t color, float positionX, float positionY, float markAnchorX, float markAnchorY) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsMarkAnchorTest", "CreateWithPositionAndMarkAnchor"); + + auto column = CreateWithMarkAnchor(color, markAnchorX, markAnchorY); + ArkUI_NumberValue position_value[] = { { .f32 = positionX }, { .f32 = positionY } }; + ArkUI_AttributeItem position_item = { position_value, sizeof(position_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_POSITION, &position_item); + + return column; +} + +std::shared_ptr CreateBorder() +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsMarkAnchorTest", "CreateBorder"); + + auto column = std::make_shared(); + column->SetWidth(SIZE_200); + column->SetHeight(SIZE_100); + column->SetMargin(5); + column->SetBorderWidth(2); + return column; +} + +static void AddMarkAnchorChild(ColumnComponent* column) +{ + auto column1 = CreateWithPositionAndMarkAnchor(COLOR_RED, 30, 0, {}, {}); + auto column2 = CreateWithPositionAndMarkAnchor(COLOR_GREEN, 30, 0, 30, -40); + auto column3 = CreateWithPositionAndMarkAnchor(COLOR_BLACK, 30, 0, -150, 0); + auto column4 = CreateWithMarkAnchor(COLOR_PURPLE, 0, 0); + auto column5 = CreateWithMarkAnchor(COLOR_BLUE, 30, -40); + auto column6 = CreateWithMarkAnchor(COLOR_YELLOW, -150, 0); + auto column7 = CreateWithMarkAnchor(COLOR_PINK, 30, -40); + column7->resetAttribute(NODE_MARK_ANCHOR); + + auto column01 = CreateBorder(); + auto column02 = CreateBorder(); + auto column03 = CreateBorder(); + auto column04 = CreateBorder(); + auto column05 = CreateBorder(); + auto column06 = CreateBorder(); + auto column07 = CreateBorder(); + + column01->AddChild(column1); + column02->AddChild(column2); + column03->AddChild(column3); + column04->AddChild(column4); + column05->AddChild(column5); + column06->AddChild(column6); + column07->AddChild(column7); + column->AddChild(column01); + column->AddChild(column02); + column->AddChild(column03); + column->AddChild(column04); + column->AddChild(column05); + column->AddChild(column06); + column->AddChild(column07); +} + +napi_value CommonAttrsMarkAnchorTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsMarkAnchorTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsMarkAnchorTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + AddMarkAnchorChild(column); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsMarkAnchorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_markanchor_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_markanchor_test.h new file mode 100644 index 0000000000000000000000000000000000000000..597391dd9b404da0a2c0b66b3a421e14cd3f3c8e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_markanchor_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_MARK_ANCHOR_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_MARK_ANCHOR_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsMarkAnchorTest { +public: + ~CommonAttrsMarkAnchorTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_MARK_ANCHOR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_offset_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_offset_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5ddc9bb9e64255e151435544c50a04de1008381 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_offset_test.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 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 "commonattrs_offset_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateColumnWithOffset(uint32_t color, float offsetX, float offsetY) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsOffsetTest", "CreateColumnWithOffset"); + + auto column = std::make_shared(); + column->SetWidth(120); + column->SetHeight(120); + column->SetMargin(DEFAULT_MARGIN); + column->SetBackgroundColor(color); + ArkUI_NumberValue offset_value[] = { { .f32 = offsetX }, { .f32 = offsetY } }; + ArkUI_AttributeItem offset_item = { offset_value, sizeof(offset_value) / sizeof(ArkUI_NumberValue) }; + column->setAttribute(NODE_OFFSET, &offset_item); + + return column; +} + +napi_value CommonAttrsOffsetTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsOffsetTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOffsetTest", "GetContext env or info is null"); + return nullptr; + } + + auto column1 = CreateColumnWithOffset(COLOR_YELLOW, 30, 10); + auto column2 = CreateColumnWithOffset(COLOR_RED, 30, 10); + auto column3 = CreateColumnWithOffset(COLOR_BLUE, 230, 0); + auto column4 = CreateColumnWithOffset(COLOR_GREEN, 300, 800); + auto column5 = CreateColumnWithOffset(COLOR_PINK, {}, {}); + column2->resetAttribute(NODE_OFFSET); + + auto column = new ColumnComponent(); + column->AddChild(column1); + column->AddChild(column2); + column->AddChild(column3); + column->AddChild(column4); + column->AddChild(column5); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOffsetTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_offset_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_offset_test.h new file mode 100644 index 0000000000000000000000000000000000000000..5b9a673c64d8cb216fe0b1fdba4efc39651a1a56 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_offset_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_OFFSET_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_OFFSET_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsOffsetTest { +public: + ~CommonAttrsOffsetTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_OFFSET_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinecolor_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinecolor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3b08b891821d4ef329c2943c09b7e898ae474d4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinecolor_test.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2024 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 "commonattrs_outlinecolor_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetOutlineColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + ArkUI_NumberValue color_value[] = {}; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_OUTLINE_COLOR, &color_item); + return nodeHandle; +} + +static auto SetOutlineColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_OUTLINE_COLOR, &color_item); + return nodeHandle; +} + +static auto SetOutlineColor( + ArkUI_NodeHandle& nodeHandle, uint32_t color1, uint32_t color2, uint32_t color3, uint32_t color4) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + ArkUI_NumberValue color_value[] = { { .u32 = color1 }, { .u32 = color2 }, { .u32 = color3 }, { .u32 = color4 } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_OUTLINE_COLOR, &color_item); + return nodeHandle; +} + +static auto SetOutlineWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width }, { .f32 = width }, { .f32 = width }, { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_OUTLINE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetButtonType(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t type) +{ + ArkUI_NumberValue value[] = { { .u32 = type } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BUTTON_TYPE, &item); + return nodeHandle; +} + +static auto SetShape(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + ArkUI_NumberValue value[] = { { .i32 = ARKUI_CLIP_TYPE_PATH }, { .f32 = SIZE_100 }, { .f32 = SIZE_100 } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + item.string = "M60 0 L120 100 L0 100 Z"; + nodeAPI->setAttribute(nodeHandle, NODE_CLIP_SHAPE, &item); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_300); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_20); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_10); + nodeHandle = SetOutlineWidth(nodeAPI, nodeHandle, PARAM_5); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_YELLOW); + return nodeHandle; +} + +static auto SetColumn(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_100); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_100); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_10); + nodeHandle = SetOutlineWidth(nodeAPI, nodeHandle, PARAM_5); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_YELLOW); + return nodeHandle; +} + +static auto SetButton(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t type) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_300); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_20); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_10); + nodeHandle = SetOutlineWidth(nodeAPI, nodeHandle, PARAM_5); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_YELLOW); + nodeHandle = SetButtonType(nodeAPI, nodeHandle, type); + return nodeHandle; +} + +static auto SetButton(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t type, float width) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, width); + nodeHandle = SetHeight(nodeAPI, nodeHandle, width); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_10); + nodeHandle = SetOutlineWidth(nodeAPI, nodeHandle, PARAM_5); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_YELLOW); + nodeHandle = SetButtonType(nodeAPI, nodeHandle, type); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto text1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_TEXT); + auto text2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_TEXT); + auto text3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_TEXT); + auto text4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_TEXT); + auto button1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_BUTTON); + auto button2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_BUTTON); + auto button3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_BUTTON); + auto row = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto button4 = CreateChildNode(nodeAPI, row, ARKUI_NODE_BUTTON); + auto button5 = CreateChildNode(nodeAPI, row, ARKUI_NODE_BUTTON); + auto button6 = CreateChildNode(nodeAPI, row, ARKUI_NODE_BUTTON); + auto column1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_COLUMN); + auto column2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_COLUMN); + auto column3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_COLUMN); + text1 = SetText(nodeAPI, text1); + text2 = SetText(nodeAPI, text2); + text3 = SetText(nodeAPI, text3); + text4 = SetText(nodeAPI, text4); + button1 = SetButton(nodeAPI, button1, ARKUI_BUTTON_TYPE_CAPSULE); + button2 = SetButton(nodeAPI, button2, ARKUI_BUTTON_TYPE_CAPSULE); + button3 = SetButton(nodeAPI, button3, ARKUI_BUTTON_TYPE_CAPSULE); + button4 = SetButton(nodeAPI, button4, ARKUI_BUTTON_TYPE_CIRCLE, SIZE_50); + button5 = SetButton(nodeAPI, button5, ARKUI_BUTTON_TYPE_CIRCLE, SIZE_50); + button6 = SetButton(nodeAPI, button6, ARKUI_BUTTON_TYPE_CIRCLE, SIZE_50); + column1 = SetColumn(nodeAPI, column1); + column2 = SetColumn(nodeAPI, column2); + column3 = SetColumn(nodeAPI, column3); + column1 = SetShape(nodeAPI, column1); + column2 = SetShape(nodeAPI, column2); + column3 = SetShape(nodeAPI, column3); + text1 = SetOutlineColor(nodeAPI, text1, COLOR_RED); + text2 = SetOutlineColor(text2, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_PURPLE); + text3 = SetOutlineColor(nodeAPI, text3); + text4 = SetOutlineColor(text4, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_PURPLE); + nodeAPI->resetAttribute(text4, NODE_OUTLINE_COLOR); + button1 = SetOutlineColor(nodeAPI, button1, COLOR_RED); + button2 = SetOutlineColor(button2, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_PURPLE); + button3 = SetOutlineColor(nodeAPI, button3); + button4 = SetOutlineColor(nodeAPI, button4, COLOR_RED); + button5 = SetOutlineColor(button5, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_PURPLE); + button6 = SetOutlineColor(nodeAPI, button6); + column1 = SetOutlineColor(nodeAPI, column1, COLOR_RED); + column2 = SetOutlineColor(column2, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_PURPLE); + column3 = SetOutlineColor(nodeAPI, column3); + return column; +} + +napi_value CommonAttrsOutlineColorTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOutlineColorTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOutlineColorTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOutlineColorTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinecolor_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinecolor_test.h new file mode 100644 index 0000000000000000000000000000000000000000..257cdb117dac6439175679e7141f45925cf41f1a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinecolor_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_OUTLINECOLOR_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_OUTLINECOLOR_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_20 20 + +class CommonAttrsOutlineColorTest { +public: + ~CommonAttrsOutlineColorTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_OUTLINECOLOR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinewidth_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinewidth_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa4d0ffd87498cfb690f5cc932948c42c024d037 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinewidth_test.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2024 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 "commonattrs_outlinewidth_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateNodePath(ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height, const char* command) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_100 } }; + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_100 } }; + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + ArkUI_NumberValue clipShape_value[] = { { .i32 = ARKUI_CLIP_TYPE_PATH }, { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem clipShape_item = { clipShape_value, sizeof(clipShape_value) / sizeof(ArkUI_NumberValue) }; + clipShape_item.string = command; + nodeAPI->setAttribute(column, NODE_CLIP_SHAPE, &clipShape_item); + + return column; +} + +static auto CreateButtonNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_BUTTON); + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_50 } }; + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_50 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + ArkUI_NumberValue buttonType_value[] = { { .i32 = ARKUI_BUTTON_TYPE_CIRCLE } }; + ArkUI_AttributeItem buttonType_item = { buttonType_value, sizeof(buttonType_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BUTTON_TYPE, &buttonType_item); + + return column; +} + +napi_value CommonAttrsOutlineWidthTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOutlineWidthTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOutlineWidthTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // creat column + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto column3 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + const char* command1 = "M60 0 L120 100 L0 100 Z"; + auto column4 = CreateNodePath(nodeAPI, 100, 100, command1); + auto column5 = CreateButtonNode(nodeAPI); + auto column6 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // set attribute + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_50 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue green_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem green_item = { green_value, sizeof(green_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue red_value[] = { { .u32 = COLOR_RED } }; + ArkUI_AttributeItem red_item = { red_value, sizeof(red_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue blue_value[] = { { .u32 = COLOR_BLUE } }; + ArkUI_AttributeItem blue_item = { blue_value, sizeof(blue_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue outline1_value[] = { { .f32 = 5 }, { .f32 = 5 }, { .f32 = 5 }, { .f32 = 5 } }; + ArkUI_AttributeItem outline1_item = { outline1_value, sizeof(outline1_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column1, NODE_OUTLINE_WIDTH, &outline1_item); + ArkUI_NumberValue outline2_value[] = { { .f32 = 0 }, { .f32 = 0 }, { .f32 = 0 }, { .f32 = 0 } }; + ArkUI_AttributeItem outline2_item = { outline2_value, sizeof(outline2_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column2, NODE_OUTLINE_WIDTH, &outline2_item); + ArkUI_NumberValue outline3_value[] = { { .f32 = -1 }, { .f32 = -1 }, { .f32 = -1 }, { .f32 = -1 } }; + ArkUI_AttributeItem outline3_item = { outline3_value, sizeof(outline3_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column3, NODE_OUTLINE_WIDTH, &outline3_item); + ArkUI_NumberValue outline4_value[] = { { .f32 = 5 }, { .f32 = 10 }, { .f32 = 5 }, { .f32 = 20 } }; + ArkUI_AttributeItem outline4_item = { outline4_value, sizeof(outline4_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue outline5_value[] = { { .f32 = 5 }, { .f32 = 5 }, { .f32 = 5 }, { .f32 = 5 } }; + ArkUI_AttributeItem outline5_item = { outline5_value, sizeof(outline5_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue outline6_value[] = { { .f32 = 10 }, { .f32 = 10 }, { .f32 = 10 }, { .f32 = 10 } }; + ArkUI_AttributeItem outline6_item = { outline6_value, sizeof(outline6_value) / sizeof(ArkUI_NumberValue) }; + + nodeAPI->setAttribute(column1, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column1, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(column1, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(column1, NODE_BACKGROUND_COLOR, &green_item); + nodeAPI->setAttribute(column2, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column2, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(column2, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(column2, NODE_BACKGROUND_COLOR, &red_item); + nodeAPI->setAttribute(column3, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column3, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(column3, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(column3, NODE_BACKGROUND_COLOR, &blue_item); + nodeAPI->setAttribute(column4, NODE_OUTLINE_WIDTH, &outline4_item); + nodeAPI->setAttribute(column4, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(column5, NODE_OUTLINE_WIDTH, &outline5_item); + nodeAPI->setAttribute(column5, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(column6, NODE_OUTLINE_WIDTH, &outline6_item); + nodeAPI->resetAttribute(column6, NODE_OUTLINE_WIDTH); + nodeAPI->setAttribute(column6, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(column6, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(column6, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(column6, NODE_BACKGROUND_COLOR, &green_item); + + // add child + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(column, column1); + nodeAPI->addChild(column, column2); + nodeAPI->addChild(column, column3); + nodeAPI->addChild(column, column4); + nodeAPI->addChild(column, column5); + nodeAPI->addChild(column, column6); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsOutlineWidthTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinewidth_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinewidth_test.h new file mode 100644 index 0000000000000000000000000000000000000000..de216f5e12ddb277118adfe50a6468e48d10c0b1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_outlinewidth_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_OUTLINEWIDTH_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_OUTLINEWIDTH_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsOutlineWidthTest { +public: + ~CommonAttrsOutlineWidthTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_OUTLINEWIDTH_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_overlay_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_overlay_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..36955be4b3a3434a907599606da012023c7124fe --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_overlay_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 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 "commonattrs_overlay_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateNodeWithOverlay(int32_t type, float offsetX, float offsetY) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", "CreateImageNode"); + + auto column = std::make_shared(); + column->SetWidth(SIZE_150); + column->SetHeight(SIZE_150); + column->SetBorderWidth(1); + column->SetBackgroundImage("resource://media/background_yellow.png"); + column->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + ArkUI_NumberValue overlay_value[] = { { .i32 = type }, { .f32 = offsetX }, { .f32 = offsetY } }; + ArkUI_AttributeItem overlay_item = { overlay_value, sizeof(overlay_value) / sizeof(ArkUI_NumberValue) }; + overlay_item.string = "Overlay"; + column->setAttribute(NODE_OVERLAY, &overlay_item); + + return column; +} + +static void AddOverlayChild(GridComponent* grid) +{ + grid->AddChild(CreateNodeWithOverlay({}, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_TOP_START, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_TOP, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_TOP_END, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_START, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_CENTER, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_END, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_BOTTOM_START, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_BOTTOM, {}, {})); + grid->AddChild(CreateNodeWithOverlay(ARKUI_ALIGNMENT_BOTTOM_END, {}, {})); + grid->AddChild(CreateNodeWithOverlay(-1, {}, {})); + grid->AddChild(CreateNodeWithOverlay(9, {}, {})); + grid->AddChild(CreateNodeWithOverlay({}, 0, -15)); + grid->AddChild(CreateNodeWithOverlay({}, 30, 15)); + auto column15 = CreateNodeWithOverlay(ARKUI_ALIGNMENT_CENTER, 30, 15); + column15->resetAttribute(NODE_OVERLAY); + grid->AddChild(column15); +} + +napi_value CommonAttrsOverlayTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", "GetContext env or info is null"); + return nullptr; + } + + auto grid = new GridComponent(); + grid->SetGridRowsGap(5); + grid->SetGridColumnsGap(5); + AddOverlayChild(grid); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), grid->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsBlurTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_overlay_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_overlay_test.h new file mode 100644 index 0000000000000000000000000000000000000000..a6bc12c68fd76eedfab0f8d7ae654fa51627a135 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_overlay_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_OVERLAY_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_OVERLAY_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" +#include "grid_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsOverlayTest { +public: + ~CommonAttrsOverlayTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_OVERLAY_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_padding_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_padding_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..51318a981039ef98234bb2b3e27ed0148847cec7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_padding_test.cpp @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2024 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 "commonattrs_padding_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetPadding(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, float padding) +{ + ArkUI_NumberValue value[] = { { .f32 = padding } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_PADDING, &item); + return nodeHandle; +} + +static auto SetPadding(ArkUI_NodeHandle nodeHandle, float padding1, float padding2, float padding3, float padding4) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + ArkUI_NumberValue value[] = { { .f32 = padding1 }, { .f32 = padding2 }, { .f32 = padding3 }, { .f32 = padding4 } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_PADDING, &item); + return nodeHandle; +} + +static auto SetSize(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, float width, float height) +{ + ArkUI_NumberValue value[] = { { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_SIZE, &item); + return nodeHandle; +} + +static auto SetColumn(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle) +{ + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetSize(nodeAPI, nodeHandle, SIZE_50, SIZE_50); + return nodeHandle; +} + +static auto SetText(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle) +{ + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_GREEN); + nodeHandle = SetSize(nodeAPI, nodeHandle, 25, 25); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateCaseNodeOne(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row1 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column1 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto column2 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text1 = CreateChildNode(nodeAPI, column1, ARKUI_NODE_TEXT); + auto text2 = CreateChildNode(nodeAPI, column2, ARKUI_NODE_TEXT); + column1 = SetColumn(nodeAPI, column1); + column2 = SetColumn(nodeAPI, column2); + text1 = SetText(nodeAPI, text1); + text2 = SetText(nodeAPI, text2); + column1 = SetPadding(nodeAPI, column1, PARAM_0); + column2 = SetPadding(column2, PARAM_0, PARAM_0, PARAM_0, PARAM_0); +} + +static auto CreateCaseNodeTwo(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row2 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column3 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_COLUMN); + auto column4 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_COLUMN); + auto text3 = CreateChildNode(nodeAPI, column3, ARKUI_NODE_TEXT); + auto text4 = CreateChildNode(nodeAPI, column4, ARKUI_NODE_TEXT); + column3 = SetColumn(nodeAPI, column3); + column4 = SetColumn(nodeAPI, column4); + text3 = SetText(nodeAPI, text3); + text4 = SetText(nodeAPI, text4); + column3 = SetPadding(nodeAPI, column3, SIZE_25); + column4 = SetPadding(column4, SIZE_25, SIZE_25, SIZE_25, SIZE_25); +} + +static auto CreateCaseNodeThree(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row3 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column5 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_COLUMN); + auto column6 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_COLUMN); + auto text5 = CreateChildNode(nodeAPI, column5, ARKUI_NODE_TEXT); + auto text6 = CreateChildNode(nodeAPI, column6, ARKUI_NODE_TEXT); + column5 = SetColumn(nodeAPI, column5); + column6 = SetColumn(nodeAPI, column6); + text5 = SetText(nodeAPI, text5); + text6 = SetText(nodeAPI, text6); + column5 = SetPadding(nodeAPI, column5, SIZE_50); + column6 = SetPadding(column6, SIZE_50, SIZE_50, SIZE_50, SIZE_50); +} + +static auto CreateCaseNodeFour(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row4 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column7 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_COLUMN); + auto column8 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_COLUMN); + auto text7 = CreateChildNode(nodeAPI, column7, ARKUI_NODE_TEXT); + auto text8 = CreateChildNode(nodeAPI, column8, ARKUI_NODE_TEXT); + column7 = SetColumn(nodeAPI, column7); + column8 = SetColumn(nodeAPI, column8); + column7 = SetMargin(nodeAPI, column7, SIZE_25); + column8 = SetMargin(nodeAPI, column8, SIZE_25); + text7 = SetText(nodeAPI, text7); + text8 = SetText(nodeAPI, text8); + column7 = SetPadding(nodeAPI, column7, PARAM_NEGATIVE_25); + column8 = SetPadding(column8, PARAM_NEGATIVE_25, PARAM_NEGATIVE_25, PARAM_NEGATIVE_25, PARAM_NEGATIVE_25); +} + +static auto CreateCaseNodeFive(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row5 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column9 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_COLUMN); + auto column10 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_COLUMN); + auto column11 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_COLUMN); + auto column12 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_COLUMN); + auto text9 = CreateChildNode(nodeAPI, column9, ARKUI_NODE_TEXT); + auto text10 = CreateChildNode(nodeAPI, column10, ARKUI_NODE_TEXT); + auto text11 = CreateChildNode(nodeAPI, column11, ARKUI_NODE_TEXT); + auto text12 = CreateChildNode(nodeAPI, column12, ARKUI_NODE_TEXT); + column9 = SetColumn(nodeAPI, column9); + column10 = SetColumn(nodeAPI, column10); + column11 = SetColumn(nodeAPI, column11); + column12 = SetColumn(nodeAPI, column12); + text9 = SetText(nodeAPI, text9); + text10 = SetText(nodeAPI, text10); + text11 = SetText(nodeAPI, text11); + text12 = SetText(nodeAPI, text12); + column9 = SetPadding(column9, PARAM_NEGATIVE_25, PARAM_0, PARAM_0, PARAM_0); + column10 = SetPadding(column10, PARAM_0, PARAM_NEGATIVE_25, PARAM_0, PARAM_0); + column11 = SetPadding(column11, PARAM_0, PARAM_0, PARAM_NEGATIVE_25, PARAM_0); + column12 = SetPadding(column12, PARAM_0, PARAM_0, PARAM_0, PARAM_NEGATIVE_25); +} + +static auto CreateCaseNodeSix(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row6 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column13 = CreateChildNode(nodeAPI, row6, ARKUI_NODE_COLUMN); + auto column14 = CreateChildNode(nodeAPI, row6, ARKUI_NODE_COLUMN); + auto column15 = CreateChildNode(nodeAPI, row6, ARKUI_NODE_COLUMN); + auto column16 = CreateChildNode(nodeAPI, row6, ARKUI_NODE_COLUMN); + auto text13 = CreateChildNode(nodeAPI, column13, ARKUI_NODE_TEXT); + auto text14 = CreateChildNode(nodeAPI, column14, ARKUI_NODE_TEXT); + auto text15 = CreateChildNode(nodeAPI, column15, ARKUI_NODE_TEXT); + auto text16 = CreateChildNode(nodeAPI, column16, ARKUI_NODE_TEXT); + column13 = SetColumn(nodeAPI, column13); + column14 = SetColumn(nodeAPI, column14); + column15 = SetColumn(nodeAPI, column15); + column16 = SetColumn(nodeAPI, column16); + text13 = SetText(nodeAPI, text13); + text14 = SetText(nodeAPI, text14); + text15 = SetText(nodeAPI, text15); + text16 = SetText(nodeAPI, text16); + column13 = SetPadding(column13, SIZE_25, PARAM_0, PARAM_0, PARAM_0); + column14 = SetPadding(column14, PARAM_0, SIZE_25, PARAM_0, PARAM_0); + column15 = SetPadding(column15, PARAM_0, PARAM_0, SIZE_25, PARAM_0); + column16 = SetPadding(column16, PARAM_0, PARAM_0, PARAM_0, SIZE_25); +} + +static auto CreateCaseNodeSeven(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row7 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column17 = CreateChildNode(nodeAPI, row7, ARKUI_NODE_COLUMN); + auto column18 = CreateChildNode(nodeAPI, row7, ARKUI_NODE_COLUMN); + auto column19 = CreateChildNode(nodeAPI, row7, ARKUI_NODE_COLUMN); + auto column20 = CreateChildNode(nodeAPI, row7, ARKUI_NODE_COLUMN); + auto text17 = CreateChildNode(nodeAPI, column17, ARKUI_NODE_TEXT); + auto text18 = CreateChildNode(nodeAPI, column18, ARKUI_NODE_TEXT); + auto text19 = CreateChildNode(nodeAPI, column19, ARKUI_NODE_TEXT); + auto text20 = CreateChildNode(nodeAPI, column20, ARKUI_NODE_TEXT); + column17 = SetColumn(nodeAPI, column17); + column18 = SetColumn(nodeAPI, column18); + column19 = SetColumn(nodeAPI, column19); + column20 = SetColumn(nodeAPI, column20); + column17 = SetMargin(nodeAPI, column17, SIZE_25); + column18 = SetMargin(nodeAPI, column18, SIZE_25); + column19 = SetMargin(nodeAPI, column19, SIZE_25); + column20 = SetMargin(nodeAPI, column20, SIZE_25); + text17 = SetText(nodeAPI, text17); + text18 = SetText(nodeAPI, text18); + text19 = SetText(nodeAPI, text19); + text20 = SetText(nodeAPI, text20); + column17 = SetPadding(column17, PARAM_NEGATIVE_50, PARAM_0, PARAM_0, PARAM_0); + column18 = SetPadding(column18, PARAM_0, PARAM_NEGATIVE_50, PARAM_0, PARAM_0); + column19 = SetPadding(column19, PARAM_0, PARAM_0, PARAM_NEGATIVE_50, PARAM_0); + column20 = SetPadding(column20, PARAM_0, PARAM_0, PARAM_0, PARAM_NEGATIVE_50); +} + +static auto CreateCaseNodeEight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row8 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column21 = CreateChildNode(nodeAPI, row8, ARKUI_NODE_COLUMN); + auto column22 = CreateChildNode(nodeAPI, row8, ARKUI_NODE_COLUMN); + auto column23 = CreateChildNode(nodeAPI, row8, ARKUI_NODE_COLUMN); + auto column24 = CreateChildNode(nodeAPI, row8, ARKUI_NODE_COLUMN); + auto text21 = CreateChildNode(nodeAPI, column21, ARKUI_NODE_TEXT); + auto text22 = CreateChildNode(nodeAPI, column22, ARKUI_NODE_TEXT); + auto text23 = CreateChildNode(nodeAPI, column23, ARKUI_NODE_TEXT); + auto text24 = CreateChildNode(nodeAPI, column24, ARKUI_NODE_TEXT); + column21 = SetColumn(nodeAPI, column21); + column22 = SetColumn(nodeAPI, column22); + column23 = SetColumn(nodeAPI, column23); + column24 = SetColumn(nodeAPI, column24); + column21 = SetMargin(nodeAPI, column21, SIZE_25); + column22 = SetMargin(nodeAPI, column22, SIZE_25); + column23 = SetMargin(nodeAPI, column23, SIZE_25); + column24 = SetMargin(nodeAPI, column24, SIZE_25); + text21 = SetText(nodeAPI, text21); + text22 = SetText(nodeAPI, text22); + text23 = SetText(nodeAPI, text23); + text24 = SetText(nodeAPI, text24); + column21 = SetPadding(column21, SIZE_50, PARAM_0, PARAM_0, PARAM_0); + column22 = SetPadding(column22, PARAM_0, SIZE_50, PARAM_0, PARAM_0); + column23 = SetPadding(column23, PARAM_0, PARAM_0, SIZE_50, PARAM_0); + column24 = SetPadding(column24, PARAM_0, PARAM_0, PARAM_0, SIZE_50); +} + +static auto CreateCaseNodeNine(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode) +{ + auto row9 = CreateChildNode(nodeAPI, parentNode, ARKUI_NODE_ROW); + auto column25 = CreateChildNode(nodeAPI, row9, ARKUI_NODE_COLUMN); + auto column26 = CreateChildNode(nodeAPI, row9, ARKUI_NODE_COLUMN); + auto text25 = CreateChildNode(nodeAPI, column25, ARKUI_NODE_TEXT); + auto text26 = CreateChildNode(nodeAPI, column26, ARKUI_NODE_TEXT); + column25 = SetColumn(nodeAPI, column25); + column26 = SetColumn(nodeAPI, column26); + text25 = SetText(nodeAPI, text25); + text26 = SetText(nodeAPI, text26); + column25 = SetPadding(column25, SIZE_50, PARAM_0, SIZE_50, PARAM_0); + column26 = SetPadding(column26, SIZE_50, PARAM_0, SIZE_50, PARAM_0); + nodeAPI->resetAttribute(column26, NODE_PADDING); +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + CreateCaseNodeOne(nodeAPI, column); + CreateCaseNodeTwo(nodeAPI, column); + CreateCaseNodeThree(nodeAPI, column); + CreateCaseNodeFour(nodeAPI, column); + CreateCaseNodeFive(nodeAPI, column); + CreateCaseNodeSix(nodeAPI, column); + CreateCaseNodeSeven(nodeAPI, column); + CreateCaseNodeEight(nodeAPI, column); + CreateCaseNodeNine(nodeAPI, column); + return column; +} + +napi_value CommonAttrsPaddingTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsPaddingTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsPaddingTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsPaddingTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_padding_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_padding_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b37f616fe6eb497424ebe2f77ad36ecdb608cf7c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_padding_test.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_PADDING_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_PADDING_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_25 25 +#define SIZE_50 50 +#define PARAM_NEGATIVE_25 (-25) +#define PARAM_NEGATIVE_50 (-50) + +class CommonAttrsPaddingTest { +public: + ~CommonAttrsPaddingTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_PADDING_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rendergroup_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rendergroup_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97db86c1a79f9932c728d0b694e5cc7d4f8f68c2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rendergroup_test.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2024 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 "commonattrs_rendergroup_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, float width, float height, float opacity, uint32_t color) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue opacity_value[] = { { .f32 = opacity } }; + ArkUI_AttributeItem opacity_item = { opacity_value, sizeof(opacity_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_OPACITY, &opacity_item); + + ArkUI_NumberValue background_color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_BACKGROUND_COLOR, &background_color_item); + + return column; +} + +napi_value CommonAttrsRenderGroupTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTranslateTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTranslateTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue justify_value[] = { { .i32 = ARKUI_FLEX_ALIGNMENT_CENTER } }; + ArkUI_AttributeItem justify_item = { justify_value, sizeof(justify_value) / sizeof(ArkUI_NumberValue) }; + auto column1 = CreateChildNode(nodeAPI, 150, 150, 1, COLOR_BLACK); + auto column2 = CreateChildNode(nodeAPI, 100, 100, 0.6, COLOR_WHITE); + auto column3 = CreateChildNode(nodeAPI, 50, 50, 1, COLOR_BLACK); + ArkUI_NumberValue renderGroup_value1[] = { { .i32 = 1 } }; + ArkUI_AttributeItem renderGroup_item1 = { renderGroup_value1, + sizeof(renderGroup_value1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column2, NODE_RENDER_GROUP, &renderGroup_item1); + auto renderGroupAttrs = nodeAPI->getAttribute(column2, NODE_RENDER_GROUP); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsRenderGroupTest", "renderGroupAttrs: %{public}d", + renderGroupAttrs->value[0].i32); + nodeAPI->setAttribute(column1, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column2, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column1, NODE_MARGIN, &margin_item); + nodeAPI->addChild(column1, column2); + nodeAPI->addChild(column2, column3); + auto column4 = CreateChildNode(nodeAPI, 150, 150, 1, COLOR_BLACK); + auto column5 = CreateChildNode(nodeAPI, 100, 100, 0.6, COLOR_WHITE); + auto column6 = CreateChildNode(nodeAPI, 50, 50, 1, COLOR_BLACK); + ArkUI_NumberValue renderGroup_value2[] = { { .i32 = 1 } }; + ArkUI_AttributeItem renderGroup_item2 = { renderGroup_value2, + sizeof(renderGroup_value2) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column5, NODE_RENDER_GROUP, &renderGroup_item2); + nodeAPI->resetAttribute(column5, NODE_RENDER_GROUP); + nodeAPI->setAttribute(column4, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column5, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column4, NODE_MARGIN, &margin_item); + nodeAPI->addChild(column4, column5); + nodeAPI->addChild(column5, column6); + auto column7 = CreateChildNode(nodeAPI, 150, 150, 1, COLOR_BLACK); + auto column8 = CreateChildNode(nodeAPI, 100, 100, 0.6, COLOR_WHITE); + auto column9 = CreateChildNode(nodeAPI, 50, 50, 1, COLOR_BLACK); + ArkUI_NumberValue renderGroup_value3[] = { { .i32 = 0 } }; + ArkUI_AttributeItem renderGroup_item3 = { renderGroup_value3, + sizeof(renderGroup_value3) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column8, NODE_RENDER_GROUP, &renderGroup_item3); + nodeAPI->setAttribute(column7, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column8, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column7, NODE_MARGIN, &margin_item); + nodeAPI->addChild(column7, column8); + nodeAPI->addChild(column8, column9); + auto column10 = CreateChildNode(nodeAPI, 150, 150, 1, COLOR_BLACK); + auto column11 = CreateChildNode(nodeAPI, 100, 100, 0.6, COLOR_WHITE); + auto column12 = CreateChildNode(nodeAPI, 50, 50, 1, COLOR_BLACK); + ArkUI_NumberValue renderGroup_value4[] = { { .i32 = -1 } }; + ArkUI_AttributeItem renderGroup_item4 = { renderGroup_value4, + sizeof(renderGroup_value4) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column11, NODE_RENDER_GROUP, &renderGroup_item4); + nodeAPI->setAttribute(column10, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column11, NODE_COLUMN_JUSTIFY_CONTENT, &justify_item); + nodeAPI->setAttribute(column10, NODE_MARGIN, &margin_item); + nodeAPI->addChild(column10, column11); + nodeAPI->addChild(column11, column12); + + auto columnP1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto columnP2 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(columnP1, column1); + nodeAPI->addChild(columnP1, column4); + nodeAPI->addChild(columnP2, column7); + nodeAPI->addChild(columnP2, column10); + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + nodeAPI->addChild(row, columnP1); + nodeAPI->addChild(row, columnP2); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), row) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTranslateTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rendergroup_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rendergroup_test.h new file mode 100644 index 0000000000000000000000000000000000000000..0bf57d52d62de316f192302f9f685defb630cafb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rendergroup_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_RENDERGROUP_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_RENDERGROUP_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsRenderGroupTest { +public: + ~CommonAttrsRenderGroupTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_RENDERGROUP_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_responseregion_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_responseregion_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a0a15036af25c8c073ad6307edf706128a31525 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_responseregion_test.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2024 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 "commonattrs_responseregion_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateButtonWithResponseRegion( + const std::string& id, const std::vector& values) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", "CreateButtonWithResponseRegion"); + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto button = std::make_shared(); + button->SetWidth(150); + button->SetHeight(75); + button->SetId(id); + std::vector responseregion_values; + for (auto value : values) { + responseregion_values.push_back({ .f32 = value }); + } + ArkUI_AttributeItem responseregion_item = { responseregion_values.data(), sizeof(responseregion_values) }; + button->setAttribute(NODE_RESPONSE_REGION, &responseregion_item); + nodeAPI->registerNodeEvent(button->GetComponent(), NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + + return button; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandle = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + // 事件回调时,修改组件背景色 + if (eventId == ON_CLICK_EVENT_ID) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + return; + } +} + +static void AddResponseRegionChild(GridComponent* grid) +{ + grid->AddChild(CreateButtonWithResponseRegion("BTN1", { 0, 0, 50, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN2", { 0, 0, 50, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN3", { 0, 0, 50, 100, 50, 0, 50, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN4", { 0, 0, 50, 100, 50, 0, 50, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN5", { 0, 0, 50, 100, 0, 0, 100, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN6", { 0, 0, 0, 0 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN7", { 0, 0, 0, 0 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN8", { -50, 0, 100, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN9", { 100, 0, 200, 200 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN10", { 0, 0, 0, 0 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN11", { 0, 0, 300, 100 })); + grid->AddChild(CreateButtonWithResponseRegion("BTN12", { 0, 0, 100, 100 })); +} + +napi_value CommonAttrsResponseRegionTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto grid = new GridComponent(); + grid->SetGridColumnsGap(20); + grid->SetGridRowsGap(30); + AddResponseRegionChild(grid); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), grid->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsResponseRegionTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_responseregion_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_responseregion_test.h new file mode 100644 index 0000000000000000000000000000000000000000..a0908628b657cf7967eddd7c26693356d80ea0f4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_responseregion_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_RESPONSE_REGION_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_RESPONSE_REGION_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "button_component.h" +#include "grid_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsResponseRegionTest { +public: + ~CommonAttrsResponseRegionTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_RESPONSE_REGION_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rotate_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rotate_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af059b9818fa7be9286ac1de19e31688e2de0672 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rotate_test.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 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 "commonattrs_rotate_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateChildNode(float x, float y, float z, float angle, float perspective) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_RED } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue rotateValue[] = { { .f32 = x }, { .f32 = y }, { .f32 = z }, { .f32 = angle }, + { .f32 = perspective } }; + ArkUI_AttributeItem rotateItem = { rotateValue, sizeof(rotateValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ROTATE, &rotateItem); + + return nodeHandle; +} + +napi_value CommonAttrsRotateTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsRotateTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsRotateTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column and set rotate + auto column1 = CreateChildNode(0, 0, 0, 0, 0); + auto column2 = CreateChildNode(1, 1, 1, 45, 0); + auto column3 = CreateChildNode(1, 1, 1, -45, 0); + auto column4 = CreateChildNode(-1, -1, -1, 45, 0); + auto column5 = CreateChildNode(-1, -1, -1, -45, 0); + auto column6 = CreateChildNode(1, -1, 1, 45, 10); + auto column7 = CreateChildNode(-1, 1, -1, 45, -10); + auto column8 = CreateChildNode({}, {}, {}, 45, {}); + auto column9 = CreateChildNode(0, 0, 1, 45, 0); + nodeAPI->resetAttribute(column9, NODE_ROTATE); + + // add child + auto columnP1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto columnP2 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(columnP1, column1); + nodeAPI->addChild(columnP1, column2); + nodeAPI->addChild(columnP1, column3); + nodeAPI->addChild(columnP1, column4); + nodeAPI->addChild(columnP2, column5); + nodeAPI->addChild(columnP2, column6); + nodeAPI->addChild(columnP2, column7); + nodeAPI->addChild(columnP2, column8); + nodeAPI->addChild(columnP2, column9); + + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + nodeAPI->addChild(row, columnP1); + nodeAPI->addChild(row, columnP2); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), row) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsRotateTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rotate_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rotate_test.h new file mode 100644 index 0000000000000000000000000000000000000000..c64bf7b7eae0eb5f9d2f60501f87c85895fc11f0 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_rotate_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ROTATE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ROTATE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsRotateTest { +public: + ~CommonAttrsRotateTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ROTATE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_saturate_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_saturate_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f41f256812bbb21c5c643a7c5d4206dcbd944c8f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_saturate_test.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 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 "commonattrs_saturate_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateImageWithSaturate(float saturate) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsSaturateTest", "CreateImageNode"); + + auto image = std::make_shared(ARKUI_NODE_IMAGE); + image->SetWidth(80); + image->SetHeight(80); + image->SetMargin(DEFAULT_MARGIN); + image->SetBackgroundImage("resource://media/icon.png"); + image->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + ArkUI_NumberValue saturate_value[] = { { .f32 = saturate } }; + ArkUI_AttributeItem saturate_item = { saturate_value, sizeof(saturate_value) / sizeof(ArkUI_NumberValue) }; + image->setAttribute(NODE_SATURATION, &saturate_item); + + return image; +} + +napi_value CommonAttrsSaturateTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsSaturateTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsSaturateTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + auto image1 = CreateImageWithSaturate(0); + auto image2 = CreateImageWithSaturate(1); + auto image3 = CreateImageWithSaturate(5); + auto image4 = CreateImageWithSaturate(30); + auto image5 = CreateImageWithSaturate(51); + auto image6 = CreateImageWithSaturate(-1); + auto image7 = CreateImageWithSaturate(30); + image7->resetAttribute(NODE_SATURATION); + column->AddChild(image1); + column->AddChild(image2); + column->AddChild(image3); + column->AddChild(image4); + column->AddChild(image5); + column->AddChild(image6); + column->AddChild(image7); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsSaturateTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_saturate_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_saturate_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8839725ecc5ecb29612729df8406146c6e3b9b1b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_saturate_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_SATURATE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_SATURATE_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsSaturateTest { +public: + ~CommonAttrsSaturateTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_SATURATE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_size_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_size_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..caf91a9d1e13c1e776d894983c1113a9dd2d203f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_size_test.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2024 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 "commonattrs_size_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetOutlineWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width }, { .f32 = width }, { .f32 = width }, { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_OUTLINE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetSize(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, float width, float height) +{ + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_10); + nodeHandle = SetOutlineWidth(nodeAPI, nodeHandle, PARAM_5); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_YELLOW); + ArkUI_NumberValue value[] = { { .f32 = width }, { .f32 = height } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_SIZE, &item); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateCaseNodeOne(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle column) +{ + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto column1 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text1 = CreateChildNode(nodeAPI, column1, ARKUI_NODE_TEXT); + auto column2 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text2 = CreateChildNode(nodeAPI, column2, ARKUI_NODE_TEXT); + auto column3 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text3 = CreateChildNode(nodeAPI, column3, ARKUI_NODE_TEXT); + auto column4 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text4 = CreateChildNode(nodeAPI, column4, ARKUI_NODE_TEXT); + auto column5 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text5 = CreateChildNode(nodeAPI, column5, ARKUI_NODE_TEXT); + auto column6 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text6 = CreateChildNode(nodeAPI, column6, ARKUI_NODE_TEXT); + auto column7 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text7 = CreateChildNode(nodeAPI, column7, ARKUI_NODE_TEXT); + auto column8 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text8 = CreateChildNode(nodeAPI, column8, ARKUI_NODE_TEXT); + auto column9 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_COLUMN); + auto text9 = CreateChildNode(nodeAPI, column9, ARKUI_NODE_TEXT); + row1 = SetBackgroundColor(nodeAPI, row1, COLOR_GREEN); + column1 = SetBackgroundColor(nodeAPI, column1, COLOR_BLUE); + text1 = SetSize(nodeAPI, text1, SIZE_30, SIZE_30); + column2 = SetBackgroundColor(nodeAPI, column2, COLOR_PURPLE); + text2 = SetSize(nodeAPI, text2, SIZE_30, PARAM_0); + column3 = SetBackgroundColor(nodeAPI, column3, COLOR_BLUE); + text3 = SetSize(nodeAPI, text3, SIZE_30, PARAM_NEGATIVE_100); + column4 = SetBackgroundColor(nodeAPI, column4, COLOR_PURPLE); + text4 = SetSize(nodeAPI, text4, PARAM_0, SIZE_30); + column5 = SetBackgroundColor(nodeAPI, column5, COLOR_BLUE); + text5 = SetSize(nodeAPI, text5, PARAM_0, PARAM_0); + column6 = SetBackgroundColor(nodeAPI, column6, COLOR_PURPLE); + text6 = SetSize(nodeAPI, text6, PARAM_0, PARAM_NEGATIVE_100); + column7 = SetBackgroundColor(nodeAPI, column7, COLOR_BLUE); + text7 = SetSize(nodeAPI, text7, PARAM_NEGATIVE_100, SIZE_30); + column8 = SetBackgroundColor(nodeAPI, column8, COLOR_PURPLE); + text8 = SetSize(nodeAPI, text8, PARAM_NEGATIVE_100, PARAM_0); + column9 = SetBackgroundColor(nodeAPI, column9, COLOR_BLUE); + text9 = SetSize(nodeAPI, text9, PARAM_NEGATIVE_100, PARAM_NEGATIVE_100); +} + +static auto CreateCaseNodeTwo(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle column) +{ + auto column10 = CreateChildNode(nodeAPI, column, ARKUI_NODE_COLUMN); + auto text10 = CreateChildNode(nodeAPI, column10, ARKUI_NODE_TEXT); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto text11 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_TEXT); + auto column12 = CreateChildNode(nodeAPI, column, ARKUI_NODE_COLUMN); + auto text12 = CreateChildNode(nodeAPI, column12, ARKUI_NODE_TEXT); + column10 = SetBackgroundColor(nodeAPI, column10, COLOR_PURPLE); + text10 = SetSize(nodeAPI, text10, SIZE_30, SIZE_300); + nodeAPI->resetAttribute(text10, NODE_SIZE); + row2 = SetBackgroundColor(nodeAPI, row2, COLOR_RED); + text11 = SetSize(nodeAPI, text11, SIZE_2000, SIZE_30); + column12 = SetBackgroundColor(nodeAPI, column12, COLOR_GREEN); + text12 = SetSize(nodeAPI, text12, SIZE_30, SIZE_2000); +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + CreateCaseNodeOne(nodeAPI, column); + CreateCaseNodeTwo(nodeAPI, column); + return column; +} + +napi_value CommonAttrsSizeTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsSizeTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsSizeTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsSizeTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_size_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_size_test.h new file mode 100644 index 0000000000000000000000000000000000000000..e4c65af1309e48d5f413378160f5146b7a26b002 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_size_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_SIZE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_SIZE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_2000 2000 + +class CommonAttrsSizeTest { +public: + ~CommonAttrsSizeTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_SIZE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_touchable_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_touchable_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..587b0b26929930ab0bf1e99e7c4252f3325070f3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_touchable_test.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2024 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 "commonattrs_touchable_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +using namespace std; +static ArkUI_NodeHandle text; + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t hitTestMode, const char* id) +{ + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + ArkUI_NumberValue hitTestMode_value[] = { { .i32 = hitTestMode } }; + ArkUI_AttributeItem hitTestMode_item = { hitTestMode_value, + sizeof(hitTestMode_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_HIT_TEST_BEHAVIOR, &hitTestMode_item); + + ArkUI_NumberValue id_value[] = {}; + ArkUI_AttributeItem id_item = { id_value, sizeof(id_value) / sizeof(ArkUI_NumberValue) }; + id_item.string = id; + nodeAPI->setAttribute(button, NODE_ID, &id_item); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_100 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(button, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 40 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_RED } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(button, NODE_BACKGROUND_COLOR, &background_color_item); + + nodeAPI->registerNodeEvent(button, NODE_ON_TOUCH_INTERCEPT, ON_TOUCH_EVENT_ID, nullptr); + + return button; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ButtonOnClickTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ButtonOnClickTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ButtonOnClickTest", "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + if (eventId == ON_TOUCH_EVENT_ID) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + return; + } +} + +napi_value CommonAttrsTouchAbleTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTouchAbleTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTouchAbleTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto button1 = CreateChildNode(nodeAPI, ARKUI_HIT_TEST_MODE_DEFAULT, "button1"); + auto button2 = CreateChildNode(nodeAPI, ARKUI_HIT_TEST_MODE_BLOCK, "button2"); + auto button3 = CreateChildNode(nodeAPI, ARKUI_HIT_TEST_MODE_TRANSPARENT, "button3"); + auto button4 = CreateChildNode(nodeAPI, ARKUI_HIT_TEST_MODE_NONE, "button4"); + auto button5 = CreateChildNode(nodeAPI, -1, "button5"); + auto button6 = CreateChildNode(nodeAPI, 4, "button6"); + auto button7 = CreateChildNode(nodeAPI, ARKUI_HIT_TEST_MODE_DEFAULT, "button7"); + nodeAPI->resetAttribute(button7, NODE_HIT_TEST_BEHAVIOR); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + auto columnP1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto columnP2 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + + nodeAPI->addChild(columnP1, button1); + nodeAPI->addChild(columnP1, button2); + nodeAPI->addChild(columnP1, button3); + nodeAPI->addChild(columnP1, button4); + nodeAPI->addChild(columnP2, button5); + nodeAPI->addChild(columnP2, button6); + nodeAPI->addChild(columnP2, button7); + nodeAPI->addChild(row, columnP1); + nodeAPI->addChild(row, columnP2); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), row) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTouchAbleTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_touchable_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_touchable_test.h new file mode 100644 index 0000000000000000000000000000000000000000..79daa399595e03c6ed48a7fa2ac12e4a348bb37e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_touchable_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_TOUCHABLE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_TOUCHABLE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsTouchAbleTest { +public: + ~CommonAttrsTouchAbleTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_TRANSFORM_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_translate_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_translate_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a49c72332f71c5a227656b1a33576e1fa32365d3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_translate_test.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2024 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 "commonattrs_translate_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, float x, float y, float z) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 60 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 60 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_RED } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue translateValue[] = { { .f32 = x }, { .f32 = y }, { .f32 = z } }; + ArkUI_AttributeItem translateItem = { translateValue, sizeof(translateValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TRANSLATE, &translateItem); + + return nodeHandle; +} + +static auto CreateChildNode1(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 60 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 60 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_RED } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + + ArkUI_NumberValue translateValue[] = { {}, {}, {} }; + ArkUI_AttributeItem translateItem = { translateValue, sizeof(translateValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TRANSLATE, &translateItem); + + return nodeHandle; +} + +static auto CreateColumnNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + ArkUI_NumberValue width_value[] = { { .f32 = 230 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 230 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem borderWidth_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &borderWidth_item); + + return nodeHandle; +} + +static auto CreateRowNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_ROW); + + ArkUI_NumberValue width_value[] = { { .f32 = 230 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 230 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue borderWidth_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem borderWidth_item = { borderWidth_value, + sizeof(borderWidth_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &borderWidth_item); + + return nodeHandle; +} + +napi_value CommonAttrsTranslateTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTranslateTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTranslateTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column and set translate + auto column1 = CreateChildNode(nodeAPI, 0, 0, 0); + auto column2 = CreateChildNode(nodeAPI, 60, 0, 0); + auto column3 = CreateChildNode(nodeAPI, -60, 0, 0); + auto column4 = CreateChildNode(nodeAPI, 0, 0, 0); + auto column5 = CreateChildNode(nodeAPI, 0, 60, 0); + auto column6 = CreateChildNode(nodeAPI, 0, -60, 0); + auto column7 = CreateChildNode(nodeAPI, 0, 0, 0); + auto column8 = CreateChildNode(nodeAPI, 0, 0, 100); + auto column9 = CreateChildNode(nodeAPI, 0, 0, -10); + auto column10 = CreateChildNode1(nodeAPI); + auto column11 = CreateChildNode(nodeAPI, 60, 60, 60); + auto column12 = CreateChildNode(nodeAPI, 400, 400, 400); + auto column13 = CreateChildNode(nodeAPI, -60, 40, 60); + auto column14 = CreateChildNode(nodeAPI, -60, 80, -60); + auto column15 = CreateChildNode(nodeAPI, 60, -80, 60); + auto column16 = CreateChildNode(nodeAPI, 60, -40, -60); + auto column17 = CreateChildNode(nodeAPI, 60, 40, 60); + auto column18 = CreateChildNode(nodeAPI, 60, 80, -60); + auto column19 = CreateChildNode(nodeAPI, -60, -80, 60); + auto column20 = CreateChildNode(nodeAPI, -60, -40, -60); + + // add child + auto columnP1 = CreateColumnNode(nodeAPI); + auto rowP2 = CreateRowNode(nodeAPI); + auto columnP3 = CreateColumnNode(nodeAPI); + auto columnP4 = CreateColumnNode(nodeAPI); + auto columnP5 = CreateColumnNode(nodeAPI); + auto columnP6 = CreateColumnNode(nodeAPI); + auto ColumnP1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto ColumnP2 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + nodeAPI->addChild(columnP1, column1); + nodeAPI->addChild(columnP1, column2); + nodeAPI->addChild(columnP1, column3); + nodeAPI->addChild(rowP2, column4); + nodeAPI->addChild(rowP2, column5); + nodeAPI->addChild(rowP2, column6); + nodeAPI->addChild(columnP3, column7); + nodeAPI->addChild(columnP3, column8); + nodeAPI->addChild(columnP3, column9); + nodeAPI->resetAttribute(column11, NODE_TRANSLATE); + nodeAPI->addChild(columnP4, column10); + nodeAPI->addChild(columnP4, column11); + nodeAPI->addChild(columnP4, column12); + nodeAPI->addChild(columnP5, column13); + nodeAPI->addChild(columnP5, column14); + nodeAPI->addChild(columnP5, column15); + nodeAPI->addChild(columnP5, column16); + nodeAPI->addChild(columnP6, column17); + nodeAPI->addChild(columnP6, column18); + nodeAPI->addChild(columnP6, column19); + nodeAPI->addChild(columnP6, column20); + nodeAPI->addChild(ColumnP1, columnP1); + nodeAPI->addChild(ColumnP1, rowP2); + nodeAPI->addChild(ColumnP1, columnP3); + nodeAPI->addChild(ColumnP2, columnP4); + nodeAPI->addChild(ColumnP2, columnP5); + nodeAPI->addChild(ColumnP2, columnP6); + nodeAPI->addChild(row, ColumnP1); + nodeAPI->addChild(row, ColumnP2); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), row) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsTranslateTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_translate_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_translate_test.h new file mode 100644 index 0000000000000000000000000000000000000000..cc690458d79d6ad246b9cb387401e1e78d777554 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_translate_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_TRANSLATE_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_TRANSLATE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsTranslateTest { +public: + ~CommonAttrsTranslateTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_TRANSLATE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_visibility_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_visibility_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..32bef49c6bb45051c0b47c6616b871adaaa84bcd --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_visibility_test.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 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 "commonattrs_visibility_test.h" + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +std::shared_ptr CreateChildWithVisibility(int32_t visibility) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsVisibilityTest", "CreateChildWithVisibility"); + + auto column = std::make_shared(); + column->SetWidth(100); + column->SetHeight(100); + column->SetMargin(DEFAULT_MARGIN); + column->SetBackgroundImage("resource://media/icon.png"); + column->SetBackgroundImageSizeWithStyle(ARKUI_IMAGE_SIZE_COVER); + if (visibility != PARAM_NEGATIVE_100) { + column->SetVisibility(visibility); + } + + return column; +} + +napi_value CommonAttrsVisibilityTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonAttrsVisibilityTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsVisibilityTest", "GetContext env or info is null"); + return nullptr; + } + + auto column = new ColumnComponent(); + auto column1 = CreateChildWithVisibility(ARKUI_VISIBILITY_VISIBLE); + auto column2 = CreateChildWithVisibility(ARKUI_VISIBILITY_HIDDEN); + auto column3 = CreateChildWithVisibility(ARKUI_VISIBILITY_NONE); + auto column4 = CreateChildWithVisibility(-1); + auto column5 = CreateChildWithVisibility(3); + auto column6 = CreateChildWithVisibility(ARKUI_VISIBILITY_HIDDEN); + auto column7 = CreateChildWithVisibility(PARAM_NEGATIVE_100); + column6->resetAttribute(NODE_VISIBILITY); + column->AddChild(column1); + column->AddChild(column2); + column->AddChild(column3); + column->AddChild(column4); + column->AddChild(column5); + column->AddChild(column6); + column->AddChild(column7); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), column->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsVisibilityTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_visibility_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_visibility_test.h new file mode 100644 index 0000000000000000000000000000000000000000..0b2db76b6b1ec5002e36dfdc34f69fd1d3007021 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_visibility_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_VISIBILITY_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_VISIBILITY_TEST_H + +#include +#include +#include + +#include "../common/common.h" +#include "column_component.h" + +namespace ArkUICApiDemo { + +class CommonAttrsVisibilityTest { +public: + ~CommonAttrsVisibilityTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_VISIBILITY_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_zindex_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_zindex_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f102b1d1d09eb0feb6ef0df418523b69421534fd --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_zindex_test.cpp @@ -0,0 +1,290 @@ + +/* + * Copyright (c) 2024 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 "commonattrs_zindex_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetZIndex(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float zIndex) +{ + ArkUI_NumberValue zIndex_value[] = { { .f32 = zIndex } }; + ArkUI_AttributeItem zIndex_item = { zIndex_value, sizeof(zIndex_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_Z_INDEX, &zIndex_item); + return nodeHandle; +} + +static auto SetOther(ArkUI_NodeHandle& nodeHandle, float width, float height, uint32_t backgroundColor, char* id) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + nodeHandle = SetWidth(nodeAPI, nodeHandle, width); + nodeHandle = SetHeight(nodeAPI, nodeHandle, height); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, backgroundColor); + nodeHandle = SetId(nodeAPI, nodeHandle, id); + return nodeHandle; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + if (eventId == ON_CLICK_EVENT_ID) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_BLACK } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + } +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static auto CreateParentNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto stack1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_STACK); + auto text1 = CreateChildNode(nodeAPI, stack1, ARKUI_NODE_TEXT); + auto text2 = CreateChildNode(nodeAPI, stack1, ARKUI_NODE_TEXT); + auto text3 = CreateChildNode(nodeAPI, stack1, ARKUI_NODE_TEXT); + auto stack2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_STACK); + auto text4 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_TEXT); + auto text5 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_TEXT); + auto text6 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_TEXT); + auto text7 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_TEXT); + auto stack3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_STACK); + auto text8 = CreateChildNode(nodeAPI, stack3, ARKUI_NODE_TEXT); + auto text9 = CreateChildNode(nodeAPI, stack3, ARKUI_NODE_TEXT); + auto text10 = CreateChildNode(nodeAPI, stack3, ARKUI_NODE_TEXT); + + stack1 = SetOther(stack1, SIZE_300, SIZE_300, COLOR_RED, "stack1"); + text1 = SetOther(text1, SIZE_250, SIZE_250, COLOR_GREEN, "text1"); + text2 = SetOther(text2, SIZE_200, SIZE_200, COLOR_BLUE, "text2"); + text3 = SetOther(text3, SIZE_150, SIZE_150, COLOR_YELLOW, "text3"); + stack2 = SetOther(stack1, SIZE_300, SIZE_300, COLOR_RED, "stack2"); + text4 = SetOther(text4, SIZE_150, SIZE_150, COLOR_GREEN, "text4"); + text5 = SetOther(text5, SIZE_200, SIZE_200, COLOR_BLUE, "text5"); + text6 = SetOther(text6, SIZE_100, SIZE_100, COLOR_YELLOW, "text6"); + text7 = SetOther(text7, SIZE_250, SIZE_250, COLOR_PURPLE, "text7"); + stack3 = SetOther(stack3, SIZE_150, SIZE_150, COLOR_RED, "stack3"); + text8 = SetOther(text8, SIZE_50, SIZE_150, COLOR_GREEN, "text8"); + text9 = SetOther(text9, SIZE_100, SIZE_100, COLOR_BLUE, "text9"); + text10 = SetOther(text10, SIZE_150, SIZE_50, COLOR_YELLOW, "text10"); + text1 = SetZIndex(nodeAPI, text1, PARAM_0); + text2 = SetZIndex(nodeAPI, text2, PARAM_1); + text3 = SetZIndex(nodeAPI, text3, PARAM_2); + text4 = SetZIndex(nodeAPI, text4, PARAM_2); + text5 = SetZIndex(nodeAPI, text5, PARAM_0); + text6 = SetZIndex(nodeAPI, text6, SIZE_300); + text7 = SetZIndex(nodeAPI, text7, PARAM_NEGATIVE_1); + text8 = SetZIndex(nodeAPI, text8, PARAM_2); + text9 = SetZIndex(nodeAPI, text9, PARAM_1); + text10 = SetZIndex(nodeAPI, text10, PARAM_0); + nodeAPI->resetAttribute(text8, NODE_Z_INDEX); + nodeAPI->resetAttribute(text9, NODE_Z_INDEX); + nodeAPI->resetAttribute(text10, NODE_Z_INDEX); + return column; +} + +napi_value CommonAttrsZIndexTest::CreateNativeNodePage1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", "CreateNativeNodePage1"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = CreateParentNode(nodeAPI); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsZIndexTest::CreateNativeNodePage2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", "CreateNativeNodePage2"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto stack1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_STACK); + auto button1 = CreateChildNode(nodeAPI, stack1, ARKUI_NODE_BUTTON); + auto button2 = CreateChildNode(nodeAPI, stack1, ARKUI_NODE_BUTTON); + auto button3 = CreateChildNode(nodeAPI, stack1, ARKUI_NODE_BUTTON); + stack1 = SetOther(stack1, SIZE_400, SIZE_400, COLOR_RED, "stack1"); + button1 = SetOther(button1, SIZE_300, SIZE_300, COLOR_YELLOW, "button1"); + button2 = SetOther(button2, SIZE_200, SIZE_200, COLOR_BLUE, "button2"); + button3 = SetOther(button3, SIZE_100, SIZE_100, COLOR_GREEN, "button3"); + nodeAPI->registerNodeEvent(button1, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(button2, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(button3, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value CommonAttrsZIndexTest::CreateNativeNodePage3(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", "CreateNativeNodePage3"); + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto stack2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_STACK); + auto button4 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_BUTTON); + auto button5 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_BUTTON); + auto button6 = CreateChildNode(nodeAPI, stack2, ARKUI_NODE_BUTTON); + stack2 = SetOther(stack2, SIZE_400, SIZE_400, COLOR_RED, "stack2"); + button4 = SetOther(button4, SIZE_100, SIZE_100, COLOR_YELLOW, "button4"); + button5 = SetOther(button5, SIZE_200, SIZE_200, COLOR_BLUE, "button5"); + button6 = SetOther(button6, SIZE_300, SIZE_300, COLOR_GREEN, "button6"); + button4 = SetZIndex(nodeAPI, button4, PARAM_3); + button5 = SetZIndex(nodeAPI, button5, PARAM_2); + button6 = SetZIndex(nodeAPI, button6, PARAM_1); + nodeAPI->registerNodeEvent(button4, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(button5, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(button6, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonAttrsZIndexTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_zindex_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_zindex_test.h new file mode 100644 index 0000000000000000000000000000000000000000..fb85c48c30c031cbb0e61a2e1d53d1138026d720 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/commonattrs/commonattrs_zindex_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMMONATTRS_ZINDEX_TEST_H +#define ARKUI_CAPI_DEMO_COMMONATTRS_ZINDEX_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class CommonAttrsZIndexTest { +public: + ~CommonAttrsZIndexTest(); + static napi_value CreateNativeNodePage1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage2(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage3(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMONATTRS_ZINDEX_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1210d977110c439f92959be591b2d6278a698ec5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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 "button_component.h" + +namespace ArkUICApiDemo { + +void ButtonComponent::SetLable(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + _nodeAPI->setAttribute(_component, NODE_BUTTON_LABEL, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h new file mode 100644 index 0000000000000000000000000000000000000000..2873acfb4be6f6642f3e44532ae1e4d1e0366214 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H +#define ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ButtonComponent : public Component { +public: + ButtonComponent() : Component(ARKUI_NODE_BUTTON) {} + explicit ButtonComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetLable(const std::string& content); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h new file mode 100644 index 0000000000000000000000000000000000000000..b06726b2d300307e8277f258544672d7d49b84d5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H +#define ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ColumnComponent : public Component { +public: + ColumnComponent() : Component(ARKUI_NODE_COLUMN) {} + explicit ColumnComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetAlignItems(int32_t verticalAlign) + { + ArkUI_NumberValue value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_COLUMN_ALIGN_ITEMS, &item); + } + void SetJustifyContent(int32_t flexAlign) + { + ArkUI_NumberValue value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_COLUMN_JUSTIFY_CONTENT, &item); + } +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1363b989fa44240c3e6d8dd1ddcbd2fc2a80bce6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2024 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 "component.h" + +#include +#include + +namespace ArkUICApiDemo { + +Component::Component(ArkUI_NodeType type) +{ + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + _component = _nodeAPI->createNode(type); + _nodeAPI->setUserData(_component, this); + _nodeAPI->addNodeEventReceiver(_component, Component::NodeEventReceiver); +} + +Component::Component(ArkUI_NodeHandle handle) +{ + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + _component = handle; + _nodeAPI->setUserData(_component, this); + _nodeAPI->addNodeEventReceiver(_component, Component::NodeEventReceiver); + + int32_t count = _nodeAPI->getTotalChildCount(_component); + for (int32_t i = 0; i < count; i++) { + auto temp = _nodeAPI->getChildAt(_component, i); + children_.emplace_back(std::make_shared(temp)); + } +} + +int32_t Component::setAttribute(ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* item) +{ + return _nodeAPI->setAttribute(_component, attribute, item); +} + +const ArkUI_AttributeItem* Component::getAttribute(ArkUI_NodeAttributeType attribute) +{ + return _nodeAPI->getAttribute(_component, attribute); +} + +int32_t Component::resetAttribute(ArkUI_NodeAttributeType attribute) +{ + return _nodeAPI->resetAttribute(_component, attribute); +} + +void Component::SetWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WIDTH, &item); +} +void Component::SetPercentWidth(float percent) +{ + ArkUI_NumberValue value[] = { { .f32 = percent } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WIDTH_PERCENT, &item); +} +void Component::SetHeight(float height) +{ + ArkUI_NumberValue value[] = { { .f32 = height } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_HEIGHT, &item); +} +void Component::SetPercentHeight(float percent) +{ + ArkUI_NumberValue value[] = { { .f32 = percent } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_HEIGHT_PERCENT, &item); +} +void Component::SetBackgroundColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_COLOR, &item); +} +void Component::SetBackgroundImage(const std::string& backgroundImage) +{ + ArkUI_AttributeItem item = { nullptr, 0, backgroundImage.c_str() }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_IMAGE, &item); +} +void Component::SetBackgroundImageSizeWithStyle(int32_t imageSize) +{ + ArkUI_NumberValue value[] = { { .i32 = imageSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_IMAGE_SIZE_WITH_STYLE, &item); +} +void Component::SetBorderRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) +{ + ArkUI_NumberValue value[] = { { .f32 = topLeft }, { .f32 = topRight }, { .f32 = bottomLeft }, + { .f32 = bottomRight } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_RADIUS, &item); +} + +void Component::SetPadding(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_PADDING, &item); +} + +void Component::SetPaddingPercent(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_PADDING_PERCENT, &item); +} + +void Component::SetMargin(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN, &item); +} +void Component::SetMargin(float margin) +{ + ArkUI_NumberValue value[] = { { .f32 = margin }, { .f32 = margin }, { .f32 = margin }, { .f32 = margin } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN, &item); +} + +void Component::SetMarginPercent(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN_PERCENT, &item); +} + +void Component::SetEnabled(int32_t enable) +{ + ArkUI_NumberValue value[] = { { .i32 = enable } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ENABLED, &item); +} + +void Component::SetAlign(int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ALIGNMENT, &item); +} + +void Component::SetAlignRules(ArkUI_AlignmentRuleOption* option) +{ + ArkUI_AttributeItem item = { .object = option }; + _nodeAPI->setAttribute(_component, NODE_ALIGN_RULES, &item); +} + +void Component::SetAlignSelf(int32_t value) +{ + ArkUI_NumberValue val[] = { { .i32 = value } }; + ArkUI_AttributeItem item = { val, 1 }; + _nodeAPI->setAttribute(_component, NODE_ALIGN_SELF, &item); +} + +void Component::SetOpacity(float opacity) +{ + ArkUI_NumberValue value[] = { { .f32 = opacity } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_OPACITY, &item); +} + +void Component::SetBorderWidth(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_WIDTH, &item); +} + +void Component::SetBorderWidth(float borderWidth) +{ + ArkUI_NumberValue value[] = { { .f32 = borderWidth }, { .f32 = borderWidth }, { .f32 = borderWidth }, + { .f32 = borderWidth } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_WIDTH, &item); +} + +void Component::SetBorderColor(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left) +{ + ArkUI_NumberValue value[] = { { .u32 = top }, { .u32 = right }, { .u32 = bottom }, { .u32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_COLOR, &item); +} + +void Component::SetBorderStyle(int32_t top, int32_t right, int32_t bottom, int32_t left) +{ + ArkUI_NumberValue value[] = { { .i32 = top }, { .i32 = right }, { .i32 = bottom }, { .i32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_STYLE, &item); +} + +void Component::SetVisibility(int32_t visibility) +{ + ArkUI_NumberValue value[] = { { .i32 = visibility } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_VISIBILITY, &item); +} +void Component::SetId(const std::string& id) +{ + ArkUI_AttributeItem item = { nullptr, 0, id.c_str() }; + _nodeAPI->setAttribute(_component, NODE_ID, &item); +} +void Component::AddChild(const std::shared_ptr& child) +{ + children_.emplace_back(child); + OnAddChild(child); +} + +void Component::RemoveChild(const std::shared_ptr& child) +{ + children_.remove(child); + OnRemoveChild(child); +} + +void Component::RemoveAll() +{ + children_.clear(); + OnRemoveAll(); +} + +void Component::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); + } +} + +std::shared_ptr Component::GetPreviousSibling() +{ + auto previousSibling = _nodeAPI->getPreviousSibling(_component); + return std::make_shared(previousSibling); +}; + +std::shared_ptr Component::GetNextSibling() +{ + auto nextSibling = _nodeAPI->getNextSibling(_component); + return std::make_shared(nextSibling); +}; + +void Component::NodeEventReceiver(ArkUI_NodeEvent* event) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // 获取事件发生的UI组件对象。 + auto nodeHandle = OH_ArkUI_NodeEvent_GetNodeHandle(event); + // 获取保持在UI组件对象中的自定义数据,返回封装类指针。 + auto* node = reinterpret_cast(nodeAPI->getUserData(nodeHandle)); + // 基于封装类实例对象处理事件。 + if (node) { + node->ProcessNodeEvent(event); + } +} +void Component::SetFontSize(float fontSize) +{ + ArkUI_NumberValue value[] = { { .f32 = fontSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_SIZE, &item); +} +void Component::ProcessNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "ProcessNodeEvent eventType=%{public}d", eventType); + switch (eventType) { + case NODE_ON_CLICK: { + if (onClick_) { + onClick_(); + } + break; + } + case NODE_TOUCH_EVENT: { + if (onTouch_) { + onTouch_(event); + } + break; + } + case NODE_EVENT_ON_DISAPPEAR: { + if (onDisappear_) { + onDisappear_(); + } + break; + } + case NODE_EVENT_ON_APPEAR: { + if (onAppear_) { + onAppear_(); + } + break; + } + case NODE_ON_HOVER: { + if (onHover_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "NODE_ON_HOVER"); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + int32_t isHover = result->data[0].i32; + onHover_(static_cast(isHover)); + } + break; + } + case NODE_EVENT_ON_VISIBLE_AREA_CHANGE: { + if (onVisibleAreaChange_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "NODE_EVENT_ON_VISIBLE_AREA_CHANGE"); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + bool visible = static_cast(result->data[0].i32); + float ratio = result->data[1].f32; + onVisibleAreaChange_(visible, ratio); + } + break; + } + case NODE_ON_MOUSE: { + if (onMouse_) { + onMouse_(event); + } + break; + } + case NODE_ON_TOUCH_INTERCEPT: { + if (onTouchIntercept_) { + onTouchIntercept_(event); + } + break; + } + case NODE_ON_FOCUS: { + if (onFocus_) { + onFocus_(); + } + break; + } + default: { + OnNodeEvent(event); + } + } +} + +void Component::RegisterOnVisibleAreaChange( + const std::function& onVisibleAreaChange, std::vector ratioArray) +{ + ArkUI_NumberValue value[ratioArray.size()]; + + for (size_t i = 0; i < ratioArray.size(); i++) { + value[i].f32 = { ratioArray[i] }; + } + ArkUI_AttributeItem item = { value, static_cast(ratioArray.size()) }; + + onVisibleAreaChange_ = onVisibleAreaChange; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_VISIBLE_AREA_CHANGE, 0, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h new file mode 100644 index 0000000000000000000000000000000000000000..890ed5f9caceadd21d64ed30de537c908886ba8b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_COMPONENT_H +#define ARKUI_CAPI_DEMO_COMPONENT_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class Component { +public: + explicit Component(ArkUI_NodeType type); + explicit Component(ArkUI_NodeHandle handle); + virtual ~Component() = default; + + int32_t setAttribute(ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* item); + const ArkUI_AttributeItem* getAttribute(ArkUI_NodeAttributeType attribute); + int32_t resetAttribute(ArkUI_NodeAttributeType attribute); + + void SetWidth(float width); + void SetPercentWidth(float percent); + void SetHeight(float height); + void SetPercentHeight(float percent); + void SetBackgroundColor(uint32_t color); + void SetBackgroundImage(const std::string& backgroundImage); + void SetBackgroundImageSizeWithStyle(int32_t imageSize); + void SetBorderRadius(float topLeft, float topRight, float bottomLeft, float bottomRight); + void SetPadding(float top, float right, float bottom, float left); + void SetPaddingPercent(float top, float right, float bottom, float left); + void SetMargin(float top, float right, float bottom, float left); + void SetMargin(float margin); + void SetMarginPercent(float top, float right, float bottom, float left); + void SetEnabled(int32_t enable); + void SetAlign(int32_t align); + void SetAlignRules(ArkUI_AlignmentRuleOption* option); + void SetAlignSelf(int32_t value); + void SetOpacity(float opacity); + void SetBorderWidth(float top, float right, float bottom, float left); + void SetBorderWidth(float borderWidth); + void SetBorderColor(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left); + void SetBorderStyle(int32_t top, int32_t right, int32_t bottom, int32_t left); + void SetVisibility(int32_t visibility); + virtual void SetFontSize(float fontSize); + void SetId(const std::string& id); + void AddChild(const std::shared_ptr& child); + void RemoveChild(const std::shared_ptr& child); + void RemoveAll(); + void InsertChild(const std::shared_ptr& child, int32_t index); + std::list> GetChildren() + { + return children_; + } + std::shared_ptr GetPreviousSibling(); + std::shared_ptr GetNextSibling(); + + ArkUI_NodeHandle GetComponent() + { + return _component; + } + // 处理通用事件。 + void RegisterOnClick(const std::function& onClick) + { + onClick_ = onClick; + _nodeAPI->registerNodeEvent(_component, NODE_ON_CLICK, 0, nullptr); + } + + void RegisterOnTouch(const std::function& onTouch) + { + onTouch_ = onTouch; + _nodeAPI->registerNodeEvent(_component, NODE_TOUCH_EVENT, 0, nullptr); + } + + void RegisterOnDisappear(const std::function& onDisappear) + { + onDisappear_ = onDisappear; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_DISAPPEAR, 0, nullptr); + } + + void RegisterOnAppear(const std::function& onAppear) + { + onAppear_ = onAppear; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_APPEAR, 0, nullptr); + } + void RegisterOnHover(const std::function& onHover) + { + onHover_ = onHover; + _nodeAPI->registerNodeEvent(_component, NODE_ON_HOVER, 0, nullptr); + } + void RegisterOnMouse(const std::function& onMouse) + { + onMouse_ = onMouse; + _nodeAPI->registerNodeEvent(_component, NODE_ON_MOUSE, 0, nullptr); + } + void RegisterOnTouchIntercept(const std::function& onTouchIntercept) + { + onTouchIntercept_ = onTouchIntercept; + _nodeAPI->registerNodeEvent(_component, NODE_ON_TOUCH_INTERCEPT, 0, nullptr); + } + void RegisterOnFocus(const std::function& onFocus) + { + onFocus_ = onFocus; + _nodeAPI->registerNodeEvent(_component, NODE_ON_FOCUS, 0, nullptr); + } + void RegisterOnVisibleAreaChange( + const std::function& onVisibleAreaChange, std::vector ratioArray); + + static void NodeEventReceiver(ArkUI_NodeEvent* event); + void ProcessNodeEvent(ArkUI_NodeEvent* event); + virtual void OnNodeEvent(ArkUI_NodeEvent* event) {} + +protected: + // 组件树操作的实现类对接。 + void OnAddChild(const std::shared_ptr& child) + { + _nodeAPI->addChild(_component, child->GetComponent()); + } + void OnRemoveChild(const std::shared_ptr& child) + { + _nodeAPI->removeChild(_component, child->GetComponent()); + } + void OnRemoveAll() + { + _nodeAPI->removeAllChildren(_component); + } + void OnInsertChild(const std::shared_ptr& child, int32_t index) + { + _nodeAPI->insertChildAt(_component, child->GetComponent(), index); + } + +protected: + std::list> children_; + ArkUI_NodeHandle _component { nullptr }; + ArkUI_NativeNodeAPI_1* _nodeAPI { nullptr }; + +private: + std::function onClick_; + std::function onDisappear_; + std::function onAppear_; + std::function onTouch_; + std::function onHover_; + std::function onVisibleAreaChange_; + std::function onMouse_; + std::function onTouchIntercept_; + std::function onFocus_; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h new file mode 100644 index 0000000000000000000000000000000000000000..c08a3d861df679909e55245207697f00ea4c4165 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H +#define ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { + +class FlowItemComponent : public Component { +public: + FlowItemComponent() : Component(ARKUI_NODE_FLOW_ITEM) {} + explicit FlowItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd9d34569c930225f826b5f641a1c9a231439661 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 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 "grid_component.h" + +namespace ArkUICApiDemo { +void GridComponent::SetGridColumnsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_GRID_COLUMN_TEMPLATE, &item); +} +void GridComponent::SetGridRowsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_GRID_ROW_TEMPLATE, &item); +} +void GridComponent::SetGridColumnsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_COLUMN_GAP, &item); +} +void GridComponent::SetGridRowsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_ROW_GAP, &item); +} +void GridComponent::SetGridCachedCount(int32_t cachedCount) +{ + ArkUI_NumberValue value[] = { { .i32 = cachedCount } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_CACHED_COUNT, &item); +} +void GridComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h new file mode 100644 index 0000000000000000000000000000000000000000..751041f87208c9b152c9b59f345ba5863effc216 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_GRID_COMPONENT_H +#define ARKUI_CAPI_DEMO_GRID_COMPONENT_H + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { + +class GridItemComponent : public Component { +public: + GridItemComponent() : Component(ARKUI_NODE_GRID_ITEM) {} + explicit GridItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; + +class GridComponent : public Component { +public: + GridComponent() : Component(ARKUI_NODE_GRID) {} + explicit GridComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_GRID_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetGridColumnsTemplate(const std::string& str); + void SetGridRowsTemplate(const std::string& str); + void SetGridColumnsGap(float val); + void SetGridRowsGap(float val); + void SetGridCachedCount(int32_t cachedCount); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + * [4] canOverScroll. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + void ReleaseAdapter() + { + return _adapter.reset(); + } + +private: + std::shared_ptr> _adapter; +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_GRID_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9349ba6b9ce8bb046f658a9f7deebb7607e463e8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 "image_component.h" + +#include + +namespace ArkUICApiDemo { + +int32_t ImageComponent::SetImageSrc(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SRC, &item); +} +int32_t ImageComponent::SetImageSrc(ArkUI_DrawableDescriptor* descriptors) +{ + ArkUI_AttributeItem item = { .object = descriptors }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SRC, &item); +} +int32_t ImageComponent::SetObjectFit(const int32_t objectFit) +{ + ArkUI_NumberValue value[] = { { .i32 = objectFit } }; + ArkUI_AttributeItem item = { value, 1 }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_OBJECT_FIT, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h new file mode 100644 index 0000000000000000000000000000000000000000..a3a30cc05fda6e773c23ed34d9c8694cfccb0935 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageComponent : public Component { +public: + ImageComponent() : Component(ARKUI_NODE_IMAGE) {} + explicit ImageComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + int32_t SetImageSrc(const std::string& content); + int32_t SetImageSrc(ArkUI_DrawableDescriptor* descriptors); + int32_t SetObjectFit(const int32_t objectFit); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45254af2c26bd9c9d1416b1af5a77bfc2297a4ce --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 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 "imageanimator_component.h" + +namespace ArkUICApiDemo { +void ImageAnimatorComponent::SetState(int32_t state) +{ + ArkUI_NumberValue value[] = { { .i32 = state } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_STATE, &item); +} + +void ImageAnimatorComponent::SetIteration(int32_t iteration) +{ + ArkUI_NumberValue value[] = { { .i32 = iteration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_ITERATION, &item); +} + +void ImageAnimatorComponent::SetImage(ArkUI_AttributeItem& item) +{ + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_IMAGES, &item); +} + +void ImageAnimatorComponent::SetFixedSize(int32_t fixedSize) +{ + ArkUI_NumberValue value[] = { { .i32 = fixedSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_FIXED_SIZE, &item); +} + +void ImageAnimatorComponent::SetReverse(int32_t reverse) +{ + ArkUI_NumberValue value[] = { { .i32 = reverse } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_REVERSE, &item); +} +void ImageAnimatorComponent::SetFillMode(int32_t mode) +{ + ArkUI_NumberValue value[] = { { .i32 = mode } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_FILL_MODE, &item); +} + +void ImageAnimatorComponent::SetDuration(int32_t duration) +{ + ArkUI_NumberValue value[] = { { .i32 = duration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_DURATION, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h new file mode 100644 index 0000000000000000000000000000000000000000..98a7d78b6cb85737aafcafe5240bf444a20f90be --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageAnimatorComponent : public Component { +public: + ImageAnimatorComponent() : Component(ARKUI_NODE_IMAGE_ANIMATOR) {} + explicit ImageAnimatorComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetState(int32_t state); + void SetIteration(int32_t iteration); + void SetImage(ArkUI_AttributeItem& item); + void SetFixedSize(int32_t fixedSize); + void SetReverse(int32_t reverse); + void SetFillMode(int32_t mode); + void SetDuration(int32_t duration); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39141070a39e169185cfcc4a75bb3c6e5fcd0937 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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 "imagespan_component.h" + +namespace ArkUICApiDemo { + +int32_t ImageSpanComponent::SetImageSpanSrc(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SPAN_SRC, &item); +} +int32_t ImageSpanComponent::SetImageSpanSrc(ArkUI_DrawableDescriptor* descriptors) +{ + ArkUI_AttributeItem item = { .object = descriptors }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SPAN_SRC, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h new file mode 100644 index 0000000000000000000000000000000000000000..c23ce64f8402c90d6296c1b00aa60718403a6632 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageSpanComponent : public Component { +public: + ImageSpanComponent() : Component(ARKUI_NODE_IMAGE_SPAN) {} + explicit ImageSpanComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + int32_t SetImageSpanSrc(const std::string& content); + int32_t SetImageSpanSrc(ArkUI_DrawableDescriptor* descriptors); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27f6f903b2a7f5192a5fbf4523757f3c60d4cbf9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2024 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 "list_component.h" + +namespace ArkUICApiDemo { + +void ListItemSwipeActionOption::SetStart(ArkUI_ListItemSwipeActionItem* item) +{ + OH_ArkUI_ListItemSwipeActionOption_SetStart(_option, item); +} + +void ListItemSwipeActionOption::SetEnd(ArkUI_ListItemSwipeActionItem* item) +{ + OH_ArkUI_ListItemSwipeActionOption_SetEnd(_option, item); +} + +void ListItemSwipeActionOption::SetEdgeEffect(ArkUI_ListItemSwipeEdgeEffect edgeEffect) +{ + OH_ArkUI_ListItemSwipeActionOption_SetEdgeEffect(_option, edgeEffect); +} + +int32_t ListItemSwipeActionOption::GetEdgeEffect() +{ + return OH_ArkUI_ListItemSwipeActionOption_GetEdgeEffect(_option); +} + +void ListItemSwipeActionOption::SetOnOffsetChange(OnOffsetChangeCallback callback) +{ + OH_ArkUI_ListItemSwipeActionOption_SetOnOffsetChange(_option, callback); +} + +void ListItemSwipeActionOption::SetOnOffsetChangWithUserData( + OnOffsetChangeWithUserDataCallback callback, void* userData) +{ + OH_ArkUI_ListItemSwipeActionOption_SetOnOffsetChangeWithUserData(_option, userData, callback); +} + +int32_t ListChildrenMainSizeOption::SetDefaultMainSize(float defaultMainSize) +{ + return OH_ArkUI_ListChildrenMainSizeOption_SetDefaultMainSize(_option, defaultMainSize); +} + +float ListChildrenMainSizeOption::GetDefaultMainSize() +{ + return OH_ArkUI_ListChildrenMainSizeOption_GetDefaultMainSize(_option); +} + +void ListChildrenMainSizeOption::Resize(int32_t totalSize) +{ + OH_ArkUI_ListChildrenMainSizeOption_Resize(_option, totalSize); +} + +int32_t ListChildrenMainSizeOption::Splice(int32_t index, int32_t deleteCount, int32_t addCount) +{ + return OH_ArkUI_ListChildrenMainSizeOption_Splice(_option, index, deleteCount, addCount); +} + +int32_t ListChildrenMainSizeOption::UpdateSize(int32_t index, float mainSize) +{ + return OH_ArkUI_ListChildrenMainSizeOption_UpdateSize(_option, index, mainSize); +} + +float ListChildrenMainSizeOption::GetMainSize(int32_t index) +{ + return OH_ArkUI_ListChildrenMainSizeOption_GetMainSize(_option, index); +} + +void ListItemComponent::SetListItemSwiperAction(ListItemSwipeActionOption* option) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, option->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_SWIPE_ACTION, &item); +} + +void ListComponent::SetListDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_DIRECTION, &item); +} + +void ListComponent::SetListSticky(int32_t stickyStyle) +{ + ArkUI_NumberValue value[] = { { .i32 = stickyStyle } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_STICKY, &item); +} + +void ListComponent::SetListSpace(float space) +{ + ArkUI_NumberValue value[] = { { .f32 = space } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_SPACE, &item); +} + +void ListComponent::SetListCachedCount(int32_t count) +{ + ArkUI_NumberValue value[] = { { .i32 = count } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_CACHED_COUNT, &item); +} + +void ListComponent::SetListScrollToIndex(const std::vector& data) +{ + ArkUI_AttributeItem item = { data.data(), static_cast(data.size()) }; + _nodeAPI->setAttribute(_component, NODE_LIST_SCROLL_TO_INDEX, &item); +} + +void ListComponent::SetListAlignListItem(int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_ALIGN_LIST_ITEM, &item); +} + +void ListComponent::SetListChildrenMainSize(ListChildrenMainSizeOption* mainSize) +{ + ArkUI_AttributeItem item = { .object = mainSize->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_CHILDREN_MAIN_SIZE, &item); + _childrenMainSize.reset(mainSize); +} + +void ListComponent::SetListInitialIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_INITIAL_INDEX, &item); +} + +void ListComponent::SetListDivider(uint32_t color, float width, float distanceStart, float distanceEnd) +{ + ArkUI_NumberValue value[] = { { .u32 = color }, { .f32 = width }, { .f32 = distanceStart }, + { .f32 = distanceEnd } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_LIST_DIVIDER, &item); +} + +void ListItemGroupComponent::SetListItemGroupHeader(Component* node) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, node->GetComponent() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_HEADER, &item); +} + +void ListItemGroupComponent::SetListItemGroupFooter(Component* node) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, node->GetComponent() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_FOOTER, &item); +} + +void ListItemGroupComponent::SetListItemGroupDivider( + uint32_t color, float width, float distanceStart, float distanceEnd) +{ + ArkUI_NumberValue value[] = { { .u32 = color }, { .f32 = width }, { .f32 = distanceStart }, + { .f32 = distanceEnd } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_DIVIDER, &item); +} + +void ListItemGroupComponent::SetListItemGroupChildrenMainSize(ListChildrenMainSizeOption* mainSize) +{ + ArkUI_AttributeItem item = { .object = mainSize->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_CHILDREN_MAIN_SIZE, &item); + _childrenMainSize.reset(mainSize); +} + +void ListItemGroupAdapter::OnNewItemAttached(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + ArkUI_NodeHandle handle = nullptr; + int32_t start = index > 0 ? _groupList[index - 1] : 0, end = _groupList[index]; + if (end - start != 1) { + handle = UpdateNewItemByGroup(start, end); + } else { + handle = UpdateNewItem(start, end); + } + // 设置需要展示的元素。 + OH_ArkUI_NodeAdapterEvent_SetItem(event, handle); +} + +void ListItemGroupAdapter::OnItemDetached(ArkUI_NodeAdapterEvent* event) +{ + auto item = OH_ArkUI_NodeAdapterEvent_GetRemovedNode(event); + if (_removedNodeCallback) { + _removedNodeCallback(std::make_shared(item)); + } + // 放置到缓存池中进行回收复用。 + if (Component(item).GetChildren().size() == 1) { + _cachedListItems.emplace(_listItems[item]); + } else { + _cachedItems.emplace(_items[item]); + } +} + +ArkUI_NodeHandle ListItemGroupAdapter::UpdateNewItemByGroup(int32_t start, int32_t end) +{ + ArkUI_NodeHandle handle = nullptr; + if (!_cachedItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedItems.top(); + recycledItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + recycledItem->AddChild(_data[i]); + } + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedItems.pop(); + } else { + // 创建新的元素。 + auto groupItem = std::make_shared(); + groupItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + groupItem->AddChild(_data[i]); + } + groupItem->SetBorderWidth(1); + handle = groupItem->GetComponent(); + // 保持文本列表项的引用。 + _items.emplace(handle, groupItem); + } + return handle; +} + +ArkUI_NodeHandle ListItemGroupAdapter::UpdateNewItem(int32_t start, int32_t end) +{ + ArkUI_NodeHandle handle = nullptr; + if (!_cachedListItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedListItems.top(); + recycledItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + recycledItem->AddChild(_data[i]); + } + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedListItems.pop(); + } else { + // 创建新的元素。 + auto listItem = std::make_shared(); + listItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + listItem->AddChild(_data[i]); + } + handle = listItem->GetComponent(); + // 保持文本列表项的引用。 + _listItems.emplace(handle, listItem); + } + return handle; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h new file mode 100644 index 0000000000000000000000000000000000000000..d372f10ed44a87d6e71176769bef3a23324ca72b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2024 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 CAPIDEMO_LIST_COMPONENT_H +#define CAPIDEMO_LIST_COMPONENT_H +#include + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { + +typedef void (*OnOffsetChangeCallback)(float offset); +typedef void (*OnOffsetChangeWithUserDataCallback)(float offset, void* userData); +typedef void (*OnFinish)(void* userData); + +class ListItemSwipeActionOption { +public: + ListItemSwipeActionOption() : _option(OH_ArkUI_ListItemSwipeActionOption_Create()) {} + ~ListItemSwipeActionOption() + { + OH_ArkUI_ListItemSwipeActionOption_Dispose(_option); + } + + void SetStart(ArkUI_ListItemSwipeActionItem* item); + void SetEnd(ArkUI_ListItemSwipeActionItem* item); + void SetEdgeEffect(ArkUI_ListItemSwipeEdgeEffect edgeEffect); + int32_t GetEdgeEffect(); + void SetOnOffsetChange(OnOffsetChangeCallback callback); + void SetOnOffsetChangWithUserData(OnOffsetChangeWithUserDataCallback callback, void* userData); + + ArkUI_ListItemSwipeActionOption* GetOption() + { + return _option; + } + +private: + ArkUI_ListItemSwipeActionOption* _option; +}; + +class ListItemComponent : public Component { +public: + ListItemComponent() : Component(ARKUI_NODE_LIST_ITEM) {} + explicit ListItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetListItemSwiperAction(ListItemSwipeActionOption* option); + std::shared_ptr GetSwipeActionOption() const + { + return _swipeActionOption; + } + void ReleaseSwipeActionOption() + { + _swipeActionOption.reset(); + } + +private: + std::shared_ptr _swipeActionOption; +}; + +class ListChildrenMainSizeOption { +public: + ListChildrenMainSizeOption() : _option(OH_ArkUI_ListChildrenMainSizeOption_Create()) {} + ~ListChildrenMainSizeOption() + { + OH_ArkUI_ListChildrenMainSizeOption_Dispose(_option); + } + int32_t SetDefaultMainSize(float defaultMainSize); + float GetDefaultMainSize(); + void Resize(int32_t totalSize); + int32_t Splice(int32_t index, int32_t deleteCount, int32_t addCount); + int32_t UpdateSize(int32_t index, float mainSize); + float GetMainSize(int32_t index); + + ArkUI_ListChildrenMainSize* GetOption() + { + return _option; + } + +private: + ArkUI_ListChildrenMainSize* _option; +}; + +class ListItemGroupComponent : public Component { +public: + ListItemGroupComponent() : Component(ARKUI_NODE_LIST_ITEM_GROUP) {} + explicit ListItemGroupComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetListItemGroupHeader(Component* node); + void SetListItemGroupFooter(Component* node); + void SetListItemGroupDivider(uint32_t color, float width, float distanceStart, float distanceEnd); + void SetListItemGroupChildrenMainSize(ListChildrenMainSizeOption* mainSize); + + std::shared_ptr GetSizeOption() const + { + return _childrenMainSize; + } + void ReleaseSizeOption() + { + _childrenMainSize.reset(); + } + +private: + std::shared_ptr _childrenMainSize; +}; + +class ListItemGroupAdapter : public ItemAdapter { +public: + explicit ListItemGroupAdapter(std::vector>& dataSource, + const std::vector& groupList) + : ItemAdapter(dataSource) + { + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, groupList.size()); + int32_t sum = 0; + for (auto& item : groupList) { + sum += item; + _groupList.push_back(sum); + } + } + virtual ~ListItemGroupAdapter() {} + +protected: + void OnNewItemAttached(ArkUI_NodeAdapterEvent* event) override; + void OnItemDetached(ArkUI_NodeAdapterEvent* event) override; + ArkUI_NodeHandle UpdateNewItemByGroup(int32_t start, int32_t end); + ArkUI_NodeHandle UpdateNewItem(int32_t start, int32_t end); + +private: + std::vector _groupList; + // 缓存listItemComponent + std::stack> _cachedListItems; + // 存储list嵌套的单个listItem + std::unordered_map> _listItems; +}; + +class ListComponent : public Component { +public: + ListComponent() : Component(ARKUI_NODE_LIST) {} + explicit ListComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + // 引入懒加载模块。 + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_LIST_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetLazyAdapterByGroup(const std::shared_ptr& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_LIST_NODE_ADAPTER, &item); + _groupAdapter = adapter; + } + /** + * @param direction ArkUI_Axis + */ + void SetListDirection(int32_t direction); + /** + * @param stickyStyle ArkUI_StickyStyle + */ + void SetListSticky(int32_t stickyStyle); + void SetListSpace(float space); + void SetListCachedCount(int32_t count); + /** + * data[0].i32:The index value of the target element to be slid to in the current container.\n + * data[1]?.i32:Set whether there is an action when sliding to the index value of a list item in the list, where + * 1 indicates an action and 0 indicates no action. Default value: 0。\n + * data[2]?.i32:ArkUI_ScrollAlignment + */ + void SetListScrollToIndex(const std::vector& data); + /** + * @param align ArkUI_ListItemAlignment + */ + void SetListAlignListItem(int32_t align); + void SetListChildrenMainSize(ListChildrenMainSizeOption* mainSize); + void SetListInitialIndex(int32_t index); + void SetListDivider(uint32_t color, float width, float distanceStart, float distanceEnd); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + std::shared_ptr GetGroupAdapter() const + { + return _groupAdapter; + } + std::shared_ptr GetSizeOption() const + { + return _childrenMainSize; + } + void ReleaseSizeOption() + { + _childrenMainSize.reset(); + } + +private: + std::shared_ptr> _adapter; + std::shared_ptr _groupAdapter; + std::shared_ptr _childrenMainSize; +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_LIST_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..8f4db32a4653680fd13e825c81871796a729a407 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_NODE_ADAPTER_H +#define ARKUI_CAPI_DEMO_NODE_ADAPTER_H + +#include +#include +#include +#include +#include +#include + +#include "column_component.h" +namespace ArkUICApiDemo { +using AllItemCallBack = std::function, uint32_t)>; + +template +class ItemAdapter { +public: + explicit ItemAdapter(std::vector>& dataSource); + virtual ~ItemAdapter(); + ArkUI_NodeAdapterHandle GetAdapter() const + { + return _adapter; + } + void RemoveItem(int32_t index); + void RemoveItems(int32_t startPosition, int32_t itemCount); + void InsertItem(int32_t index, const std::shared_ptr& value); + void InsertItems(int32_t index, std::vector>& dataSource); + void MoveItem(int32_t oldIndex, int32_t newIndex); + void ReloadItem(int32_t index, const std::shared_ptr& value); + void ReloadItems(int32_t startPosition, std::vector>& dataSource); + void ReloadAllItem(); + void SetAllItem(AllItemCallBack callback); + void UnregisterEventReceiver(); + void SetNodeAdapterEvent(const std::function& callback); + void RegisterRemovedNodeCallback(std::function)> callback) + { + _removedNodeCallback = callback; + } + void SetTotalNodeCount(uint32_t count) + { + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, count); + } + uint32_t GetTotalNodeCount() + { + return OH_ArkUI_NodeAdapter_GetTotalNodeCount(_adapter); + } + +protected: + static void OnStaticAdapterEvent(ArkUI_NodeAdapterEvent* event); + virtual void OnAdapterEvent(ArkUI_NodeAdapterEvent* event); + // 分配ID给需要显示的Item,用于ReloadAllItems场景的元素diff。 + virtual void OnNewItemIdCreated(ArkUI_NodeAdapterEvent* event); + // 需要新的Item显示在可见区域。 + virtual void OnNewItemAttached(ArkUI_NodeAdapterEvent* event); + // Item从可见区域移除。 + virtual void OnItemDetached(ArkUI_NodeAdapterEvent* event); + + std::vector> _data; + ArkUI_NativeNodeAPI_1* _nodeAPI = nullptr; + ArkUI_NodeAdapterHandle _adapter = nullptr; + // 管理NodeAdapter生成的元素。 + std::unordered_map> _items; + // 管理回收复用组件池。 + std::stack> _cachedItems; + std::function _eventCallBack; + std::function)> _removedNodeCallback; +}; + +template +ItemAdapter::ItemAdapter(std::vector>& dataSource) + : _adapter(OH_ArkUI_NodeAdapter_Create()) +{ + // 使用NodeAdapter创建函数。 + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + std::swap(_data, dataSource); + // 设置懒加载数据。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); + // 设置懒加载回调事件。 + OH_ArkUI_NodeAdapter_RegisterEventReceiver(_adapter, this, OnStaticAdapterEvent); +} + +template +ItemAdapter::~ItemAdapter() +{ + // 释放创建的组件。 + while (!_cachedItems.empty()) { + _cachedItems.pop(); + } + _items.clear(); + // 释放Adapter相关资源。 + OH_ArkUI_NodeAdapter_UnregisterEventReceiver(_adapter); + OH_ArkUI_NodeAdapter_Dispose(_adapter); +} + +template +void ItemAdapter::RemoveItem(int32_t index) +{ + // 删除第index个数据。 + _data.erase(_data.begin() + index); + // 如果index会导致可视区域元素发生可见性变化,则会回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER事件删除元素, + // 根据是否有新增元素回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_RemoveItem(_adapter, index, 1); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::RemoveItems(int32_t startPosition, int32_t itemCount) +{ + auto end = _data.begin() + startPosition + itemCount; + if (startPosition + itemCount > _data.size()) { + end = _data.end(); + } + _data.erase(_data.begin() + startPosition, end); + OH_ArkUI_NodeAdapter_RemoveItem(_adapter, startPosition, itemCount); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::InsertItem(int32_t index, const std::shared_ptr& value) +{ + _data.insert(_data.begin() + index, value); + // 如果index会导致可视区域元素发生可见性变化,则会回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件, + // 根据是否有删除元素回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER事件。 + OH_ArkUI_NodeAdapter_InsertItem(_adapter, index, 1); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::InsertItems(int32_t index, std::vector>& dataSource) +{ + _data.insert(_data.begin() + index, dataSource.begin(), dataSource.end()); + OH_ArkUI_NodeAdapter_InsertItem(_adapter, index, dataSource.size()); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::MoveItem(int32_t oldIndex, int32_t newIndex) +{ + auto temp = _data[oldIndex]; + _data.insert(_data.begin() + newIndex, temp); + _data.erase(_data.begin() + oldIndex); + // 移到位置如果未发生可视区域内元素的可见性变化,则不回调事件,反之根据新增和删除场景回调对应的事件。 + OH_ArkUI_NodeAdapter_MoveItem(_adapter, oldIndex, newIndex); +} + +template +void ItemAdapter::ReloadItem(int32_t index, const std::shared_ptr& value) +{ + _data[index] = value; + // 如果index位于可视区域内,先回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素, + // 再回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_ReloadItem(_adapter, index, 1); +} + +template +void ItemAdapter::ReloadItems(int32_t startPosition, std::vector>& dataSource) +{ + if (startPosition + dataSource.size() > _data.size()) { + // 防止nodeAdapter崩溃 + return; + } + for (int32_t i = 0; i < dataSource.size(); i++) { + _data[startPosition + i] = dataSource[i]; + } + // 如果index位于可视区域内,先回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素, + // 再回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_ReloadItem(_adapter, startPosition, dataSource.size()); +} + +template +void ItemAdapter::SetAllItem(AllItemCallBack callback) +{ + ArkUI_NodeHandle* items = nullptr; + uint32_t size = 0; + OH_ArkUI_NodeAdapter_GetAllItems(_adapter, &items, &size); + for (uint32_t i = 0; i < size; i++) { + if (!items[i]) { + continue; + } + auto temp = std::make_shared(items[i]); + if (callback) { + callback(temp, i); + } + } +} + +template +void ItemAdapter::UnregisterEventReceiver() +{ + OH_ArkUI_NodeAdapter_UnregisterEventReceiver(_adapter); +} + +template +void ItemAdapter::SetNodeAdapterEvent(const std::function& callback) +{ + _eventCallBack = callback; +} + +template +void ItemAdapter::ReloadAllItem() +{ + std::reverse(_data.begin(), _data.end()); + // 全部重新加载场景下,会回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID接口获取新的组件ID, + // 根据新的组件ID进行对比,ID不发生变化的进行复用, + // 针对新增ID的元素,调用NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件创建新的组件, + // 然后判断老数据中遗留的未使用ID,调用NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素。 + OH_ArkUI_NodeAdapter_ReloadAllItems(_adapter); +} + +template +void ItemAdapter::OnStaticAdapterEvent(ArkUI_NodeAdapterEvent* event) +{ + // 获取实例对象,回调实例事件。 + auto itemAdapter = reinterpret_cast(OH_ArkUI_NodeAdapterEvent_GetUserData(event)); + itemAdapter->OnAdapterEvent(event); +} + +template +void ItemAdapter::OnAdapterEvent(ArkUI_NodeAdapterEvent* event) +{ + auto type = OH_ArkUI_NodeAdapterEvent_GetType(event); + switch (type) { + case NODE_ADAPTER_EVENT_WILL_ATTACH_TO_NODE: + break; + case NODE_ADAPTER_EVENT_WILL_DETACH_FROM_NODE: + break; + case NODE_ADAPTER_EVENT_ON_GET_NODE_ID: + OnNewItemIdCreated(event); + break; + case NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER: + OnNewItemAttached(event); + break; + case NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER: + OnItemDetached(event); + break; + default: + break; + } + if (_eventCallBack) { + _eventCallBack(event); + } +} +template +void ItemAdapter::OnNewItemIdCreated(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + static std::hash hashId = std::hash(); + auto id = hashId(std::to_string(index)); + OH_ArkUI_NodeAdapterEvent_SetNodeId(event, id); +} + +// 需要新的Item显示在可见区域。 +template +void ItemAdapter::OnNewItemAttached(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + ArkUI_NodeHandle handle = nullptr; + auto showNode = _data[index]; + if (!_cachedItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedItems.top(); + recycledItem->RemoveAll(); + recycledItem->AddChild(showNode); + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedItems.pop(); + } else { + // 创建新的元素。 + auto flowItem = std::make_shared(); + flowItem->RemoveAll(); + flowItem->AddChild(showNode); + handle = flowItem->GetComponent(); + // 保持文本列表项的引用。 + _items.emplace(handle, flowItem); + } + // 设置需要展示的元素。 + OH_ArkUI_NodeAdapterEvent_SetItem(event, handle); +} + +// Item从可见区域移除。 +template +void ItemAdapter::OnItemDetached(ArkUI_NodeAdapterEvent* event) +{ + auto item = OH_ArkUI_NodeAdapterEvent_GetRemovedNode(event); + if (_removedNodeCallback) { + _removedNodeCallback(std::make_shared(item)); + } + // 放置到缓存池中进行回收复用。 + _cachedItems.emplace(_items[item]); +} +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_NODE_ADAPTER_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..975473d6357a9dc1910a500a172877e4b04ddba5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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 "radio_component.h" + +#include + +namespace ArkUICApiDemo { +constexpr size_t ALLOW_SIZE_3 = 3; +void RadioComponent::SetChecked(const bool& isChecked) +{ + ArkUI_NumberValue value[] = { { .i32 = static_cast(isChecked) } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_RADIO_CHECKED, &item); +} +void RadioComponent::SetGroup(const std::string& group) +{ + ArkUI_AttributeItem item = { .string = group.c_str() }; + _nodeAPI->setAttribute(_component, NODE_RADIO_GROUP, &item); +} +void RadioComponent::SetStyled(const uint32_t* colorArray, size_t size) +{ + if (size == ALLOW_SIZE_3) { + ArkUI_NumberValue radioStyle_value[] = { { .u32 = colorArray[0] }, { .u32 = colorArray[1] }, + { .u32 = colorArray[2] } }; + ArkUI_AttributeItem radioStyle_value_item = { radioStyle_value, ALLOW_SIZE_3 }; + _nodeAPI->setAttribute(_component, NODE_RADIO_STYLE, &radioStyle_value_item); + } +} +void RadioComponent::SetValue(const std::string& value) +{ + ArkUI_AttributeItem item = { .string = value.c_str() }; + _nodeAPI->setAttribute(_component, NODE_RADIO_VALUE, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h new file mode 100644 index 0000000000000000000000000000000000000000..b40239197998d9b4f9a52c3cd1803b03d68ce060 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_RADIO_COMPONENT_H +#define ARKUI_CAPI_DEMO_RADIO_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class RadioComponent : public Component { +public: + RadioComponent() : Component(ARKUI_NODE_RADIO) {} + explicit RadioComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetChecked(const bool& isChecked); + void SetGroup(const std::string& group); + void SetStyled(const uint32_t* colorArray, size_t size); + void SetValue(const std::string& value); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06f55393c9345a0249f924305ddf8be34fe047c6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 "refresh_component.h" + +#include + +namespace ArkUICApiDemo { + +void RefreshComponent::SetPullToRefresh(int32_t pullToRefresh) +{ + ArkUI_NumberValue value[] = { { .i32 = pullToRefresh } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_PULL_TO_REFRESH, &item); +} +void RefreshComponent::SetPullDownRatio(float pullDownRatio) +{ + ArkUI_NumberValue value[] = { { .f32 = pullDownRatio } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_PULL_DOWN_RATIO, &item); +} +void RefreshComponent::SetRefreshOffset(float refreshOffset) +{ + ArkUI_NumberValue value[] = { { .f32 = refreshOffset } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_OFFSET, &item); +} +void RefreshComponent::SetRefreshing(bool refreshing) +{ + ArkUI_NumberValue value[] = { { .i32 = refreshing } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_REFRESHING, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h new file mode 100644 index 0000000000000000000000000000000000000000..69288ede3a5d722198a07544dd773e3a9d9906ba --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H +#define ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class RefreshComponent : public Component { +public: + RefreshComponent() : Component(ARKUI_NODE_REFRESH) {} + explicit RefreshComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetPullToRefresh(int32_t pullToRefresh); + void SetPullDownRatio(float pullDownRatio); + void SetRefreshOffset(float refreshOffset); + void SetRefreshing(bool refreshing); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h new file mode 100644 index 0000000000000000000000000000000000000000..12bb583e22275a328a8e0378ad98d03ba069e739 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H +#define ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H + +#include +#include + +#include "./relativeContainer/ruleOption.h" +#include "component.h" +namespace ArkUICApiDemo { +class RelativeContainerComponent : public Component { +public: + RelativeContainerComponent() : Component(ARKUI_NODE_RELATIVE_CONTAINER) {} + explicit RelativeContainerComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetRelativeContainerGuideLine(const std::shared_ptr guidelineOption) + { + ArkUI_AttributeItem item = { .object = guidelineOption->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_RELATIVE_CONTAINER_GUIDE_LINE, &item); + guidelineOption_ = guidelineOption; + } + + void SetRelativeContainerBarrier(const std::shared_ptr barrierOption) + { + ArkUI_AttributeItem item = { .object = barrierOption->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_RELATIVE_CONTAINER_BARRIER, &item); + barrierOption_ = barrierOption; + } + + std::shared_ptr GetRuleOption() const + { + return ruleOption_; + } + std::shared_ptr GetGuideLineOption() const + { + return guidelineOption_; + } + std::shared_ptr GetBarrierOption() const + { + return barrierOption_; + } + +private: + std::shared_ptr ruleOption_ = nullptr; + std::shared_ptr guidelineOption_ = nullptr; + std::shared_ptr barrierOption_ = nullptr; +}; +; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h new file mode 100644 index 0000000000000000000000000000000000000000..89e04a0300d895575d0a7c08d3acd715521f1008 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_ROW_COMPONENT_H +#define ARKUI_CAPI_DEMO_ROW_COMPONENT_H + +#include "component.h" +namespace ArkUICApiDemo { +class RowComponent : public Component { +public: + RowComponent() : Component(ARKUI_NODE_ROW) {} + explicit RowComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetAlignItems(int32_t verticalAlign) + { + ArkUI_NumberValue value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ROW_ALIGN_ITEMS, &item); + } + void SetJustifyContent(int32_t flexAlign) + { + ArkUI_NumberValue value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ROW_JUSTIFY_CONTENT, &item); + } +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_ROW_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5575c157d7c3b2d05ce7451913dfc9f335c69222 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024 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 "scroll_component.h" +namespace ArkUICApiDemo { + +void ScrollComponent::SetScrollScrollBar(int32_t barState) +{ + ArkUI_NumberValue value[] = { { .i32 = barState } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_DISPLAY_MODE, &item); +} +void ScrollComponent::SetScrollScrollBarWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_WIDTH, &item); +} +void ScrollComponent::SetScrollScrollBarColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_COLOR, &item); +} +void ScrollComponent::SetScrollScrollable(int32_t scrollable) +{ + ArkUI_NumberValue value[] = { { .i32 = scrollable } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SCROLL_DIRECTION, &item); +} +void ScrollComponent::SetScrollEdgeEffect(int32_t edgeEffect, bool alwaysEnabled) +{ + ArkUI_NumberValue value[] = { { .i32 = edgeEffect }, { .i32 = alwaysEnabled } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE_EFFECT, &item); +} +void ScrollComponent::SetScrollEnableScrollInteraction(bool enableScrollInteraction) +{ + ArkUI_NumberValue value[] = { { .i32 = enableScrollInteraction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_SCROLL_INTERACTION, &item); +} +void ScrollComponent::SetScrollFriction(float friction) +{ + ArkUI_NumberValue value[] = { { .f32 = friction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_FRICTION, &item); +} +void ScrollComponent::SetScrollScrollSnap( + int32_t snapAlign, int32_t enableSnapToStart, int32_t enableSnapToEnd, const std::vector& pagination) +{ + auto value = new ArkUI_NumberValue[3 + static_cast(pagination.size())]; + value[0] = { .i32 = snapAlign }; + value[1] = { .i32 = enableSnapToStart }; + value[2] = { .i32 = enableSnapToEnd }; + for (int32_t i = 0; i < pagination.size(); i++) { + value[3 + i] = { .f32 = pagination[i] }; + } + ArkUI_AttributeItem item = { value, 3 + static_cast(pagination.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SNAP, &item); +} +void ScrollComponent::SetScrollNestedScroll(int32_t forward, int32_t backward) +{ + ArkUI_NumberValue value[] = { { .i32 = forward }, { .i32 = backward } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_NESTED_SCROLL, &item); +} +void ScrollComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +void ScrollComponent::SetScrollEdge(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE, &item); +} +void ScrollComponent::SetScrollEnablePaging(int32_t enablePaging) +{ + ArkUI_NumberValue value[] = { { .i32 = enablePaging } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_PAGING, &item); +} +void ScrollComponent::SetScrollPage(int32_t next) +{ + ArkUI_NumberValue value[] = { { .i32 = next } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void ScrollComponent::SetScrollPage(int32_t next, int32_t animation) +{ + ArkUI_NumberValue value[] = { { .i32 = next }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void ScrollComponent::SetScrollBy(float hDistance, float vDistance) +{ + ArkUI_NumberValue value[] = { { .f32 = hDistance }, { .f32 = vDistance } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BY, &item); +} +void ScrollComponent::SetScrollScrollDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SCROLL_DIRECTION, &item); +} +void ScrollComponent::AddChildWithNumber(int32_t number, ArkUI_NodeType type) +{ + SetBorderWidth(2); + auto node = std::make_shared(type); + if (type == ARKUI_NODE_LIST) { + ArkUI_NumberValue value[] = { { .i32 = ARKUI_AXIS_HORIZONTAL } }; + ArkUI_AttributeItem item = { value, 1 }; + node->setAttribute(NODE_LIST_DIRECTION, &item); + node->SetMargin(DEFAULT_MARGIN); + } + for (int32_t i = 0; i < number; ++i) { + auto column = std::make_shared(ARKUI_NODE_COLUMN); + column->SetWidth(SIZE_50); + column->SetHeight(SIZE_50); + column->SetMargin(DEFAULT_MARGIN); + if (number == 0) { + number = 1; + } + column->SetBackgroundColor((i * 0xFFFFFF / number) | 0xFF000000); + node->AddChild(column); + } + AddChild(node); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h new file mode 100644 index 0000000000000000000000000000000000000000..52cb6ffeb62e0cdbc197815fcc85bfc6caa6edd9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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 CAPIDEMO_SCROLL_COMPONENT_H +#define CAPIDEMO_SCROLL_COMPONENT_H + +#include "component.h" + +namespace ArkUICApiDemo { +class ScrollComponent : public Component { +public: + ScrollComponent() : Component(ARKUI_NODE_SCROLL) {} + explicit ScrollComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetScrollScrollBar(int32_t barState); + void SetScrollScrollBarWidth(float width); + void SetScrollScrollBarColor(uint32_t color); + void SetScrollScrollable(int32_t scrollable); + void SetScrollEdgeEffect(int32_t edgeEffect, bool alwaysEnabled); + void SetScrollEnableScrollInteraction(bool enableScrollInteraction); + void SetScrollFriction(float friction); + void SetScrollScrollSnap( + int32_t snapAlign, int32_t enableSnapToStart, int32_t enableSnapToEnd, const std::vector& pagination); + void SetScrollNestedScroll(int32_t forward, int32_t backward); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + void SetScrollEdge(int32_t type); + void SetScrollEnablePaging(int32_t enablePaging); + void SetScrollPage(int32_t next); + void SetScrollPage(int32_t next, int32_t animation); + void SetScrollBy(float hDistance, float vDistance); + void SetScrollScrollDirection(int32_t direction); + void AddChildWithNumber(int32_t number, ArkUI_NodeType type); +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_SCROLL_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9500a64aede50cc3317a3fd2a85834e9ef514678 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2024 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 "swiper_component.h" + +namespace ArkUICApiDemo { + +void SwiperComponent::SetSwiperLoop(int32_t loop) +{ + ArkUI_NumberValue value[] = { { .i32 = loop } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_LOOP, &item); +} + +void SwiperComponent::SetSwiperAutoPlay(int32_t playValue) +{ + ArkUI_NumberValue value[] = { { .i32 = playValue } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_AUTO_PLAY, &item); +} + +void SwiperComponent::SetSwiperPrevMigration(float migration, int32_t ignoreBlank) +{ + ArkUI_NumberValue value[] = { { .f32 = migration }, { .i32 = ignoreBlank } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_PREV_MARGIN, &item); +} + +void SwiperComponent::SetSwiperNextMigration(float migration, int32_t ignoreBlank) +{ + ArkUI_NumberValue value[] = { { .f32 = migration }, { .i32 = ignoreBlank } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_NEXT_MARGIN, &item); +} + +void SwiperComponent::SetSwiperDisplayCount(int32_t count) +{ + ArkUI_NumberValue value[] = { { .i32 = count } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_DISPLAY_COUNT, &item); +} + +void SwiperComponent::SetSwiperIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INDEX, &item); +} + +void SwiperComponent::SetSwiperVertical(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_VERTICAL, &item); +} + +void SwiperComponent::SetSwiperEffectMode(int32_t effect) +{ + ArkUI_NumberValue value[] = { { .i32 = effect } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_EDGE_EFFECT_MODE, &item); +} + +void SwiperComponent::SetSwiperNestedScroll(int32_t nestedScroll) +{ + ArkUI_NumberValue value[] = { { .i32 = nestedScroll } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_NESTED_SCROLL, &item); +} + +void SwiperComponent::SetSwiperInterval(float interval) +{ + ArkUI_NumberValue value[] = { { .f32 = interval } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INTERVAL, &item); +} + +void SwiperComponent::SetSwiperDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_DIRECTION, &item); +} + +void SwiperComponent::SetSwiperIndicator(ArkUI_SwiperIndicator* indicator) +{ + ArkUI_NumberValue indicator_value[] = { { .i32 = ARKUI_SWIPER_INDICATOR_TYPE_DOT } }; + ArkUI_AttributeItem indicator_item = { indicator_value, sizeof(indicator_value) / sizeof(ArkUI_NumberValue), "", + indicator }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INDICATOR, &indicator_item); +} + +void SwiperComponent::SetSwiperToIndex(int32_t index, int32_t useAnimation) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = useAnimation } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_SWIPE_TO_INDEX, &item); +} + +void SwiperComponent::RegisterOnGesture(const std::function& onGesture) +{ + onGesture_ = onGesture; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_GESTURE_SWIPE, 0, nullptr); +} + +void SwiperComponent::RegisterOnChange(const std::function& onChange) +{ + onChange_ = onChange; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_CHANGE, 0, nullptr); +} + +void SwiperComponent::RegisterOnDidScrollContext(const std::function& onDid) +{ + onDid_ = onDid; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL, 0, nullptr); +} + +void SwiperComponent::RegisterOnAnimationStart(const std::function& onStart) +{ + onStart_ = onStart; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_ANIMATION_START, 0, nullptr); +} + +void SwiperComponent::RegisterOnAnimationEnd(const std::function& onEnd) +{ + onEnd_ = onEnd; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_ANIMATION_END, 0, nullptr); +} + +void SwiperComponent::OnNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + switch (eventType) { + case NODE_SWIPER_EVENT_ON_GESTURE_SWIPE: + if (onGesture_) { + onGesture_(event); + } + break; + case NODE_SWIPER_EVENT_ON_CHANGE: + if (onChange_) { + onChange_(event); + } + break; + case NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL: + if (onDid_) { + onDid_(event); + } + break; + case NODE_SWIPER_EVENT_ON_ANIMATION_START: + if (onStart_) { + onStart_(event); + } + break; + case NODE_SWIPER_EVENT_ON_ANIMATION_END: + if (onEnd_) { + onEnd_(event); + } + break; + default: + break; + } +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h new file mode 100644 index 0000000000000000000000000000000000000000..f8ee03c9875a802d61260ec9ffb231f12c1f96cb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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 CAPIDEMO_SWIPER_COMPONENT_H +#define CAPIDEMO_SWIPER_COMPONENT_H + +#include + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { +class SwiperComponent : public Component { +public: + SwiperComponent() : Component(ARKUI_NODE_SWIPER) {} + explicit SwiperComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetSwiperLoop(int32_t loop); + void SetSwiperAutoPlay(int32_t playValue); + void SetSwiperPrevMigration(float migration, int32_t ignoreBlank = false); + void SetSwiperNextMigration(float migration, int32_t ignoreBlank = false); + void SetSwiperDisplayCount(int32_t count); + void SetSwiperIndex(int32_t index); + void SetSwiperVertical(int32_t index); + void SetSwiperNestedScroll(int32_t nestedScroll); + void SetSwiperEffectMode(int32_t effect); + void SetSwiperInterval(float interval); + void SetSwiperDirection(int32_t direction); + void SetSwiperIndicator(ArkUI_SwiperIndicator* indicator); + void SetSwiperToIndex(int32_t index, int32_t useAnimation = false); + void RegisterOnGesture(const std::function& onGesture); + void RegisterOnChange(const std::function& onChange); + void RegisterOnDidScrollContext(const std::function& onDid); + void RegisterOnAnimationStart(const std::function& onStart); + void RegisterOnAnimationEnd(const std::function& onEnd); + void OnNodeEvent(ArkUI_NodeEvent* event) override; + + std::function onGesture_; + std::function onDid_; + std::function onChange_; + std::function onStart_; + std::function onEnd_; +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_SWIPER_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d7de2b2b9a21354658f2a31429384ef681673e7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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 "text_component.h" + +namespace ArkUICApiDemo { + +void TextComponent::SetFontSize(float fontSize) +{ + ArkUI_NumberValue value[] = { { .f32 = fontSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_SIZE, &item); +} +void TextComponent::SetFontColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_COLOR, &item); +} +void TextComponent::SetTextContent(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + _nodeAPI->setAttribute(_component, NODE_TEXT_CONTENT, &item); +} +void TextComponent::SetTextAlign(ArkUI_TextAlignment align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_TEXT_ALIGN, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h new file mode 100644 index 0000000000000000000000000000000000000000..ce370faaf3b9f1df9823c4c6b3cd1309a455b601 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_TEXT_COMPONENT_H +#define ARKUI_CAPI_DEMO_TEXT_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class TextComponent : public Component { +public: + TextComponent() : Component(ARKUI_NODE_TEXT) {} + explicit TextComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetFontSize(float fontSize) override; + void SetFontColor(uint32_t color); + void SetTextContent(const std::string& content); + void SetTextAlign(ArkUI_TextAlignment align); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXT_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..05fd85f3c34ed77a9d019c6244b4999b2bd3d29d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2024 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 "waterflow_component.h" + +namespace ArkUICApiDemo { + +void WaterFlowSectionOption::SetSection(int32_t index, WaterFlowSection section) +{ + OH_ArkUI_WaterFlowSectionOption_SetItemCount(_option, index, section.itemsCount); + OH_ArkUI_WaterFlowSectionOption_SetCrossCount(_option, index, section.crossCount); + OH_ArkUI_WaterFlowSectionOption_SetColumnGap(_option, index, section.columnsGap); + OH_ArkUI_WaterFlowSectionOption_SetRowGap(_option, index, section.rowsGap); + OH_ArkUI_WaterFlowSectionOption_SetMargin( + _option, index, section.margin.top, section.margin.right, section.margin.bottom, section.margin.left); + OH_ArkUI_WaterFlowSectionOption_RegisterGetItemMainSizeCallbackByIndex( + _option, index, section.onGetItemMainSizeByIndex); +} +WaterFlowSection WaterFlowSectionOption::GetSection(int32_t index) +{ + return { OH_ArkUI_WaterFlowSectionOption_GetItemCount(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetCrossCount(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetColumnGap(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetRowGap(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetMargin(_option, index) }; +} + +void WaterFlowSectionOption::SetSize(int32_t size) +{ + OH_ArkUI_WaterFlowSectionOption_SetSize(_option, size); +} +int32_t WaterFlowSectionOption::GetSize() +{ + return OH_ArkUI_WaterFlowSectionOption_GetSize(_option); +} + +void WaterFlowComponent::SetLayoutDirection(int32_t layoutDirection) +{ + ArkUI_NumberValue value[] = { { .i32 = layoutDirection } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_LAYOUT_DIRECTION, &item); +} + +void WaterFlowComponent::SetColumnsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_COLUMN_TEMPLATE, &item); +} + +void WaterFlowComponent::SetRowsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ROW_TEMPLATE, &item); +} + +void WaterFlowComponent::SetWaterFlowColumnsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_COLUMN_GAP, &item); +} + +void WaterFlowComponent::SetWaterFlowRowsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ROW_GAP, &item); +} + +void WaterFlowComponent::SetWaterFlowSectionOption(int32_t start, const std::shared_ptr& option) +{ + ArkUI_NumberValue value[] = { { .i32 = start } }; + ArkUI_AttributeItem item = { value, 1, nullptr, option->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SECTION_OPTION, &item); + _sectionsOption = option; +} + +void WaterFlowComponent::SetWaterFlowCachedCount(int32_t cachedCount) +{ + ArkUI_NumberValue value[] = { { .i32 = cachedCount } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_CACHED_COUNT, &item); +} + +void WaterFlowComponent::SetWaterFlowFooter(ArkUI_NodeHandle node) +{ + ArkUI_AttributeItem item = { .object = node }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_FOOTER, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index, int32_t animation) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index, int32_t animation, int32_t alignment) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = animation }, { .i32 = alignment } }; + ArkUI_AttributeItem item = { value, 3 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetItemConstraintSize(float minWidth, float maxWidth, float minHeight, float maxHeight) +{ + ArkUI_NumberValue value[] = { { .f32 = minWidth }, { .f32 = maxWidth }, { .f32 = minHeight }, + { .f32 = maxHeight } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ITEM_CONSTRAINT_SIZE, &item); +} +void WaterFlowComponent::SetWaterFlowNestedScroll(int32_t forward, int32_t backward) +{ + ArkUI_NumberValue value[] = { { .i32 = forward }, { .i32 = backward } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_NESTED_SCROLL, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBar(int32_t barState) +{ + ArkUI_NumberValue value[] = { { .i32 = barState } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_DISPLAY_MODE, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBarWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_WIDTH, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBarColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_COLOR, &item); +} +void WaterFlowComponent::SetWaterFlowEnableScrollInteraction(bool enableScrollInteraction) +{ + ArkUI_NumberValue value[] = { { .i32 = enableScrollInteraction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_SCROLL_INTERACTION, &item); +} +void WaterFlowComponent::SetWaterFlowFriction(float friction) +{ + ArkUI_NumberValue value[] = { { .f32 = friction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_FRICTION, &item); +} +void WaterFlowComponent::SetWaterFlowEdgeEffect(int32_t edgeEffect, bool alwaysEnabled) +{ + ArkUI_NumberValue value[] = { { .i32 = edgeEffect }, { .i32 = alwaysEnabled } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE_EFFECT, &item); +} +void WaterFlowComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +void WaterFlowComponent::SetScrollEdge(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE, &item); +} +void WaterFlowComponent::SetScrollPage(bool next) +{ + ArkUI_NumberValue value[] = { { .i32 = next } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void WaterFlowComponent::SetScrollPage(bool next, bool animation) +{ + ArkUI_NumberValue value[] = { { .i32 = next }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void WaterFlowComponent::SetScrollBy(float hDistance, float vDistance) +{ + ArkUI_NumberValue value[] = { { .f32 = hDistance }, { .f32 = vDistance } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BY, &item); +} +void WaterFlowComponent::OnNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + switch (eventType) { + case NODE_ON_WILL_SCROLL: { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + int32_t source = result->data[2].i32; + if (_onWillScroll) { + _onWillScroll(offset, state, source); + } + break; + } + case NODE_SCROLL_EVENT_ON_REACH_START: + if (_onReachStart) { + _onReachStart(); + } + break; + case NODE_SCROLL_EVENT_ON_REACH_END: + if (_onReachEnd) { + _onReachEnd(); + } + break; + case NODE_SCROLL_EVENT_ON_SCROLL_STOP: + if (_onScrollStop) { + _onScrollStop(); + } + break; + case NODE_WATER_FLOW_ON_DID_SCROLL: + if (_onDidScroll) { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + _onDidScroll(offset, state); + } + break; + case NODE_SCROLL_EVENT_ON_SCROLL_FRAME_BEGIN: + if (_onScrollFrameBegin) { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + _onScrollFrameBegin(offset, state); + } + break; + case NODE_WATER_FLOW_ON_SCROLL_INDEX: + if (_onScrollIndex) { + int32_t first = result->data[0].i32; + int32_t last = result->data[1].i32; + _onScrollIndex(first, last); + } + break; + default: + break; + } +} +void WaterFlowComponent::SetOnWillScroll(OnWillScroll onWillScroll) +{ + _onWillScroll = onWillScroll; + _nodeAPI->registerNodeEvent(_component, NODE_ON_WILL_SCROLL, 0, nullptr); +} +void WaterFlowComponent::SetOnReachStart(OnReachStart onReachStart) +{ + _onReachStart = onReachStart; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_REACH_START, 0, nullptr); +} +void WaterFlowComponent::SetOnReachEnd(OnReachEnd onReachEnd) +{ + _onReachEnd = onReachEnd; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_REACH_END, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollStop(OnScrollStop onScrollStop) +{ + _onScrollStop = onScrollStop; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_SCROLL_STOP, 0, nullptr); +} +void WaterFlowComponent::SetOnDidScroll(OnDidScroll onDidScroll) +{ + _onDidScroll = onDidScroll; + _nodeAPI->registerNodeEvent(_component, NODE_WATER_FLOW_ON_DID_SCROLL, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollFrameBegin(OnScrollFrameBegin onScrollFrameBegin) +{ + _onScrollFrameBegin = onScrollFrameBegin; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_SCROLL_FRAME_BEGIN, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollIndex(OnScrollIndex onScrollIndex) +{ + _onScrollIndex = onScrollIndex; + _nodeAPI->registerNodeEvent(_component, NODE_WATER_FLOW_ON_SCROLL_INDEX, 0, nullptr); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h new file mode 100644 index 0000000000000000000000000000000000000000..20196b3f7fe346740499c18893632a8e6690618e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H +#define ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H + +#include +#include + +#include "component.h" +#include "flowitem_component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { +using OnWillScroll = std::function; +using OnReachStart = std::function; +using OnReachEnd = std::function; +using OnScrollStop = std::function; +using OnDidScroll = std::function; +using OnScrollFrameBegin = std::function; +using OnScrollIndex = std::function; + +struct WaterFlowSection { + int32_t itemsCount = 0; + int32_t crossCount; + float columnsGap; + float rowsGap; + // top right bottom left + ArkUI_Margin margin { 0, 0, 0, 0 }; + float (*onGetItemMainSizeByIndex)(int32_t itemIndex); + void* userData; +}; + +class WaterFlowSectionOption { +public: + WaterFlowSectionOption() : _option(OH_ArkUI_WaterFlowSectionOption_Create()) {} + ~WaterFlowSectionOption() + { + OH_ArkUI_WaterFlowSectionOption_Dispose(_option); + } + void SetSection(int32_t index, WaterFlowSection section); + WaterFlowSection GetSection(int32_t index); + + void SetSize(int32_t size); + int32_t GetSize(); + ArkUI_WaterFlowSectionOption* GetOption() + { + return _option; + } + +private: + ArkUI_WaterFlowSectionOption* _option; +}; + +class WaterFlowComponent : public Component { +public: + WaterFlowComponent() : Component(ARKUI_NODE_WATER_FLOW) {} + explicit WaterFlowComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + // 引入懒加载模块。 + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetLayoutDirection(int32_t layoutDirection); + void SetColumnsTemplate(const std::string& str); + void SetRowsTemplate(const std::string& str); + void SetWaterFlowColumnsGap(float val); + void SetWaterFlowRowsGap(float val); + void SetWaterFlowSectionOption(int32_t start, const std::shared_ptr& option); + void SetWaterFlowCachedCount(int32_t cachedCount); + void SetWaterFlowFooter(ArkUI_NodeHandle node); + void SetWaterFlowScrollToIndex(int32_t index); + void SetWaterFlowScrollToIndex(int32_t index, int32_t animation); + void SetWaterFlowScrollToIndex(int32_t index, int32_t animation, int32_t alignment); + void SetItemConstraintSize(float minWidth, float maxWidth, float minHeight, float maxHeight); + void SetWaterFlowNestedScroll(int32_t forward, int32_t backward); + void SetWaterFlowScrollBar(int32_t barState); + void SetWaterFlowScrollBarWidth(float width); + void SetWaterFlowScrollBarColor(uint32_t color); + void SetWaterFlowEnableScrollInteraction(bool enableScrollInteraction); + void SetWaterFlowFriction(float friction); + void SetWaterFlowEdgeEffect(int32_t edgeEffect, bool alwaysEnabled); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + * [4] canOverScroll. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + void SetScrollEdge(int32_t type); + void SetScrollPage(bool next); + void SetScrollPage(bool next, bool animation); + void SetScrollBy(float hDistance, float vDistance); + + void OnNodeEvent(ArkUI_NodeEvent* event) override; + void SetOnWillScroll(OnWillScroll onWillScroll); + void SetOnReachStart(OnReachStart onReachStart); + void SetOnReachEnd(OnReachEnd onReachEnd); + void SetOnScrollStop(OnScrollStop onScrollStop); + void SetOnDidScroll(OnDidScroll onDidScroll); + void SetOnScrollFrameBegin(OnScrollFrameBegin onScrollFrameBegin); + void SetOnScrollIndex(OnScrollIndex onScrollIndex); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + std::shared_ptr GetSectionOption() const + { + return _sectionsOption; + } + void ReleaseSectionOption() + { + _sectionsOption.reset(); + } + +private: + std::shared_ptr _sectionsOption; + std::shared_ptr> _adapter; + + OnWillScroll _onWillScroll; + OnReachStart _onReachStart; + OnReachEnd _onReachEnd; + OnScrollStop _onScrollStop; + OnDidScroll _onDidScroll; + OnScrollFrameBegin _onScrollFrameBegin; + OnScrollIndex _onScrollIndex; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..356fbf2385b658009e6304d4d28bcbab059a6ece --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2024 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 "plugin_manager.h" + +#include +#include +#include + +#include "./common/common.h" + +namespace ArkUICApiDemo { +PluginManager PluginManager::pluginManager_; + +PluginManager::~PluginManager() +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", "~PluginManager"); + for (auto iter = nativeXComponentMap_.begin(); iter != nativeXComponentMap_.end(); ++iter) { + if (iter->second != nullptr) { + delete iter->second; + iter->second = nullptr; + } + } + nativeXComponentMap_.clear(); +} + +napi_value PluginManager::GetContext(napi_env env, napi_callback_info info) +{ + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "GetContext 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_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "GetContext napi_get_cb_info failed"); + } + + if (argCnt != 1) { + napi_throw_type_error(env, NULL, "Wrong number of arguments"); + return nullptr; + } + + napi_valuetype valuetype; + if (napi_typeof(env, args[0], &valuetype) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_typeof failed"); + return nullptr; + } + + if (valuetype != napi_number) { + napi_throw_type_error(env, NULL, "Wrong type of arguments"); + return nullptr; + } + + int64_t value; + if (napi_get_value_int64(env, args[0], &value) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_get_value_int64 failed"); + return nullptr; + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +void PluginManager::Export(napi_env env, napi_value exports) +{ + if ((env == nullptr) || (exports == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: env or exports is null"); + return; + } + + napi_value exportInstance = nullptr; + if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: napi_get_named_property fail"); + return; + } + + OH_NativeXComponent* nativeXComponent = nullptr; + if (napi_unwrap(env, exportInstance, reinterpret_cast(&nativeXComponent)) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: napi_unwrap fail"); + return; + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: napi_unwrap success"); + } + + char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = { '\0' }; + uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1; + if (OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize) != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "Export: OH_NativeXComponent_GetXComponentId fail"); + return; + } + + std::string id(idStr); + auto context = PluginManager::GetInstance(); + if ((context != nullptr) && (nativeXComponent != nullptr)) { + context->SetNativeXComponent(id, nativeXComponent); + } +} + +void PluginManager::SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent) +{ + if (nativeXComponent == nullptr) { + return; + } + + if (nativeXComponentMap_.find(id) == nativeXComponentMap_.end()) { + nativeXComponentMap_[id] = nativeXComponent; + return; + } + + if (nativeXComponentMap_[id] != nativeXComponent) { + OH_NativeXComponent* tmp = nativeXComponentMap_[id]; + delete tmp; + tmp = nullptr; + nativeXComponentMap_[id] = nativeXComponent; + } +} + +OH_NativeXComponent* PluginManager::GetNativeXComponent(std::string& id) +{ + if (nativeXComponentMap_.find(id) == nativeXComponentMap_.end()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", "GetNativeXComponent.%{public}s == nullptr", + id.c_str()); + return nullptr; + } + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "PluginManager", + "nativeXComponentMap_[%{public}s] == %{public}p", id.c_str(), nativeXComponentMap_[id]); + return nativeXComponentMap_[id]; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.h b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..a151d7e83b59691e2d4b18d430cfeb66aea5aaf4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/manager/plugin_manager.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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_XCOMPONENT_PLUGIN_MANAGER_H +#define NATIVE_XCOMPONENT_PLUGIN_MANAGER_H + +#include +#include +#include +#include +#include + +namespace ArkUICApiDemo { +class PluginManager { +public: + ~PluginManager(); + + static PluginManager* GetInstance() + { + return &PluginManager::pluginManager_; + } + + static napi_value GetContext(napi_env env, napi_callback_info info); + + void SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent); + OH_NativeXComponent* GetNativeXComponent(std::string& id); + void Export(napi_env env, napi_value exports); + +private: + static PluginManager pluginManager_; + + std::unordered_map nativeXComponentMap_; +}; +} // namespace ArkUICApiDemo +#endif // NATIVE_XCOMPONENT_PLUGIN_MANAGER_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0af1b4801b948f6f150612fd96cb3e9907205c0 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2024 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/plugin_manager.h" +#include "commonattrs/commonattrs_backgroundblurstyle_test.h" +#include "commonattrs/commonattrs_backgroundimage_test.h" +#include "commonattrs/commonattrs_backgroundimagesize_test.h" +#include "commonattrs/commonattrs_backgroundimageposition_test.h" +#include "commonattrs/commonattrs_brightness_test.h" +#include "commonattrs/commonattrs_saturate_test.h" +#include "commonattrs/commonattrs_blur_test.h" +#include "commonattrs/commonattrs_clipshape_test.h" +#include "commonattrs/commonattrs_customshadow_test.h" +#include "commonattrs/commonattrs_visibility_test.h" +#include "commonattrs/commonattrs_defaultfocus_test.h" +#include "commonattrs/commonattrs_focusstatus_test.h" +#include "commonattrs/commonattrs_aspectratio_test.h" +#include "commonattrs/commonattrs_foregroundcolor_test.h" +#include "commonattrs/commonattrs_markanchor_test.h" +#include "commonattrs/commonattrs_offset_test.h" +#include "commonattrs/commonattrs_overlay_test.h" +#include "commonattrs/commonattrs_responseregion_test.h" +#include "commonattrs/commonattrs_translate_test.h" +#include "commonattrs/commonattrs_touchable_test.h" +#include "commonattrs/commonattrs_rotate_test.h" +#include "commonattrs/commonattrs_rendergroup_test.h" +#include "commonattrs/commonattrs_layoutweight_test.h" +#include "commonattrs/commonattrs_displaypriority_test.h" +#include "commonattrs/commonattrs_outlinewidth_test.h" +#include "commonattrs/commonattrs_colorblend_test.h" +#include "commonattrs/commonattrs_chainmode_test.h" +#include "commonattrs/commonattrs_zindex_test.h" +#include "commonattrs/commonattrs_accessibilityrole_test.h" +#include "commonattrs/commonattrs_accessibilitystate_test.h" +#include "commonattrs/commonattrs_accessibilityvalue_test.h" +#include "commonattrs/commonattrs_focus_on_touch_test.h" +#include "commonattrs/commonattrs_alignment_test.h" +#include "commonattrs/commonattrs_padding_test.h" +#include "commonattrs/commonattrs_outlinecolor_test.h" +#include "commonattrs/commonattrs_size_test.h" + +using namespace ArkUICApiDemo; + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "Init begins"); + if ((env == nullptr) || (exports == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "env or exports is null"); + return nullptr; + } + + napi_property_descriptor desc[] = { + {"commonAttrsZIndexPage1Test", nullptr, CommonAttrsZIndexTest::CreateNativeNodePage1, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsZIndexPage2Test", nullptr, CommonAttrsZIndexTest::CreateNativeNodePage2, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsZIndexPage3Test", nullptr, CommonAttrsZIndexTest::CreateNativeNodePage3, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsSizeTest", nullptr, CommonAttrsSizeTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"commonAttrsPaddingTest", nullptr, CommonAttrsPaddingTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsAccessibilityRoleTest", nullptr, CommonAttrsAccessibilityRoleTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsAccessibilityStateTest", nullptr, CommonAttrsAccessibilityStateTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsAccessibilityValueTest", nullptr, CommonAttrsAccessibilityValueTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsFocusOnTouchTest", nullptr, CommonAttrsFocusOnTouchTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsAlignmentPage1Test", nullptr, CommonAttrsAlignmentTest::CreateNativeNodePage1, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsAlignmentPage2Test", nullptr, CommonAttrsAlignmentTest::CreateNativeNodePage2, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsAlignmentPage3Test", nullptr, CommonAttrsAlignmentTest::CreateNativeNodePage3, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsOutlineColorTest", nullptr, CommonAttrsOutlineColorTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsTranslateTest", nullptr, CommonAttrsTranslateTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsTouchAbleTest", nullptr, CommonAttrsTouchAbleTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsRotateTest", nullptr, CommonAttrsRotateTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsRenderGroupTest", nullptr, CommonAttrsRenderGroupTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsLayoutWeightTest", nullptr, CommonAttrsLayoutWeightTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsDisplayPriorityTest", nullptr, CommonAttrsDisplayPriorityTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsOutlineWidthTest", nullptr, CommonAttrsOutlineWidthTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsColorBlendTest", nullptr, CommonAttrsColorBlendTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsChainModeTest", nullptr, CommonAttrsChainModeTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsChainMode1Test", nullptr, CommonAttrsChainModeTest::CreateNativeNode1, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsChainMode2Test", nullptr, CommonAttrsChainModeTest::CreateNativeNode2, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsBackgroundBlurStyleTest", nullptr, CommonAttrsBackgroundBlurStyleTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsBackgroundImageResourceStrTest", nullptr, + CommonAttrsBackgroundImageTest::CreateNativeNodeResourceStr, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsBackgroundImagePixelMapTest", nullptr, CommonAttrsBackgroundImageTest::CreateNativeNodePixelMap, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsBackgroundImageSizeTest", nullptr, CommonAttrsBackgroundImageSizeTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsBackgroundImagePositionTest", nullptr, CommonAttrsBackgroundImagePositionTest::CreateNativeNode, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsBrightnessTest", nullptr, CommonAttrsBrightnessTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsSaturateTest", nullptr, CommonAttrsSaturateTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsBlurTest", nullptr, CommonAttrsBlurTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"commonAttrsClipShapeTest", nullptr, CommonAttrsClipShapeTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsCustomShadowTest", nullptr, CommonAttrsCustomShadowTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsVisibilityTest", nullptr, CommonAttrsVisibilityTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsDefaultFocusSingleTest", nullptr, CommonAttrsDefaultFocusTest::CreateNativeNodeSingle, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsDefaultFocusNoneTest", nullptr, CommonAttrsDefaultFocusTest::CreateNativeNodeNone, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsDefaultFocusMultiTest", nullptr, CommonAttrsDefaultFocusTest::CreateNativeNodeMulti, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsDefaultFocusAbnormalTest", nullptr, CommonAttrsDefaultFocusTest::CreateNativeNodeAbnormal, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"commonAttrsFocusStatusTest", nullptr, CommonAttrsFocusStatusTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsAspectRatioTest", nullptr, CommonAttrsAspectRatioTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsForegroundColorTest", nullptr, CommonAttrsForegroundColorTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + {"commonAttrsMarkAnchorTest", nullptr, CommonAttrsMarkAnchorTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsOffsetTest", nullptr, CommonAttrsOffsetTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsOverlayTest", nullptr, CommonAttrsOverlayTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"commonAttrsResponseRegionTest", nullptr, CommonAttrsResponseRegionTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr}, + }; + if (napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "napi_define_properties failed"); + return nullptr; + } + + ArkUICApiDemo::PluginManager::GetInstance()->Export(env, exports); + return exports; +} +EXTERN_C_END + +static napi_module nativerenderModule = {.nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "nativerender", + .nm_priv = ((void *)0), + .reserved = {0}}; + +extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&nativerenderModule); } \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/ruleOption.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/ruleOption.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c5b8a2399a2165b627fdbd6c180a59f4769856c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/ruleOption.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 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 "ruleOption.h" + +namespace ArkUICApiDemo { +using namespace std; + +void BarrierOption::SetBarrierStyle(const BarrierStyle& style, int32_t index) +{ + OH_ArkUI_BarrierOption_SetId(barrierOption_, style.id.c_str(), index); + OH_ArkUI_BarrierOption_SetDirection(barrierOption_, style.direction, index); + for (const auto& id : style.referencedId) { + OH_ArkUI_BarrierOption_SetReferencedId(barrierOption_, id.c_str(), index); + } +} + +BarrierStyle BarrierOption::GetBarrierStyle(int32_t index) const +{ + BarrierStyle style; + style.id = OH_ArkUI_BarrierOption_GetId(barrierOption_, index); + style.direction = OH_ArkUI_BarrierOption_GetDirection(barrierOption_, index); + return style; +} + +std::string BarrierOption::GetReferencedId(int32_t index, int32_t referencedIndex) const +{ + return OH_ArkUI_BarrierOption_GetReferencedId(barrierOption_, index, referencedIndex); +} + +int32_t BarrierOption::GetReferencedIdSize(int32_t index) const +{ + return OH_ArkUI_BarrierOption_GetReferencedIdSize(barrierOption_, index); +} + +void GuideLineOption::SetGuideLineStyle(const GuidelineStyle& style, int32_t index) +{ + OH_ArkUI_GuidelineOption_SetId(guideLineOption_, style.id.c_str(), index); + OH_ArkUI_GuidelineOption_SetDirection(guideLineOption_, style.direction, index); + if (style.start.has_value()) { + OH_ArkUI_GuidelineOption_SetPositionStart(guideLineOption_, style.start.value(), index); + } + if (style.end.has_value()) { + OH_ArkUI_GuidelineOption_SetPositionEnd(guideLineOption_, style.end.value(), index); + } +} + +GuidelineStyle GuideLineOption::GetGuideLineStyle(int32_t index) +{ + GuidelineStyle style; + style.id = OH_ArkUI_GuidelineOption_GetId(guideLineOption_, index); + style.direction = OH_ArkUI_GuidelineOption_GetDirection(guideLineOption_, index); + style.start = OH_ArkUI_GuidelineOption_GetPositionStart(guideLineOption_, index); + style.end = OH_ArkUI_GuidelineOption_GetPositionEnd(guideLineOption_, index); + return style; +} + +void RuleOption::SetAlignOption(AlignmentRuleOption ruleOption) +{ + OH_ArkUI_AlignmentRuleOption_SetStart(ruleOption_, ruleOption.left.anchor.c_str(), ruleOption.left.align); + OH_ArkUI_AlignmentRuleOption_SetEnd(ruleOption_, ruleOption.right.anchor.c_str(), ruleOption.right.align); + OH_ArkUI_AlignmentRuleOption_SetTop(ruleOption_, ruleOption.top.anchor.c_str(), ruleOption.top.align); + OH_ArkUI_AlignmentRuleOption_SetBottom(ruleOption_, ruleOption.bottom.anchor.c_str(), ruleOption.bottom.align); + OH_ArkUI_AlignmentRuleOption_SetCenterHorizontal( + ruleOption_, ruleOption.middle.anchor.c_str(), ruleOption.middle.align); + OH_ArkUI_AlignmentRuleOption_SetCenterVertical( + ruleOption_, ruleOption.center.anchor.c_str(), ruleOption.center.align); + OH_ArkUI_AlignmentRuleOption_SetBiasHorizontal(ruleOption_, ruleOption.biasHorizontal); + OH_ArkUI_AlignmentRuleOption_SetBiasVertical(ruleOption_, ruleOption.biasVertical); +} +AlignmentRuleOption RuleOption::GetAlignOption() +{ + AlignmentRuleOption ruleOption; + ruleOption.left.align = OH_ArkUI_AlignmentRuleOption_GetStartAlignment(ruleOption_); + ruleOption.right.align = OH_ArkUI_AlignmentRuleOption_GetEndAlignment(ruleOption_); + ruleOption.top.align = OH_ArkUI_AlignmentRuleOption_GetTopAlignment(ruleOption_); + ruleOption.bottom.align = OH_ArkUI_AlignmentRuleOption_GetBottomAlignment(ruleOption_); + ruleOption.middle.align = OH_ArkUI_AlignmentRuleOption_GetCenterAlignmentHorizontal(ruleOption_); + ruleOption.center.align = OH_ArkUI_AlignmentRuleOption_GetCenterAlignmentVertical(ruleOption_); + ruleOption.biasHorizontal = OH_ArkUI_AlignmentRuleOption_GetBiasHorizontal(ruleOption_); + ruleOption.biasVertical = OH_ArkUI_AlignmentRuleOption_GetBiasVertical(ruleOption_); + return ruleOption; +} + +RuleOptionId RuleOption::GetRuleOptionId() +{ + RuleOptionId ruleOptionId; + ruleOptionId.startId = OH_ArkUI_AlignmentRuleOption_GetStartId(ruleOption_); + ruleOptionId.endId = OH_ArkUI_AlignmentRuleOption_GetEndId(ruleOption_); + ruleOptionId.topId = OH_ArkUI_AlignmentRuleOption_GetTopId(ruleOption_); + ruleOptionId.bottomId = OH_ArkUI_AlignmentRuleOption_GetBottomId(ruleOption_); + ruleOptionId.centerIdHorizontal = OH_ArkUI_AlignmentRuleOption_GetCenterIdHorizontal(ruleOption_); + ruleOptionId.centerIdVertical = OH_ArkUI_AlignmentRuleOption_GetCenterIdVertical(ruleOption_); + return ruleOptionId; +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/ruleOption.h b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/ruleOption.h new file mode 100644 index 0000000000000000000000000000000000000000..00d5ae767feb53974cf681e397aab5dd338f28d4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/ruleOption.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_RULEOPTION_H +#define ARKUI_CAPI_DEMO_RULEOPTION_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { +struct BarrierStyle { + std::string id; + ArkUI_BarrierDirection direction; + std::vector referencedId; +}; + +class BarrierOption { +public: + explicit BarrierOption(int32_t size) : barrierOption_(OH_ArkUI_BarrierOption_Create(size)) {} + virtual ~BarrierOption() + { + OH_ArkUI_BarrierOption_Dispose(barrierOption_); + } + + void SetBarrierStyle(const BarrierStyle& style, int32_t index); + + BarrierStyle GetBarrierStyle(int32_t index) const; + std::string GetReferencedId(int32_t index, int32_t referencedIndex) const; + int32_t GetReferencedIdSize(int32_t index) const; + + ArkUI_BarrierOption* GetOption() + { + return barrierOption_; + } + +private: + ArkUI_BarrierOption* barrierOption_; +}; + +struct GuidelineStyle { + std::string id; + ArkUI_Axis direction; + std::optional start; + bool hasStart; + std::optional end; + bool hasEnd; +}; + +class GuideLineOption { +public: + explicit GuideLineOption(int32_t size) : guideLineOption_(OH_ArkUI_GuidelineOption_Create(size)) {} + virtual ~GuideLineOption() + { + OH_ArkUI_GuidelineOption_Dispose(guideLineOption_); + } + + void SetGuideLineStyle(const GuidelineStyle& style, int32_t index); + GuidelineStyle GetGuideLineStyle(int32_t index); + ArkUI_GuidelineOption* GetOption() + { + return guideLineOption_; + } + +private: + ArkUI_GuidelineOption* guideLineOption_ = nullptr; +}; + +struct HorizontalAlignRule { + bool hasValue; + std::string anchor; + ArkUI_HorizontalAlignment align; +}; + +struct VerticalAlignRule { + bool hasValue; + std::string anchor; + ArkUI_VerticalAlignment align; +}; + +struct AlignmentRuleOption { + HorizontalAlignRule left; + HorizontalAlignRule middle; + HorizontalAlignRule right; + VerticalAlignRule top; + VerticalAlignRule center; + VerticalAlignRule bottom; + float biasHorizontal; + float biasVertical; +}; + +struct RuleOptionId { + std::string startId; + std::string endId; + std::string topId; + std::string bottomId; + std::string centerIdHorizontal; + std::string centerIdVertical; +}; + +class RuleOption { +public: + RuleOption() : ruleOption_(OH_ArkUI_AlignmentRuleOption_Create()) {} + virtual ~RuleOption() + { + OH_ArkUI_AlignmentRuleOption_Dispose(ruleOption_); + } + void SetAlignOption(AlignmentRuleOption ruleOption); + AlignmentRuleOption GetAlignOption(); + RuleOptionId GetRuleOptionId(); + ArkUI_AlignmentRuleOption* GetOption() + { + return ruleOption_; + } + +private: + ArkUI_AlignmentRuleOption* ruleOption_; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_RULEOPTION_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/rule_option_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/rule_option_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..809c85ad8f80f1142322fdfa4ae5d62812037376 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/rule_option_test.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2024 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 "rule_option_test.h" + +#include +#include +#include + +#include "../manager/plugin_manager.h" +#include "arkui/native_node.h" +#include "column_component.h" +#include "component/row_component.h" + +namespace ArkUICApiDemo { +using namespace std; +std::shared_ptr CreateTestRow( + std::string id, uint32_t color = COLOR_RED, std::shared_ptr ruleOption = nullptr) +{ + auto row = std::make_shared(); + row->SetWidth(50.0); + row->SetHeight(50.0); + row->SetId(id); + if (ruleOption) { + row->SetAlignRules(ruleOption->GetOption()); + } + row->SetBackgroundColor(color); + return row; +} + +std::shared_ptr CreateTestColumn(std::vector> rows) +{ + auto column = std::make_shared(); + column->SetMargin(5); + auto relativeContainer = std::make_shared(); + relativeContainer->SetWidth(200); + relativeContainer->SetHeight(200); + relativeContainer->SetBorderWidth(2); + relativeContainer->SetBorderColor(COLOR_BLUE, COLOR_BLUE, COLOR_BLUE, COLOR_BLUE); + for (auto row : rows) { + relativeContainer->AddChild(row); + } + column->AddChild(relativeContainer); + return column; +} + +static shared_ptr CreateTestRows(string id, shared_ptr ruleOption, uint32_t color) +{ + auto row = std::make_shared(); + row->SetWidth(50.0); + row->SetHeight(50.0); + row->SetId(id); + row->SetAlignRules(ruleOption->GetOption()); + row->SetBackgroundColor(color); + return row; +} +napi_value RuleOptionTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RelativeContainerGuideLineTest", "CreateNativeNode"); + + size_t argc = 1; + napi_value args[1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = 64; + size_t strLength = 0; + char xComponentID[64] = { 0 }; + napi_get_value_string_utf8(env, args[0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ButtonBackgroundColorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create ruleOption + HorizontalAlignRule start { .align = ARKUI_HORIZONTAL_ALIGNMENT_START, .anchor = "__container__" }; + HorizontalAlignRule end { .align = ARKUI_HORIZONTAL_ALIGNMENT_END, .anchor = "__container__" }; + VerticalAlignRule top { .align = ARKUI_VERTICAL_ALIGNMENT_TOP, .anchor = "__container__" }; + VerticalAlignRule bottom { .align = ARKUI_VERTICAL_ALIGNMENT_BOTTOM, .anchor = "__container__" }; + HorizontalAlignRule middle { .align = ARKUI_HORIZONTAL_ALIGNMENT_CENTER, .anchor = "__container__" }; + VerticalAlignRule center { .align = ARKUI_VERTICAL_ALIGNMENT_CENTER, .anchor = "__container__" }; + + auto horizontalAlignment1 = static_cast(-1); + auto horizontalAlignment2 = static_cast(3); + auto verticalAlignment1 = static_cast(-1); + auto verticalAlignment2 = static_cast(3); + + HorizontalAlignRule start2 { .align = horizontalAlignment1, .anchor = "__container__" }; + HorizontalAlignRule end2 { .align = horizontalAlignment1, .anchor = "__container__" }; + VerticalAlignRule top2 { .align = verticalAlignment1, .anchor = "__container__" }; + VerticalAlignRule bottom2 { .align = verticalAlignment1, .anchor = "__container__" }; + HorizontalAlignRule middle2 { .align = horizontalAlignment1, .anchor = "__container__" }; + VerticalAlignRule center2 { .align = verticalAlignment1, .anchor = "__container__" }; + + HorizontalAlignRule start3 { .align = horizontalAlignment2, .anchor = "__container__" }; + HorizontalAlignRule end3 { .align = horizontalAlignment2, .anchor = "__container__" }; + VerticalAlignRule top3 { .align = verticalAlignment2, .anchor = "__container__" }; + VerticalAlignRule bottom3 { .align = verticalAlignment2, .anchor = "__container__" }; + HorizontalAlignRule middle3 { .align = horizontalAlignment2, .anchor = "__container__" }; + VerticalAlignRule center3 { .align = verticalAlignment2, .anchor = "__container__" }; + + auto rule1 = std::make_shared(); + AlignmentRuleOption ruleOption1 { .left = start, .right = end, .top = top, .bottom = bottom }; + rule1->SetAlignOption(ruleOption1); + + auto rule2 = std::make_shared(); + AlignmentRuleOption ruleOption2 { .left = start, .bottom = bottom }; + rule2->SetAlignOption(ruleOption2); + + auto rule3 = std::make_shared(); + AlignmentRuleOption ruleOption3 { .right = end, .bottom = bottom }; + rule3->SetAlignOption(ruleOption3); + + auto rule4 = std::make_shared(); + AlignmentRuleOption ruleOption4 { .right = end, .top = top }; + rule4->SetAlignOption(ruleOption4); + + auto rule5 = std::make_shared(); + AlignmentRuleOption ruleOption5 { .middle = middle, .center = center }; + rule5->SetAlignOption(ruleOption5); + + auto rule6 = std::make_shared(); + AlignmentRuleOption ruleOption6 { + .biasVertical = 1, .biasHorizontal = 1, .left = start, .right = end, .top = top, .bottom = bottom + }; + rule6->SetAlignOption(ruleOption6); + + auto rule7 = std::make_shared(); + AlignmentRuleOption ruleOption7 { + .biasVertical = 0, .biasHorizontal = 0, .left = start, .right = end, .top = top, .bottom = bottom + }; + rule7->SetAlignOption(ruleOption7); + + auto rule8 = std::make_shared(); + AlignmentRuleOption ruleOption8 { + .biasVertical = -0.3, .biasHorizontal = -0.3, .left = start, .right = end, .top = top, .bottom = bottom + }; + rule8->SetAlignOption(ruleOption8); + + auto rule9 = std::make_shared(); + AlignmentRuleOption ruleOption9 { + .middle = middle2, .center = center2, .left = start2, .right = end2, .top = top2, .bottom = bottom2 + }; + rule9->SetAlignOption(ruleOption9); + + auto rule10 = std::make_shared(); + AlignmentRuleOption ruleOption10 { + .middle = middle3, .center = center3, .left = start3, .right = end3, .top = top3, .bottom = bottom3 + }; + rule10->SetAlignOption(ruleOption10); + + // create row + auto row1 = CreateTestRow("row1", COLOR_RED, rule1); + auto row2 = CreateTestRow("row2", COLOR_BLUE, rule2); + auto row3 = CreateTestRow("row3", COLOR_YELLOW, rule3); + auto row4 = CreateTestRow("row4", COLOR_LIGHT_BLUE, rule4); + auto row5 = CreateTestRow("row5", COLOR_GRAY, rule5); + auto row6 = CreateTestRow("row6", COLOR_RED, rule6); + auto row7 = CreateTestRow("row7", COLOR_YELLOW, rule7); + auto row8 = CreateTestRow("row8", COLOR_GREEN, rule8); + auto row9 = CreateTestRow("row9", COLOR_GREEN, rule9); + auto row10 = CreateTestRow("row10", COLOR_RED, rule10); + auto row11 = CreateTestRow("row11", COLOR_WHITE); + + auto column1 = CreateTestColumn({ row1, row2, row3, row4, row5 }); + auto column2 = CreateTestColumn({ row6, row7, row8 }); + row11->AddChild(row9); + row11->AddChild(row10); + auto column3 = CreateTestColumn({ row11 }); + + auto ruleOptionId1 = rule6->GetRuleOptionId(); + auto ruleOptionId2 = rule5->GetRuleOptionId(); + auto alignOption1 = rule6->GetAlignOption(); + auto alignOption2 = rule5->GetAlignOption(); + if (alignOption1.left.align == start.align && alignOption1.right.align == end.align && + alignOption1.top.align == top.align && alignOption1.bottom.align == bottom.align && + alignOption2.center.align == center.align && center.align && alignOption2.middle.align == middle.align && + ruleOptionId1.startId == "__container__" && ruleOptionId1.endId == "__container__" && + ruleOptionId1.topId == "__container__" && ruleOptionId1.bottomId == "__container__" && + ruleOptionId2.centerIdHorizontal == "__container__" && ruleOptionId2.centerIdVertical == "__container__") { + column1->SetBackgroundColor(COLOR_GREEN); + } + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(column, column1->GetComponent()); + nodeAPI->addChild(column, column2->GetComponent()); + nodeAPI->addChild(column, column3->GetComponent()); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RelativeContainerGuideLineTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, NULL, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/rule_option_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/rule_option_test.h new file mode 100644 index 0000000000000000000000000000000000000000..af86c787949104dd6dc9d0f4e10417595e212ede --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/relativeContainer/rule_option_test.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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 ARKUI_CAPI_DEMO_RULE_OPTION_TEST_H +#define ARKUI_CAPI_DEMO_RULE_OPTION_TEST_H +#include "../common/common.h" +#include "../component/relativecontainer_component.h" + +namespace ArkUICApiDemo { +class RuleOptionTest { +public: + ~RuleOptionTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RULE_OPTION_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c78100bd580de63f02625520d4737a0e996f4fe7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 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. + */ + +export const commonAttrsBackgroundBlurStyleTest: (a: string) => void; + +export const commonAttrsBackgroundImageResourceStrTest: (a: string) => void; + +export const commonAttrsBackgroundImagePixelMapTest: (a: string) => void; + +export const commonAttrsBackgroundImageSizeTest: (a: string) => void; + +export const commonAttrsBackgroundImagePositionTest: (a: string) => void; + +export const commonAttrsBrightnessTest: (a: string) => void; + +export const commonAttrsSaturateTest: (a: string) => void; + +export const commonAttrsBlurTest: (a: string) => void; + +export const commonAttrsClipShapeTest: (a: string) => void; + +export const commonAttrsCustomShadowTest: (a: string) => void; + +export const commonAttrsVisibilityTest: (a: string) => void; + +export const commonAttrsDefaultFocusSingleTest: (a: string) => void; + +export const commonAttrsDefaultFocusNoneTest: (a: string) => void; + +export const commonAttrsDefaultFocusMultiTest: (a: string) => void; + +export const commonAttrsDefaultFocusAbnormalTest: (a: string) => void; + +export const commonAttrsFocusStatusTest: (a: string) => void; + +export const commonAttrsAspectRatioTest: (a: string) => void; + +export const commonAttrsForegroundColorTest: (a: string) => void; + +export const commonAttrsMarkAnchorTest: (a: string) => void; + +export const commonAttrsOffsetTest: (a: string) => void; + +export const commonAttrsOverlayTest: (a: string) => void; + +export const commonAttrsResponseRegionTest: (a: string) => void; + +export const commonAttrsZIndexPage1Test: (a: string) => void; + +export const commonAttrsZIndexPage2Test: (a: string) => void; + +export const commonAttrsZIndexPage3Test: (a: string) => void; + +export const commonAttrsOutlineColorTest: (a: string) => void; + +export const commonAttrsSizeTest: (a: string) => void; + +export const commonAttrsAccessibilityRoleTest: (a: string) => void; + +export const commonAttrsAccessibilityStateTest: (a: string) => void; + +export const commonAttrsAccessibilityValueTest: (a: string) => void; + +export const commonAttrsFocusOnTouchTest: (a: string) => void; + +export const commonAttrsAlignmentPage1Test: (a: string) => void; + +export const commonAttrsAlignmentPage2Test: (a: string) => void; + +export const commonAttrsAlignmentPage3Test: (a: string) => void; + +export const commonAttrsPaddingTest: (a: string) => void; + +export const commonAttrsTranslateTest: (a: string) => void; + +export const commonAttrsTouchAbleTest: (a: string) => void; + +export const commonAttrsRotateTest: (a: string) => void; + +export const commonAttrsRenderGroupTest: (a: string) => void; + +export const commonAttrsLayoutWeightTest: (a: string) => void; + +export const commonAttrsDisplayPriorityTest: (a: string) => void; + +export const commonAttrsOutlineWidthTest: (a: string) => void; + +export const commonAttrsChainModeTest: (a: string) => void; + +export const commonAttrsChainMode1Test: (a: string) => void; + +export const commonAttrsChainMode2Test: (a: string) => void; + +export const commonAttrsColorBlendTest: (a: string) => void; \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70466261f5936d9f1f412c12bea873a6fb3a522c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libnativerender.so", + "types": "./index.d.ts", + "version": "0.1.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8fc7e79adb1ff2e33ead7f07174ed044bb1b5fcf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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 { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..dc094b13d3162617b1089a984e5b598a9e6b4a45 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets b/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a295be0daf9df23471c8559e61f062b70f31a8d7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 render from "libnativerender.so" +@Entry +@Component +struct Index { + build() { + Column() { + Column() { + + XComponent({ + id: 'xComponentId', + type: XComponentType.NODE, + libraryname: 'nativerender' + }).onDestroy(() => { + console.log('onDestroy'); + }).onAppear(() => { + + }).width('100%') + .height('100%') + }.margin({ + top: 27, + left: 12, + right: 12 + }) + .height('100%') + .width('100%') + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/module.json5 b/function/ui_compare/capidemo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aa0ed1bad179e91b0e7d4f9d7e84f7f83c25a33a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/module.json5 @@ -0,0 +1,45 @@ +{ + "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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json b/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/function/ui_compare/capidemo/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/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png new file mode 100644 index 0000000000000000000000000000000000000000..385aee55284cd8a5ebde3910bf82c494f057fecf Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png new file mode 100644 index 0000000000000000000000000000000000000000..742044d80325e183663d8dffd8a2e5a37c6bed90 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..1fa2f73575caef6b5fcf736b6eb2e8ff34802713 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png new file mode 100644 index 0000000000000000000000000000000000000000..adb226051b3771a741509382c683606d029e5b25 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json b/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/function/ui_compare/capidemo/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/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg b/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg new file mode 100644 index 0000000000000000000000000000000000000000..36a19cd6b90bb98511116f5015c74fe2f860249d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..597ecf95e61d7e30367c22fe2f8638008361b044 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..35d7138e9c498ded1b55d2daf4f9d58630841647 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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 AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log('[Demo] MyAbilityStage onCreate'); + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..bb42e0040a8974b56a591f1e662fe7b7e64842d5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 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 Ability from '@ohos.app.ability.UIAbility'; +import Settings from '../test/common/Settings'; + +const TAG: string = '[createWindow]' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log(`${TAG} MainAbility onCreate`); + globalThis.abilityWant = want; + globalThis.abilityLaunchParam = launchParam; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log(`${TAG} MainAbility onDestroy`); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log(`${TAG} MainAbility onWindowStageCreate windowStage=` + windowStage); + globalThis.windowStage = windowStage; + globalThis.context = this.context; + + setTimeout(() => { + console.info(`${TAG} setTimeout`) + Settings.createWindow('MainAbility/pages/DemoIndex', { + width: 720, height: 1280, dpi: 230 + }) + }, 1000) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log(`${TAG} MainAbility onWindowStageDestroy`); + } + + onForeground() { + // Ability has brought to foreground + console.log(`${TAG} MainAbility onForeground`); + } + + onBackground() { + // Ability has back to background + console.log(`${TAG} MainAbility onBackground`); + } +}; \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets new file mode 100644 index 0000000000000000000000000000000000000000..a049a87977058169ed5625795b248d3aa773bb1e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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. + */ + +@Component +export struct CommonView { + pageTag: string = ''; + + build() { + Column() { + Column({ space: 10 }) { + XComponent({ + id: this.pageTag, + type: 'node', + libraryname: 'nativerender' + }).onDestroy(() => { + console.log('onDestroy'); + }).backgroundColor('#FFEEEEEE') + .width('100%') + .height('100%') + }.margin(20) + .height('100%') + .width('100%') + } + .id(this.pageTag) + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e9adc265a2b3e7260371437cdedd90608f51df5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../../test/List.test'; + +@Entry +@Component +struct DemoIndex { + aboutToAppear() { + setTimeout(() => { + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, 2000) + } + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('ARKUI CAPI DEMO') + .fontSize(36) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityRoleTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityRoleTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..031b9934afb00c6536d6ec4272a9819c38c42686 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityRoleTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAccessibilityRoleTest { + PAGE_TAG: string = 'CommonAttrsAccessibilityRoleTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAccessibilityRoleTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityStateTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityStateTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..dcd0b385a779a76abb8dcffdd871c643886629d8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityStateTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAccessibilityStateTest { + PAGE_TAG: string = 'CommonAttrsAccessibilityStateTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAccessibilityStateTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityValueTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityValueTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..10f5de85647568b0541992537d5de7569587d4e2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAccessibilityValueTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAccessibilityValueTest { + PAGE_TAG: string = 'CommonAttrsAccessibilityValueTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAccessibilityValueTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6c1344baf0bb820ba7a118b28fa300ef126fa22 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage1Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAlignmentPage1Test { + PAGE_TAG: string = 'CommonAttrsAlignmentPage1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAlignmentPage1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b51adb07cfde2d6beeba113c4e02eb05e9f70fa --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage2Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAlignmentPage2Test { + PAGE_TAG: string = 'CommonAttrsAlignmentPage2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAlignmentPage2Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage3Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage3Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b259960754f9d55ae42dc5089eafb02d9b605bc3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAlignmentPage3Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAlignmentPage3Test { + PAGE_TAG: string = 'CommonAttrsAlignmentPage3Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAlignmentPage3Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAspectRatioTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAspectRatioTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d9f36362bc4807a2658122ddf50399e4b8e0d14 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsAspectRatioTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsAspectRatioTest { + PAGE_TAG: string = 'CommonAttrsAspectRatioTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsAspectRatioTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundBlurStyleTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundBlurStyleTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..8fc058a380f02d466ef204d4dfdae16a62f7a34c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundBlurStyleTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBackgroundBlurStyleTest { + PAGE_TAG: string = 'CommonAttrsBackgroundBlurStyleTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBackgroundBlurStyleTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePixelMapTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePixelMapTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5f91a9bf93fdad31b1c59b28c59aaf45bbfa13e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePixelMapTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBackgroundImagePixelMapTest { + PAGE_TAG: string = 'CommonAttrsBackgroundImagePixelMapTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBackgroundImagePixelMapTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePositionTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePositionTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..15debc0cfeaff4f63320b0223b8ced992326bb01 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePositionTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBackgroundImagePositionTest { + PAGE_TAG: string = 'CommonAttrsBackgroundImagePositionTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBackgroundImagePositionTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImageResourceStrTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImageResourceStrTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ca32974a78e5a3553be4f7757b83bdc8c3ff144 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImageResourceStrTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBackgroundImageResourceStrTest { + PAGE_TAG: string = 'CommonAttrsBackgroundImageResourceStrTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBackgroundImageResourceStrTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImageSizeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImageSizeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..838b49c0731f4e8b1ee3d1df04fe3d5c83c62a67 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBackgroundImageSizeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBackgroundImageSizeTest { + PAGE_TAG: string = 'CommonAttrsBackgroundImageSizeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBackgroundImageSizeTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBlurTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBlurTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..b28e02ae58538e9e0d986bff9bf8e5c94ba5e7b8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBlurTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBlurTest { + PAGE_TAG: string = 'CommonAttrsBlurTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBlurTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBrightnessTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBrightnessTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4ec5c89a64a82cb112381cdca3ff630be43c2eb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsBrightnessTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsBrightnessTest { + PAGE_TAG: string = 'CommonAttrsBrightnessTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsBrightnessTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainMode1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainMode1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8cf54637208e8269bfd1ca14f9c973f4e69972dc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainMode1Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsChainMode1Test { + PAGE_TAG: string = 'CommonAttrsChainMode1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsChainMode1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainMode2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainMode2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6bc2bddf28a402d8fd8b8a92c08426032cdc513 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainMode2Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsChainMode2Test { + PAGE_TAG: string = 'CommonAttrsChainMode2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsChainMode2Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainModeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainModeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..4dd4acec8b48054ad9a6d0cc2ea1ac8c8f8559f4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsChainModeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsChainModeTest { + PAGE_TAG: string = 'CommonAttrsChainModeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsChainModeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsClipShapeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsClipShapeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..39ea2af6ed877751ef63272fd2225c32c9a92ad6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsClipShapeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsClipShapeTest { + PAGE_TAG: string = 'CommonAttrsClipShapeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsClipShapeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsColorBlendTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsColorBlendTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b0e351ef1201a00233390fabbb4fb51efc65636 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsColorBlendTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsColorBlendTest { + PAGE_TAG: string = 'CommonAttrsColorBlendTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsColorBlendTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsCustomShadowTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsCustomShadowTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..657862affa9294851a58bffa95749f94536aeee2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsCustomShadowTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsCustomShadowTest { + PAGE_TAG: string = 'CommonAttrsCustomShadowTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsCustomShadowTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c12e6d4934afa342a5307f746f039df1babbae34 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusAbnormalTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsDefaultFocusAbnormalTest { + PAGE_TAG: string = 'CommonAttrsDefaultFocusAbnormalTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsDefaultFocusAbnormalTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusMultiTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusMultiTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e01fd799552b71d753568dfdfd1f568a02f567d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusMultiTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsDefaultFocusMultiTest { + PAGE_TAG: string = 'CommonAttrsDefaultFocusMultiTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsDefaultFocusMultiTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusNoneTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusNoneTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..7eead6febc1697e75f52732b844e563b1c462729 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusNoneTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsDefaultFocusNoneTest { + PAGE_TAG: string = 'CommonAttrsDefaultFocusNoneTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsDefaultFocusNoneTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusSingleTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusSingleTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..0552f0d31a3365fa31e61168b64fe90a8ec12a38 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDefaultFocusSingleTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsDefaultFocusSingleTest { + PAGE_TAG: string = 'CommonAttrsDefaultFocusSingleTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsDefaultFocusSingleTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDisplayPriorityTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDisplayPriorityTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..2166707cc1d802073fdd9246a70d65c87e3e3910 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsDisplayPriorityTest.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsDisplayPriorityTest { + PAGE_TAG: string = 'CommonAttrsDisplayPriorityTest'; + PARENT_CONTAINER: number = 3; + DIRECTION: number = 2; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsDisplayPriorityTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsFocusOnTouchTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsFocusOnTouchTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c1afbfa2b0e8c178e728048bca888620478ed9b4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsFocusOnTouchTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsFocusOnTouchTest { + PAGE_TAG: string = 'CommonAttrsFocusOnTouchTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsFocusOnTouchTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsFocusStatusTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsFocusStatusTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..d31f8a3a9996cf46c275f111c9fe18e3e94e1182 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsFocusStatusTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsFocusStatusTest { + PAGE_TAG: string = 'CommonAttrsFocusStatusTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsFocusStatusTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsForegroundColorTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsForegroundColorTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..571a2b1c3470a774c91a31d93e029802322ee09e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsForegroundColorTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsForegroundColorTest { + PAGE_TAG: string = 'CommonAttrsForegroundColorTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsForegroundColorTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsLayoutWeightTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsLayoutWeightTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..470b7b77510d3ea95e977f8f7f2b406665f8637d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsLayoutWeightTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsLayoutWeightTest { + PAGE_TAG: string = 'CommonAttrsLayoutWeightTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsLayoutWeightTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsMarkAnchorTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsMarkAnchorTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..8cd220950577f7244c9a86b4588a3249a75e1416 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsMarkAnchorTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsMarkAnchorTest { + PAGE_TAG: string = 'CommonAttrsMarkAnchorTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsMarkAnchorTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOffsetTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOffsetTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..df4b0bdddaaa588cacb1ee34a6461cc4b6d08b89 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOffsetTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsOffsetTest { + PAGE_TAG: string = 'CommonAttrsOffsetTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsOffsetTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOutlineColorTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOutlineColorTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..15f932b9e2f324e5b1b3df09eaeb7bc52466c8cf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOutlineColorTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsOutlineColorTest { + PAGE_TAG: string = 'CommonAttrsOutlineColorTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsOutlineColorTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOutlineWidthTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOutlineWidthTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..a46b11b32d73ef8f0cff42101fa47e989332a5fc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOutlineWidthTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsOutlineWidthTest { + PAGE_TAG: string = 'CommonAttrsOutlineWidthTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsOutlineWidthTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOverlayTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOverlayTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..ea4c73a7cc0ab419e64f35ffb0a82ff02a3efdab --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsOverlayTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsOverlayTest { + PAGE_TAG: string = 'CommonAttrsOverlayTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsOverlayTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsPaddingTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsPaddingTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..487fdcf03e5dc35bdb0b562b0d085e1c1e9e70be --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsPaddingTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsPaddingTest { + PAGE_TAG: string = 'CommonAttrsPaddingTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsPaddingTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsRenderGroupTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsRenderGroupTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9a33f12472da0b7d26b1e97eeea9795a19fe10a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsRenderGroupTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsRenderGroupTest { + PAGE_TAG: string = 'CommonAttrsRenderGroupTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsRenderGroupTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsResponseRegionTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsResponseRegionTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..0483c4c34266e12ac2a916d256bf28a62fe92239 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsResponseRegionTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsResponseRegionTest { + PAGE_TAG: string = 'CommonAttrsResponseRegionTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsResponseRegionTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsRotateTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsRotateTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..2244da5889ae28075a1bc464fa70e3052b2918e1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsRotateTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsRotateTest { + PAGE_TAG: string = 'CommonAttrsRotateTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsRotateTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsSaturateTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsSaturateTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..7cae215af3a59e32b90ea2b9294f645b558a8ee3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsSaturateTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsSaturateTest { + PAGE_TAG: string = 'CommonAttrsSaturateTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsSaturateTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsSizeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsSizeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b16aa6c1722664b166af3ec56caa38be276682c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsSizeTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsSizeTest { + PAGE_TAG: string = 'CommonAttrsSizeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsSizeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsTouchAbleTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsTouchAbleTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..63ee74f45f68dca0507c7740cf2c1292dd440548 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsTouchAbleTest.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsTouchAbleTest { + PAGE_TAG: string = 'CommonAttrsTouchAbleTest'; + PARENT_CONTAINER: number = 3; + DIRECTION: number = 3; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsTouchAbleTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsTranslateTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsTranslateTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4cee9b62ebb0e3c610006d25d01be0036f445f2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsTranslateTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsTranslateTest { + PAGE_TAG: string = 'CommonAttrsTranslateTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsTranslateTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsVisibilityTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsVisibilityTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b9bbfade0411844ec89021c96d1b8aecc976948 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsVisibilityTest.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsVisibilityTest { + PAGE_TAG: string = 'CommonAttrsVisibilityTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsVisibilityTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5689aeafcd312458f49c5ecc1bcea588e961932f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage1Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsZIndexPage1Test { + PAGE_TAG: string = 'CommonAttrsZIndexPage1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsZIndexPage1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d016f0aaa7679f473031e75ec2030a1005e2a187 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage2Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsZIndexPage2Test { + PAGE_TAG: string = 'CommonAttrsZIndexPage2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsZIndexPage2Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage3Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage3Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca2d21b12f1995a3143ba38f8c89375f7ecaabd5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/commonattrs/CommonAttrsZIndexPage3Test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct CommonAttrsZIndexTestPage3 { + PAGE_TAG: string = 'CommonAttrsZIndexTestPage3'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.commonAttrsZIndexPage3Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..72e54668b7f98ce6a0a17cc864a3dbbfe17ae497 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 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 commonAttrsZIndexTest from './commonattrs/CommonAttrsZIndexTest.test' +import commonAttrsOutlineColorTest from './commonattrs/CommonAttrsOutlineColorTest.test' +import commonAttrsSizeTest from './commonattrs/CommonAttrsSizeTest.test' +import commonAttrsPaddingTest from './commonattrs/CommonAttrsPaddingTest.test' +import commonAttrsAccessibilityRoleTest from './commonattrs/CommonAttrsAccessibilityRoleTest.test' +import commonAttrsAccessibilityStateTest from './commonattrs/CommonAttrsAccessibilityStateTest.test' +import commonAttrsAccessibilityValueTest from './commonattrs/CommonAttrsAccessibilityValueTest.test' +import commonAttrsFocusOnTouchTest from './commonattrs/CommonAttrsFocusOnTouchTest.test' +import commonAttrsAlignmentTest from './commonattrs/CommonAttrsAlignmentTest.test' +import commonAttrsTranslateTest from './commonattrs/CommonAttrsTranslateTest.test' +import commonAttrsTouchAbleTest from './commonattrs/CommonAttrsTouchAbleTest.test' +import commonAttrsRotateTest from './commonattrs/CommonAttrsRotateTest.test' +import commonAttrsRenderGroupTest from './commonattrs/CommonAttrsRenderGroupTest.test' +import commonAttrsLayoutWeightTest from './commonattrs/CommonAttrsLayoutWeightTest.test' +import commonAttrsDisplayPriorityTest from './commonattrs/CommonAttrsDisplayPriorityTest.test' +import commonAttrsOutlineWidthTest from './commonattrs/CommonAttrsOutlineWidthTest.test' +import commonAttrsColorBlendTest from './commonattrs/CommonAttrsColorBlendTest.test' +import commonAttrsChainModeTest from './commonattrs/CommonAttrsChainModeTest.test' +import commonAttrsBackgroundBlurStyleTest from './commonattrs/CommonAttrsBackgroundBlurStyleTest.test' +import commonAttrsBackgroundImageTest from './commonattrs/CommonAttrsBackgroundImageTest.test' +import commonAttrsBackgroundImageSizeTest from './commonattrs/CommonAttrsBackgroundImageSizeTest.test' +import commonAttrsBackgroundImagePositionTest from './commonattrs/CommonAttrsBackgroundImagePositionTest.test' +import commonAttrsBrightnessTest from './commonattrs/CommonAttrsBrightnessTest.test' +import commonAttrsSaturateTest from './commonattrs/CommonAttrsSaturateTest.test' +import commonAttrsBlurTest from './commonattrs/CommonAttrsBlurTest.test' +import commonAttrsClipShapeTest from './commonattrs/CommonAttrsClipShapeTest.test' +import commonAttrsCustomShadowTest from './commonattrs/CommonAttrsCustomShadowTest.test' +import commonAttrsVisibilityTest from './commonattrs/CommonAttrsVisibilityTest.test' +import commonAttrsDefaultFocusTest from './commonattrs/CommonAttrsDefaultFocusTest.test' +import commonAttrsFocusStatusTest from './commonattrs/CommonAttrsFocusStatusTest.test' +import commonAttrsAspectRatioTest from './commonattrs/CommonAttrsAspectRatioTest.test' +import commonAttrsForegroundColorTest from './commonattrs/CommonAttrsForegroundColorTest.test' +import commonAttrsMarkAnchorTest from './commonattrs/CommonAttrsMarkAnchorTest.test' +import commonAttrsOffsetTest from './commonattrs/CommonAttrsOffsetTest.test' +import commonAttrsOverlayTest from './commonattrs/CommonAttrsOverlayTest.test' +import commonAttrsResponseRegionTest from './commonattrs/CommonAttrsResponseRegionTest.test' + +export default function testsuite() { + commonAttrsZIndexTest() + commonAttrsAccessibilityRoleTest() + commonAttrsAccessibilityStateTest() + commonAttrsAccessibilityValueTest() + commonAttrsFocusOnTouchTest() + commonAttrsAlignmentTest() + commonAttrsOutlineColorTest() + commonAttrsSizeTest() + commonAttrsPaddingTest() + commonAttrsTranslateTest() + commonAttrsTouchAbleTest() + commonAttrsRotateTest() + commonAttrsRenderGroupTest() + commonAttrsLayoutWeightTest() + commonAttrsDisplayPriorityTest() + commonAttrsOutlineWidthTest() + commonAttrsColorBlendTest() + commonAttrsChainModeTest() + commonAttrsBackgroundBlurStyleTest() + commonAttrsBackgroundImageTest() + commonAttrsBackgroundImageSizeTest() + commonAttrsBackgroundImagePositionTest() + commonAttrsBrightnessTest() + commonAttrsSaturateTest() + commonAttrsBlurTest() + commonAttrsClipShapeTest() + commonAttrsCustomShadowTest() + commonAttrsVisibilityTest() + commonAttrsDefaultFocusTest() + commonAttrsFocusStatusTest() + commonAttrsAspectRatioTest() + commonAttrsForegroundColorTest() + commonAttrsMarkAnchorTest() + commonAttrsOffsetTest() + commonAttrsOverlayTest() + commonAttrsResponseRegionTest() +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d2e942f4a238e9c6cce0f4b752699a8c622663e3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 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. + */ + +export class ComponentInfo { + $type: string; + $rect: Object[]; +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts new file mode 100644 index 0000000000000000000000000000000000000000..f92fa6f417dd13fe3ea3699af14531d1c3e82c82 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 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 screen from '@ohos.screen'; +import window from '@ohos.window'; + +const TAG: string = '[SettingsCApiDemo]' + +class Settings { + sleep(time) { + return new Promise((resolve) => { + setTimeout(resolve, time) + }); + } + + windowClass: window.Window = null + + //为悬浮窗设置位置 + changeWindowPosition(windowClass, X, Y) { + windowClass.moveWindowTo(X, Y, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to move the window. Cause: ${JSON.stringify(err)}`); + return; + } + }) + } + + //为悬浮窗设置大小 + changeWindowSize(windowClass, width, height) { + windowClass.resize(width, height, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to change the window size. Cause: ${JSON.stringify(err)}`); + return; + } + }) + } + + loadContent(windowClass, pageURI) { + //为悬浮窗加载对应的目标页面 + windowClass.setUIContent(pageURI, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in loading the content.`); + + //显示悬浮窗 + windowClass.showWindow((err) => { + if (err.code) { + console.error(`${TAG}, Fail to show the window. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in showing the window.`); + }) + + }) + } + + // changeDpi(dpi) { + // let screenClass = null; + // screen.getAllScreens((err, data) => { + // if (err.code) { + // console.error(`${TAG}, Fail to get all screens. Cause: ${JSON.stringify(err)}`); + // return; + // } + // console.info(`${TAG}, Succeeded in geting all screens.`); + // + // screenClass = data[0]; + // //设置设备dpi + // screenClass.setDensityDpi(dpi, (err, data) => { + // if (err.code) { + // console.error(`${TAG}, Fail to set the piexl density. Cause: ${JSON.stringify(err)}`); + // return; + // } + // console.info(`${TAG}, Succeeded in seting the piexl density.`) + // }) + // }) + // } + + destroyWindow() { + //销毁窗口 + let windowClass = null; + try { + windowClass = window.findWindow('floatWindow'); + console.info(`${TAG}, find window success.`) + } catch (exception) { + console.error(`${TAG}, Fail to find the window. Cause: ${JSON.stringify(exception)}`); + } + windowClass.destroyWindow((err) => { + if (err.code) { + console.error(`${TAG}, Fail to destroy the window. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in destroying the window.`) + }) + } + + createWindow(pageURI: String, {X=0,Y=0,width=1344,height=2560,dpi=400}={}) { + console.info(`${TAG}, params, pageURI=${pageURI}}, X=${X}, Y=${Y}, width=${width}, height=${height}, dpi=${dpi}`) + + // this.changeDpi(dpi); + this.sleep(1000); + let windowClass = null; + let config = { + name: 'floatWindow', windowType: window.WindowType.TYPE_FLOAT, ctx: globalThis.context + } + window.createWindow(config, (err, data) => { + if (err.code) { + console.error(`${TAG}, Fail to create the floatWindow. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in creating the floatWindow.`) + windowClass = data; + this.windowClass = data; + + this.changeWindowPosition(windowClass, X, Y) + this.changeWindowSize(windowClass, width, height) + this.loadContent(windowClass, pageURI) + }) + } +} + +export default new Settings() \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts new file mode 100644 index 0000000000000000000000000000000000000000..c2d92270475c072bd61a22931f6b281a030ac5dc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2024 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 window from '@ohos.window'; +import image from '@ohos.multimedia.image'; +import fs from '@ohos.file.fs'; +import { Driver, Rect } from '@ohos.UiTest'; + +const TAG: string = '[WindowSnap]' +const INFO = { + 'img': { + prefix: 'IMG_', + suffix: '.webp' + }, + 'txt': { + prefix: 'TXT_', + suffix: '.txt' + } +} + +class WindowSnap { + async sleep(time) { + return new Promise((resolve) => { + setTimeout(resolve, time) + }); + } + + createFile(context: any, type, page) { + console.info(`${TAG}, createFile start`) + let pathDir = context.filesDir; + console.info(`${TAG}, createFile pathDir = ${pathDir}`) + let name = page + let info = INFO[type] + let displayName = `${info.prefix}${name}${info.suffix}` + let filePath = pathDir + '/' + displayName + console.info(`${TAG}, createFile filePath = ${filePath}`) + let exists = fs.accessSync(filePath) + console.info(`${TAG}, oldFile exists = ${exists}`) + if (exists) { + fs.unlinkSync(filePath) + console.info(`${TAG}, remove file succeed`) + } + return fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) + } + + async save(data: image.PixelMap, context: any, page) { + console.info(`${TAG}, start save image`) + let packOpts: image.PackingOption = { + format: 'image/webp', quality: 100 + } + let imagePackerApi = image.createImagePacker() + let arrayBuffer = await imagePackerApi.packing(data, packOpts) + let file = null + while (file == null) { + file = this.createFile(context, 'img', page) + } + let exists = fs.accessSync(file.path) + console.info(`${TAG}, createFile exists = ${exists}`) + let fd = file.fd + console.info(`${TAG}, createFile fd = ${fd}`) + imagePackerApi.release() + try { + fs.writeSync(fd, arrayBuffer) + } catch (err) { + console.error(`${TAG}, write failed, code is ${err.code}, message is ${err.message}}`) + } + fs.closeSync(file) + console.info(`${TAG}, write picture done`) + } + + /** + * 获取窗口截图&文件保存 + * 入参必须为ability的context + * + * save:设备保存路径:/data/app/el2/100/base/{bundle_name}/haps/entry_test/files/IMG_test.webp + */ + async snapShot(context, page, done?) { + console.info(`${TAG}, start snapshot`) + await this.sleep(2000); + let windowClass = null + try { + windowClass = window.findWindow('floatWindow') + console.info(`${TAG}, find window success`) + } catch (exception) { + console.error(`${TAG}, Failed to find the window. Cause: ${JSON.stringify(exception)}`) + } + + windowClass.snapshot(async (err, data) => { + console.info(`${TAG}, windowClass.snapshot`) + if (err.code) { + console.error(`${TAG}, Failed to snapshot window. Cause: ${JSON.stringify(err)}`) + return + } + await this.save(data, context, page) + data.release() + if (done) { + done(); + } + }) + } + + async snapShotNext(context, page, done?) { + console.info(`${TAG}, start snapshot`) + let windowClass = null + try { + windowClass = window.findWindow('floatWindow'); + } catch (exception) { + console.error(`${TAG}, Failed to find the window. Cause: ${JSON.stringify(exception)}`) + } + await this.sleep(600); + windowClass.snapshot(async (err, data) => { + console.info(`${TAG}, windowClass.snapshot`) + + if (err.code) { + console.error(`${TAG}, Failed to snapshot window. Cause: ${JSON.stringify(err)}`) + return + } + await this.save(data, context, page) + data.release() + if (done) { + done(); + } + }) + } + + async snapShotByDriver(context, page, done?) { + console.info(`Start snapshot by driver`) + await this.sleep(2000); + let file = null + while (file == null) { + file = this.createFile(context, 'img', page) + } + let exists = fs.accessSync(file.path) + console.info(`${TAG}, createFile exists = ${exists}`) + + try { + let windowClass = window.findWindow('floatWindow') + console.info(`${TAG}, find window success`) + let windowRect = windowClass.getWindowProperties().windowRect; + console.info(`${TAG}, windowRct is ${JSON.stringify(windowRect)}`) + let driver = Driver.create(); + await driver.screenCapture(file.path, { + left: windowRect.left, + top: windowRect.top, + right: windowRect.width, + bottom: windowRect.height + }); + } catch (exception) { + console.error(`${TAG}, Failed to snap shot. Cause: ${JSON.stringify(exception)}`) + } + + if (done) { + done(); + } + } +} + +export default new WindowSnap() \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..0de7823510a15bd718a457a592c6f4f29d4c2d3d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2024 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 events_emitter from '@ohos.events.emitter'; +import { Driver, ON, PointerMatrix, Rect } from '@ohos.UiTest'; +import { ComponentInfo } from './Interfaces'; +import systemDateTime from '@ohos.systemDateTime'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry' +import fs from '@ohos.file.fs'; +import router from '@ohos.router'; + +export default class Utils { + static sleep(time: number) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve("ok") + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getSystemTime() { + return systemDateTime.getTime(true) / 1000 + } + + static getSandboxFileDir() { + let sandboxFileDir = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext().filesDir + "/" + console.log(`[getSandboxFileDir] return ${sandboxFileDir}`); + return sandboxFileDir; + } + + static deleteFile(filePath: string) { + console.info("[deleteFile] filePath:" + filePath); + try { + fs.unlinkSync(filePath) + } catch (error) { + console.info("[deleteFile] error:" + error); + } + } + + static isFileExist(filePath: string): boolean { + console.info("[isFileExist] filePath:" + filePath); + try { + let fileExist = fs.accessSync(filePath) + console.info("[isFileExist] return:" + fileExist); + return fileExist + } catch (error) { + console.info("[isFileExist] error:" + error); + return false + } + } + + static getComponentInfoByKey(key: string): ComponentInfo { + let strJson = getInspectorByKey(key); + let obj: ComponentInfo = JSON.parse(strJson); + console.info('[getInspectorByKey] current component info: ' + JSON.stringify(obj)); + return obj; + } + + + static async flingComponent(key: string, isHorizontal: boolean, isForward: boolean) { + let driver = Driver.create(); + let rect = Utils.getComponentRect(key); + let centerX = Utils.getRectHorizontalCenterX(rect) + let centerY = Utils.getRectVerticalCenterY(rect) + let X1 = centerX - 100; + let X2 = centerX + 100; + let Y1 = centerY - 100; + let Y2 = centerY + 100; + let stepLen = 20; + let speed = 10000; + if (isHorizontal) { + if (isForward) { + await driver.fling({ + x: X2, y: centerY + }, { + x: X1, y: centerY + }, stepLen, speed); + } else { + await driver.fling({ + x: X1, y: centerY + }, { + x: X2, y: centerY + }, stepLen, speed); + } + } else { + if (isForward) { + await driver.fling({ + x: centerX, y: Y2 + }, { + x: centerX, y: Y1 + }, stepLen, speed); + } else { + await driver.fling({ + x: centerX, y: Y1 + }, { + x: centerX, y: Y2 + }, stepLen, speed); + } + } + } + + static async clickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.click(); + } + + static async doubleClickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.click(); + await component.click(); + } + + static async clickLocation(X: number, Y: number) { + let driver = Driver.create(); + await driver.click(X, Y); + } + + static async triggerKey(id: number) { + let driver = Driver.create(); + await driver.triggerKey(id); + } + + static async longClickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.longClick(); + } + + static async clickComponentByText(text: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.text(text)); + await component.click(); + } + + static async fingerZoom(key: string, isOut: boolean) { + let rect = Utils.getComponentRect(key); + let centerX = Utils.getRectHorizontalCenterX(rect) + let centerY = Utils.getRectVerticalCenterY(rect) + let fingerUpCenterY = centerY - 100; + let fingerDownCenterY = centerY + 100; + let driver: Driver = Driver.create(); + let pointers: PointerMatrix = PointerMatrix.create(2, 3); + pointers.setPoint(0, 0, { + x: centerX, y: fingerUpCenterY - (isOut ? 40 : 120) + }); + pointers.setPoint(0, 1, { + x: centerX, y: fingerUpCenterY - 80 + }); + pointers.setPoint(0, 2, { + x: centerX, y: fingerUpCenterY - (isOut ? 120 : 40) + }); + pointers.setPoint(1, 0, { + x: centerX, y: fingerDownCenterY + (isOut ? 40 : 120) + }); + pointers.setPoint(1, 1, { + x: centerX, y: fingerDownCenterY + 80 + }); + pointers.setPoint(1, 2, { + x: centerX, y: fingerDownCenterY + (isOut ? 120 : 40) + }); + await driver.injectMultiPointerAction(pointers); + } + + static registerEvent(pageTag: string, eventId: number, callBack: Function) { + events_emitter.on({ + eventId: eventId, + priority: events_emitter.EventPriority.LOW + }, (eventData: events_emitter.EventData) => { + console.info("Value Change CallBack"); + if (eventData != null && eventData.data != null) { + if (pageTag == eventData.data.PAGE_TAG) { + console.info("CallBack value:" + JSON.stringify(eventData)); + callBack(eventData.data.VALUE); + } + } + }) + } + + static emitEvent(pageTag: string, emitValue: number | string | object, eventId: number) { + try { + let backData: events_emitter.EventData = { + data: { + "PAGE_TAG": pageTag, + "VALUE": emitValue + } + } + let backEvent: events_emitter.InnerEvent = { + eventId: eventId, + priority: events_emitter.EventPriority.LOW + } + console.info("start to emit page state"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("emit page state err: " + JSON.stringify(err)); + } + } + + static async pushPage(pageTag: string, done?: Function) { + let options: router.RouterOptions = { + url: `MainAbility/pages/${pageTag}`, + } + try { + router.clear(); + let pages = router.getState(); + console.info(`get ${pageTag} state success ` + JSON.stringify(pages)); + if (pageTag.indexOf(pages.name) < 0) { + console.info(`get ${pageTag} state success ` + JSON.stringify(pages.name)); + let result = await router.pushUrl(options); + await Utils.sleep(2000); + console.info(`push ${pageTag} page success ` + JSON.stringify(result)); + } + } catch (err) { + console.error(`push ${pageTag} page error: ` + err); + } + if (done) { + done(); + } + } + + static getComponentRect(key: string): Rect { + let strJson = getInspectorByKey(key); + let obj: ComponentInfo = JSON.parse(strJson); + console.info('[getInspectorByKey] key is: ' + key); + return Utils.getComponentRectByObj(obj); + } + + static getComponentRectByObj(obj: ComponentInfo): Rect { + console.info('[getInspectorByKey] current component is: ' + obj.$type); + let rectInfo: Object[] = JSON.parse('[' + obj.$rect + ']'); + let rect_value: Rect = { + left: JSON.parse('[' + rectInfo[0] + ']')[0], + top: JSON.parse('[' + rectInfo[0] + ']')[1], + right: JSON.parse('[' + rectInfo[1] + ']')[0], + bottom: JSON.parse('[' + rectInfo[1] + ']')[1] + }; + console.info(JSON.stringify(rect_value)); + return rect_value; + } + + static getRectHorizontalCenterX(rect: Rect): number { + return Number.parseInt(Number((rect.right - rect.left) / 2 + rect.left).toFixed(0)); + } + + static getRectVerticalCenterY(rect: Rect): number { + return Number.parseInt(Number((rect.bottom - rect.top) / 2 + rect.top).toFixed(0)); + } + + static async mouseMoveTo(X: number, Y: number) { + let driver = Driver.create(); + await driver.mouseMoveTo({ + x: X, y: Y + }); + } + + static async mouseMoveToCurrentComponent(componentId: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(componentId)); + let point = await component.getBounds(); + await driver.mouseMoveTo({ + x: point.left + 10, y: point.bottom - 10 + }); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityRoleTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityRoleTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e8fdcf5242811b25dea23d188e7471ef8031a669 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityRoleTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsAccessibilityRoleTest() { + + describe('CommonAttrsAccessibilityRoleTest', () => { + + let PAGE_TAG = 'CommonAttrsAccessibilityRoleTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsAccessibilityRole001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityStateTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityStateTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6454542c39d82739b5201f501b3fabc830c62273 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityStateTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsAccessibilityStateTest() { + + describe('CommonAttrsAccessibilityStateTest', () => { + + let PAGE_TAG = 'CommonAttrsAccessibilityStateTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsAccessibilityState001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityValueTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityValueTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3368865a4c398e93345069372396343da7e17a58 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAccessibilityValueTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsAccessibilityValueTest() { + + describe('CommonAttrsAccessibilityValueTest', () => { + + let PAGE_TAG = 'CommonAttrsAccessibilityValueTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsAccessibilityValue001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAlignmentTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAlignmentTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c521d01c216cb877e8457c4a2f89fe41d38454f6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAlignmentTest.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 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 { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsAlignmentTest() { + + describe('CommonAttrsAlignmentTest', () => { + + let PAGE_TAG_1 = 'CommonAttrsAlignmentPage1Test'; + let PAGE_TAG_2 = 'CommonAttrsAlignmentPage2Test'; + let PAGE_TAG_3 = 'CommonAttrsAlignmentPage3Test'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsAlignment001', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG_1}`, done); + done(); + }) + + it('testCommonAttrsAlignment002', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG_2}`, done); + done(); + }) + + it('testCommonAttrsAlignment003', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG_3}`, done); + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAspectRatioTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAspectRatioTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1a7d1414e7ae1f8627b0220b778040a4a0acfd2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsAspectRatioTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsAspectRatioTest() { + + describe('CommonAttrsAspectRatioTest', () => { + + let PAGE_TAG = 'CommonAttrsAspectRatioTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsAspectRatio001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundBlurStyleTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundBlurStyleTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a166b63396550363d454d1c733aa5aba469e27e7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundBlurStyleTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsBackgroundBlurStyleTest() { + + describe('CommonAttrsBackgroundBlurStyleTest', () => { + + let PAGE_TAG = 'CommonAttrsBackgroundBlurStyleTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsBackgroundBlurStyle001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImagePositionTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImagePositionTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1536af22495bc835872f7124c2a26089cc8b63c3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImagePositionTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsBackgroundImagePositionTest() { + + describe('CommonAttrsBackgroundImagePositionTest', () => { + + let PAGE_TAG = 'CommonAttrsBackgroundImagePositionTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsBackgroundImagePosition001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImageSizeTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImageSizeTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a89fcce065fcab8c2388a0025f5981196c99ad3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImageSizeTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsBackgroundImageSizeTest() { + + describe('CommonAttrsBackgroundImageSizeTest', () => { + + let PAGE_TAG = 'CommonAttrsBackgroundImageSizeTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsBackgroundImageSize001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImageTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImageTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7be90c140304eeefc202be274fa000b55856e44d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBackgroundImageTest.test.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsBackgroundImageTest() { + + describe('CommonAttrsBackgroundImageTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsBackgroundImage001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsBackgroundImageResourceStrTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + + it('testCommonAttrsBackgroundImage002', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsBackgroundImagePixelMapTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBlurTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBlurTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..69e07dec6239dc9dddbe79c4ce198ca3ecd0f3d4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBlurTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsBlurTest() { + + describe('CommonAttrsBlurTest', () => { + + let PAGE_TAG = 'CommonAttrsBlurTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsBlur001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBrightnessTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBrightnessTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9376068c084760d9da6279a8e92f2d7785d6a8a8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsBrightnessTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsBrightnessTest() { + + describe('CommonAttrsBrightnessTest', () => { + + let PAGE_TAG = 'CommonAttrsBrightnessTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsBrightness001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsChainModeTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsChainModeTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d27553077e4686f4c46a63b13fadd4c545b0049a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsChainModeTest.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsChainModeTest() { + + describe('CommonAttrsChainModeTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsChainMode001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsChainModeTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + done(); + }) + + it('testCommonAttrsChainMode002', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsChainMode1Test'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + done(); + }) + + it('testCommonAttrsChainMode003', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsChainMode2Test'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsClipShapeTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsClipShapeTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..84181e78525b3608fc2f17fb9e6310874a6b50dc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsClipShapeTest.test.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsClipShapeTest() { + + describe('CommonAttrsClipShapeTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsClipShape001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsClipShapeTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsColorBlendTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsColorBlendTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf51ef6488a89bd8c45326cf6895621ae632133c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsColorBlendTest.test.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsColorBlendTest() { + + describe('CommonAttrsColorBlendTest', () => { + + let PAGE_TAG = 'CommonAttrsColorBlendTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsColorBlend001', 0, async (done: Function) => { + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsCustomShadowTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsCustomShadowTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..22d8f0b031a5118d42137726fa5e20ee6a16d245 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsCustomShadowTest.test.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsCustomShadowTest() { + + describe('CommonAttrsCustomShadowTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsCustomShadow001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsCustomShadowTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsDefaultFocusTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsDefaultFocusTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..47bdf545cd4d2b11db86553f42750bf911d30a92 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsDefaultFocusTest.test.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsDefaultFocusTest() { + + describe('CommonAttrsDefaultFocusTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsDefaultFocus001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsDefaultFocusSingleTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + + it('testCommonAttrsDefaultFocus002', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsDefaultFocusNoneTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + + it('testCommonAttrsDefaultFocus003', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsDefaultFocusMultiTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + + it('testCommonAttrsDefaultFocus004', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsDefaultFocusAbnormalTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsDisplayPriorityTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsDisplayPriorityTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fd1ea86e1ca247ab4406c0b06136189fa0e6ce0e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsDisplayPriorityTest.test.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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 { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver } from '@ohos.UiTest'; + +export default function commonAttrsDisplayPriorityTest() { + + describe('CommonAttrsDisplayPriorityTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsDisplayPriority001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsDisplayPriorityTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsFocusOnTouchTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsFocusOnTouchTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..403d1f7c8dd93e231e158df562b29fd96657988e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsFocusOnTouchTest.test.ets @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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 { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsFocusOnTouchTest() { + + describe('CommonAttrsFocusOnTouchTest', () => { + + let PAGE_TAG = 'CommonAttrsFocusOnTouchTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsFocusOnTouch001', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + await Utils.clickComponent("text1"); + await Utils.sleep(2000); + done(); + }) + + it('testCommonAttrsFocusOnTouch002', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + await Utils.clickComponent("text2"); + await Utils.sleep(2000); + done(); + }) + + it('testCommonAttrsFocusOnTouch003', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + await Utils.clickComponent("text3"); + await Utils.sleep(2000); + done(); + }) + + it('testCommonAttrsFocusOnTouch004', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + await Utils.clickComponent("text4"); + await Utils.sleep(2000); + done(); + }) + + it('testCommonAttrsFocusOnTouch005', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + await Utils.clickComponent("text5"); + await Utils.sleep(2000); + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsFocusStatusTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsFocusStatusTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..352c7f46180d2c542a6b7328090e7a2ea106355b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsFocusStatusTest.test.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver } from '@kit.TestKit'; + +export default function commonAttrsFocusStatusTest() { + + describe('CommonAttrsFocusStatusTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsFocusStatus001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsFocusStatusTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + await Utils.clickComponent('Button'); + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsForegroundColorTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsForegroundColorTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..18ffd927c70d8993cc98929b709bd9693d68f370 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsForegroundColorTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsForegroundColorTest() { + + describe('CommonAttrsForegroundColorTest', () => { + + let PAGE_TAG = 'CommonAttrsForegroundColorTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsForegroundColor001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsLayoutWeightTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsLayoutWeightTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff2e05ad42eb4cd899d0b66dcb55779884c84ada --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsLayoutWeightTest.test.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsLayoutWeightTest() { + + describe('CommonAttrsLayoutWeightTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsLayoutWeight001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsLayoutWeightTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsMarkAnchorTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsMarkAnchorTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a15e3ef047be1ddeef92f1a87cbb4f3a8697c1b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsMarkAnchorTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsMarkAnchorTest() { + + describe('CommonAttrsMarkAnchorTest', () => { + + let PAGE_TAG = 'CommonAttrsMarkAnchorTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsMarkAnchor001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOffsetTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOffsetTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..beb3336adef2caf0b005b20237ad40b076d1d1bf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOffsetTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsOffsetTest() { + + describe('CommonAttrsOffsetTest', () => { + + let PAGE_TAG = 'CommonAttrsOffsetTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsOffset001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOutlineColorTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOutlineColorTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..af962207935c4f687a6fbae65f9ecec1f90bf184 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOutlineColorTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsOutlineColorTest() { + + describe('CommonAttrsOutlineColorTest', () => { + + let PAGE_TAG = 'CommonAttrsOutlineColorTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsOutlineColor001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOutlineWidthTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOutlineWidthTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b5bfb6f7d2bde903b4b2d677b7f52a6c7b82702 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOutlineWidthTest.test.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsOutlineWidthTest() { + + describe('CommonAttrsOutlineWidthTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsOutlineWidth001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsOutlineWidthTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOverlayTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOverlayTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3524648c8655db738e57e21df9df3d28d824232d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsOverlayTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsOverlayTest() { + + describe('CommonAttrsOverlayTest', () => { + + let PAGE_TAG = 'CommonAttrsOverlayTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsOverlay001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsPaddingTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsPaddingTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..96e96ba8d4953b8ee4952d979565f99b064877e6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsPaddingTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsPaddingTest() { + + describe('CommonAttrsPaddingTest', () => { + + let PAGE_TAG = 'CommonAttrsPaddingTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsPadding001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsRenderGroupTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsRenderGroupTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b17689183c75ec7e8a03fc83f4acf642a5560c97 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsRenderGroupTest.test.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsRenderGroupTest() { + + describe('CommonAttrsRenderGroupTest', () => { + + let PAGE_TAG = 'CommonAttrsRenderGroupTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsRenderGroup001', 0, async (done: Function) => { + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsResponseRegionTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsResponseRegionTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4778845eb075792097fdc89e86bd25e6c7db0a10 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsResponseRegionTest.test.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver, ON, MouseButton } from '@kit.TestKit'; + +async function clickLeft(id: string, done: Function, x = 40, y = 35) { + let driver = Driver.create(); + let refresh = await driver.findComponent(ON.id(id)); + let point = await refresh.getBounds(); + await driver.click(point.left + x, point.top + y) +} + +async function clickRight(id: string, done: Function, x = 40, y = 35) { + let driver = Driver.create(); + let refresh = await driver.findComponent(ON.id(id)); + let point = await refresh.getBounds(); + await driver.click(point.right - x, point.top + y) +} + +export default function commonAttrsResponseRegionTest() { + + describe('CommonAttrsResponseRegionTest', () => { + + let PAGE_TAG = 'CommonAttrsResponseRegionTest'; + let driver = Driver.create(); + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + // 点击各组件的左侧或右侧 + it('testCommonAttrsResponseRegion001', 0, async (done: Function) => { + await clickLeft("BTN1", done); + await clickRight("BTN2", done); + await clickLeft("BTN3", done); + await clickRight("BTN4", done); + await clickRight("BTN5", done); + await clickRight("BTN6", done); + await clickRight("BTN7", done); + await clickLeft("BTN8", done); + await clickRight("BTN9", done); + await clickLeft("BTN10", done); + await clickLeft("BTN12", done); + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsRotateTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsRotateTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..828cdb84a07e67d1c69634a84119a2df91b4cf3e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsRotateTest.test.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsRotateTest() { + + describe('CommonAttrsRotateTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsRotate001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsRotateTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsSaturateTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsSaturateTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5fd65013b4bc4fec9a996f93dd3aba9e3500ee18 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsSaturateTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsSaturateTest() { + + describe('CommonAttrsSaturateTest', () => { + + let PAGE_TAG = 'CommonAttrsSaturateTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsSaturate001', 0, async (done: Function) => { + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsSizeTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsSizeTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d7c056facf1770cc41d56873a449a5a43fddd5f0 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsSizeTest.test.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsSizeTest() { + + describe('CommonAttrsSizeTest', () => { + + let PAGE_TAG = 'CommonAttrsSizeTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsSize001', 0, async (done: Function) => { + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsTouchAbleTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsTouchAbleTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ca50016cb9358d49cfadc18db1d8e2c5d8dbf1a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsTouchAbleTest.test.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsTouchAbleTest() { + + describe('CommonAttrsTouchAbleTest', () => { + + let PAGE_TAG = 'CommonAttrsTouchAbleTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsTouchAble001', 0, async (done: Function) => { + await Utils.clickComponent("button1") + await Utils.clickComponent("button2") + await Utils.clickComponent("button3") + await Utils.clickComponent("button4") + await Utils.clickComponent("button5") + await Utils.clickComponent("button6") + await Utils.clickComponent("button7") + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsTranslateTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsTranslateTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f5c37c5664ad91d4b631b4728e5eac912ee9063 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsTranslateTest.test.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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 { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsTranslateTest() { + + describe('CommonAttrsTranslateTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsTranslate001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsTranslateTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`); + Utils.sleep(200) + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsVisibilityTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsVisibilityTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2069fa65efc34742cbd63dd28fc2d1fe8321797d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsVisibilityTest.test.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function commonAttrsVisibilityTest() { + + describe('CommonAttrsVisibilityTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsVisibility001', 0, async (done: Function) => { + let PAGE_TAG = 'CommonAttrsVisibilityTest'; + await Utils.pushPage(`commonattrs/${PAGE_TAG}`, done); + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsZIndexTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsZIndexTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4cbfce3c8d0e324b84527f34edb8a542a0759374 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/commonattrs/CommonAttrsZIndexTest.test.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 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 { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver, ON, Component } from '@ohos.UiTest'; + +// 点击 +async function click(id: string, done: Function) { + let driver: Driver = Driver.create(); + let component: Component = await driver.findComponent(ON.id(id)); + await component.click(); + await Utils.sleep(1000); +} + +export default function commonAttrsZIndexTest() { + + describe('CommonAttrsZIndexTest', () => { + + let PAGE_TAG_1 = 'CommonAttrsZIndexPage1Test'; + let PAGE_TAG_2 = 'CommonAttrsZIndexPage2Test'; + let PAGE_TAG_3 = 'CommonAttrsZIndexPage3Test'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testCommonAttrsZIndex001', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG_1}`, done); + done(); + }) + + it('testCommonAttrsZIndex002', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG_2}`, done); + await click("button3", done); + done(); + }) + + it('testCommonAttrsZIndex003', 0, async (done: Function) => { + await Utils.pushPage(`commonattrs/${PAGE_TAG_3}`, done); + await click("button4", done); + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..22e8d7e308a48383a2acdc13254a18588637bdfa --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 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 TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +let abilityDelegator = undefined; +let abilityDelegatorArguments = undefined; + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]); + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}`; + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + let cmd = 'aa start -d 0 -a MainAbility' + + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); + let debug = abilityDelegatorArguments.parameters['-D']; + if (debug == 'true') { + cmd += ' -D'; + } + console.info('cmd : ' + cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }); + console.info('OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 b/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b0ee0e81d470b8fc3b276f0b706ddf014ed6099 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 @@ -0,0 +1,47 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntry": "./ets/Application/AbilityStage.ts", + "description": "$string:module_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "MainAbility", + "srcEntry": "./ets/MainAbility/MainAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/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/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..8658bacc0d5d479ee25116b206bc152e53d92953 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json @@ -0,0 +1,24 @@ +{ + "float": [ + { + "name": "300vp", + "value": "300vp" + }, + { + "name": "200vp", + "value": "200vp" + }, + { + "name": "100vp", + "value": "100vp" + }, + { + "name": "50vp", + "value": "50vp" + } + ,{ + "name": "10vp", + "value": "10vp" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..bbe9979eda9db82793df2873701e4beae14c44cc Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..0ec2e1692ed4a280147f41fa7491fa6595958153 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..4b68e9b07b4c30539ff093e43c193cfd61dc59fd Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg new file mode 100644 index 0000000000000000000000000000000000000000..36a19cd6b90bb98511116f5015c74fe2f860249d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..9b045ba74e7873993c3bad78c6a3ddfcb9fc76c2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json @@ -0,0 +1,52 @@ +{ + "src": [ + "MainAbility/pages/DemoIndex", + "MainAbility/pages/commonattrs/CommonAttrsZIndexPage1Test", + "MainAbility/pages/commonattrs/CommonAttrsZIndexPage2Test", + "MainAbility/pages/commonattrs/CommonAttrsZIndexPage3Test", + "MainAbility/pages/commonattrs/CommonAttrsOutlineColorTest", + "MainAbility/pages/commonattrs/CommonAttrsSizeTest", + "MainAbility/pages/commonattrs/CommonAttrsPaddingTest", + "MainAbility/pages/commonattrs/CommonAttrsAccessibilityRoleTest", + "MainAbility/pages/commonattrs/CommonAttrsAccessibilityStateTest", + "MainAbility/pages/commonattrs/CommonAttrsAccessibilityValueTest", + "MainAbility/pages/commonattrs/CommonAttrsFocusOnTouchTest", + "MainAbility/pages/commonattrs/CommonAttrsAlignmentPage1Test", + "MainAbility/pages/commonattrs/CommonAttrsAlignmentPage2Test", + "MainAbility/pages/commonattrs/CommonAttrsAlignmentPage3Test", + "MainAbility/pages/commonattrs/CommonAttrsTranslateTest", + "MainAbility/pages/commonattrs/CommonAttrsTouchAbleTest", + "MainAbility/pages/commonattrs/CommonAttrsRotateTest", + "MainAbility/pages/commonattrs/CommonAttrsRenderGroupTest", + "MainAbility/pages/commonattrs/CommonAttrsLayoutWeightTest", + "MainAbility/pages/commonattrs/CommonAttrsDisplayPriorityTest", + "MainAbility/pages/commonattrs/CommonAttrsOutlineWidthTest", + "MainAbility/pages/commonattrs/CommonAttrsChainModeTest", + "MainAbility/pages/commonattrs/CommonAttrsChainMode1Test", + "MainAbility/pages/commonattrs/CommonAttrsChainMode2Test", + "MainAbility/pages/commonattrs/CommonAttrsColorBlendTest", + "MainAbility/pages/commonattrs/CommonAttrsBackgroundBlurStyleTest", + "MainAbility/pages/commonattrs/CommonAttrsBackgroundImageResourceStrTest", + "MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePixelMapTest", + "MainAbility/pages/commonattrs/CommonAttrsBackgroundImageSizeTest", + "MainAbility/pages/commonattrs/CommonAttrsBackgroundImagePositionTest", + "MainAbility/pages/commonattrs/CommonAttrsBrightnessTest", + "MainAbility/pages/commonattrs/CommonAttrsSaturateTest", + "MainAbility/pages/commonattrs/CommonAttrsBlurTest", + "MainAbility/pages/commonattrs/CommonAttrsClipShapeTest", + "MainAbility/pages/commonattrs/CommonAttrsCustomShadowTest", + "MainAbility/pages/commonattrs/CommonAttrsVisibilityTest", + "MainAbility/pages/commonattrs/CommonAttrsDefaultFocusSingleTest", + "MainAbility/pages/commonattrs/CommonAttrsDefaultFocusNoneTest", + "MainAbility/pages/commonattrs/CommonAttrsDefaultFocusMultiTest", + "MainAbility/pages/commonattrs/CommonAttrsDefaultFocusAbnormalTest", + "MainAbility/pages/commonattrs/CommonAttrsFocusStatusTest", + "MainAbility/pages/commonattrs/CommonAttrsAspectRatioTest", + "MainAbility/pages/commonattrs/CommonAttrsForegroundColorTest", + "MainAbility/pages/commonattrs/CommonAttrsMarkAnchorTest", + "MainAbility/pages/commonattrs/CommonAttrsOffsetTest", + "MainAbility/pages/commonattrs/CommonAttrsOverlayTest", + "MainAbility/pages/commonattrs/CommonAttrsResponseRegionTest" + ] +} + diff --git a/function/ui_compare/capidemo/hvigor/hvigor-config.json5 b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f70ecd4112d94f9aa555adf898d53f18bf58f3e9 --- /dev/null +++ b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 @@ -0,0 +1,5 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/hvigorfile.ts b/function/ui_compare/capidemo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/function/ui_compare/capidemo/hvigorfile.ts @@ -0,0 +1,6 @@ +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. */ +} diff --git a/function/ui_compare/capidemo/log.txt b/function/ui_compare/capidemo/log.txt new file mode 100644 index 0000000000000000000000000000000000000000..c30becbf3cf835fb939a2032089d1445f7774299 Binary files /dev/null and b/function/ui_compare/capidemo/log.txt differ diff --git a/function/ui_compare/capidemo/oh-package-lock.json5 b/function/ui_compare/capidemo/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..166762a255eba6f82019e77b23b4168704decc5a --- /dev/null +++ b/function/ui_compare/capidemo/oh-package-lock.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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. + */ + +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.19": { + "name": "@ohos/hypium", + "version": "1.0.19", + "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.19.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/oh-package.json5 b/function/ui_compare/capidemo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9efdda6f4890c0b6e53b460db90bd0aad0f54f43 --- /dev/null +++ b/function/ui_compare/capidemo/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} \ No newline at end of file