diff --git a/function/ui_compare/capidemo/.gitignore b/function/ui_compare/capidemo/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..4a8074e50a1d6d61d58e3962faf9b1f27fb27a3f --- /dev/null +++ b/function/ui_compare/capidemo/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +build-profile.json5 \ 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 100755 index 0000000000000000000000000000000000000000..5f0deb75205610a7000e46414d1557fa40810ec2 --- /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 100755 index 0000000000000000000000000000000000000000..fb020ee114b8acb97b8dd12741b8a36ef4d5a26d --- /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 100755 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 100755 index 0000000000000000000000000000000000000000..80a5141f789450de473ca5924a703b02c8652799 --- /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/build-profile.json5 b/function/ui_compare/capidemo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..25255c09b22c8ee5c92dd996d086837b3ccb6982 --- /dev/null +++ b/function/ui_compare/capidemo/build-profile.json5 @@ -0,0 +1,29 @@ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ 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 100755 index 0000000000000000000000000000000000000000..95fce531ca2df66e9e28ad1fb183730472234fc7 --- /dev/null +++ b/function/ui_compare/capidemo/code-linter.json5 @@ -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. + */ +{ + "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 100755 index 0000000000000000000000000000000000000000..32abf8fd5e44623ebe60bf2adeee4a366372cc85 --- /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 100755 index 0000000000000000000000000000000000000000..c57c77181d0d36beb49c897ff3fc1ad92f7eaa7c --- /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 100755 index 0000000000000000000000000000000000000000..4379e3b1adc873250733ce178ce4ddf796d350da --- /dev/null +++ b/function/ui_compare/capidemo/entry/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "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 100755 index 0000000000000000000000000000000000000000..7d6ab2164afcb6febf05fd7f955b67cc3a807a3e --- /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 100755 index 0000000000000000000000000000000000000000..a09128ba4acf72041c16c0a4354389a5bcd533cb --- /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/column/column_align_items_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_align_items_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b293e763fe7780648a828ac23284b67405af414e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_align_items_test.cpp @@ -0,0 +1,201 @@ +/* + * 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 "column_align_items_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t backgroundColor) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_BUTTON); + // set width + ArkUI_NumberValue button_width_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_width_item = { button_width_value, + sizeof(button_width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &button_width_item); + // set height + ArkUI_NumberValue button_height_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_height_item = { button_height_value, + sizeof(button_height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &button_height_item); + + // set background color + ArkUI_NumberValue button1_background_color_value[] = { { .u32 = backgroundColor } }; + ArkUI_AttributeItem button1_background_color_item = { button1_background_color_value, + sizeof(button1_background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &button1_background_color_item); + return nodeHandle; +} + +static auto createColumnNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t horizontalAlign) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + // set AlignItems + ArkUI_NumberValue alignItems_value[] = { { .i32 = horizontalAlign } }; + ArkUI_AttributeItem alignItems_item = { alignItems_value, sizeof(alignItems_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_COLUMN_ALIGN_ITEMS, &alignItems_item); + return nodeHandle; +} + +static auto createColumnNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t horizontalAlign, int32_t flexAlign) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + // set AlignItems + ArkUI_NumberValue alignItems_value[] = { { .i32 = horizontalAlign } }; + ArkUI_AttributeItem alignItems_item = { alignItems_value, sizeof(alignItems_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_COLUMN_ALIGN_ITEMS, &alignItems_item); + // set justifyContent + ArkUI_NumberValue justifyContent_value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem justifyContent_item = { justifyContent_value, + sizeof(justifyContent_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_COLUMN_JUSTIFY_CONTENT, &justifyContent_item); + return nodeHandle; +} +napi_value ColumnAlignItemsTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ColumnAlignItemsTest", "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, "ColumnAlignItemsTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto columnStart = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_START); + auto columnCenter = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_CENTER); + auto columnEnd = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_END); + auto columnSpaceError = createColumnNode(nodeAPI, -1); + nodeAPI->addChild(parentColumn, columnStart); + nodeAPI->addChild(parentColumn, columnCenter); + nodeAPI->addChild(parentColumn, columnEnd); + nodeAPI->addChild(parentColumn, columnSpaceError); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ColumnAlignItemsTest", + "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 ColumnAlignItemsTest::CreateMoreAttributeNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ColumnAlignItemsTest", "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, "ColumnAlignItemsTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto column1 = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_START, ARKUI_FLEX_ALIGNMENT_END); + auto column2 = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_CENTER, ARKUI_FLEX_ALIGNMENT_SPACE_BETWEEN); + auto column3 = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_END, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY); + auto column4 = createColumnNode(nodeAPI, ARKUI_HORIZONTAL_ALIGNMENT_CENTER, ARKUI_FLEX_ALIGNMENT_SPACE_AROUND); + nodeAPI->addChild(parentColumn, column1); + nodeAPI->addChild(parentColumn, column2); + nodeAPI->addChild(parentColumn, column3); + nodeAPI->addChild(parentColumn, column4); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ColumnAlignItemsTest", + "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/column/column_align_items_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_align_items_test.h new file mode 100644 index 0000000000000000000000000000000000000000..569e0ad8eec1374b6699b0b2fc8e419968d2a484 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_align_items_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_COLUMN_ALIGN_ITEMS_TEST_H +#define ARKUI_CAPI_DEMO_COLUMN_ALIGN_ITEMS_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class ColumnAlignItemsTest { +public: + ~ColumnAlignItemsTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + static napi_value CreateMoreAttributeNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COLUMN_ALIGN_ITEMS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/column/column_justify_content_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_justify_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65f1132c79991dc37ef05dd251f5dc799b30d802 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_justify_content_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 "column_justify_content_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t backgroundColor) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_BUTTON); + // set width + ArkUI_NumberValue button_width_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_width_item = { button_width_value, + sizeof(button_width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &button_width_item); + // set height + ArkUI_NumberValue button_height_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_height_item = { button_height_value, + sizeof(button_height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &button_height_item); + + // set background color + ArkUI_NumberValue button1_background_color_value[] = { { .u32 = backgroundColor } }; + ArkUI_AttributeItem button1_background_color_item = { button1_background_color_value, + sizeof(button1_background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &button1_background_color_item); + return nodeHandle; +} + +static auto createColumnNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t flexAlign) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_COLUMN); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + // set justifyContent + ArkUI_NumberValue justifyContent_value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem justifyContent_item = { justifyContent_value, + sizeof(justifyContent_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_COLUMN_JUSTIFY_CONTENT, &justifyContent_item); + return nodeHandle; +} + +napi_value ColumnJustifyContentTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ColumnJustifyContentTest", "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, "ColumnJustifyContentTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto columnStart = createColumnNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_START); + auto columnCenter = createColumnNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_CENTER); + auto columnEnd = createColumnNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_END); + auto columnSpaceBetween = createColumnNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_SPACE_BETWEEN); + auto columnSpaceAround = createColumnNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_SPACE_AROUND); + auto columnSpaceEvenly = createColumnNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY); + auto columnSpaceError = createColumnNode(nodeAPI, -1); + nodeAPI->addChild(parentColumn, columnStart); + nodeAPI->addChild(parentColumn, columnCenter); + nodeAPI->addChild(parentColumn, columnEnd); + nodeAPI->addChild(parentColumn, columnSpaceBetween); + nodeAPI->addChild(parentColumn, columnSpaceAround); + nodeAPI->addChild(parentColumn, columnSpaceEvenly); + nodeAPI->addChild(parentColumn, columnSpaceError); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ColumnJustifyContentTest", + "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/column/column_justify_content_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_justify_content_test.h new file mode 100644 index 0000000000000000000000000000000000000000..069fdb320e69cd2567ce5ce9e81c1a3513b0de6b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/column/column_justify_content_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_COLUMN_JUSTIFY_CONTENT_TEST_H +#define ARKUI_CAPI_DEMO_COLUMN_JUSTIFY_CONTENT_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class ColumnJustifyContentTest { +public: + ~ColumnJustifyContentTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COLUMN_JUSTIFY_CONTENT_TEST_H 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 100755 index 0000000000000000000000000000000000000000..314a9515d77adade1ff4e600c71ff6dc640e5c9c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h @@ -0,0 +1,93 @@ +/* + * 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_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_250 250 +#define SIZE_300 300 +#define SIZE_350 350 +#define SIZE_400 400 +#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 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 100755 index 0000000000000000000000000000000000000000..6fd8c36a04d4828db0d71f0bc954b57ed67de04d --- /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 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 100755 index 0000000000000000000000000000000000000000..a492222c60e272c0186e3737d2ff35babc103d1e --- /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) {} + 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 100755 index 0000000000000000000000000000000000000000..cf988d67740fa17b9119d3637e74d6faf803564b --- /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) {} + 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 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 100755 index 0000000000000000000000000000000000000000..f8aa4404841d08c18e1f15d9fdb2bb6cc6dd694f --- /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 100755 index 0000000000000000000000000000000000000000..1d17ecb670f619a9ebcaa16c7716d37d889c3b63 --- /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: + Component(ArkUI_NodeType type); + 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); + 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 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 100755 index 0000000000000000000000000000000000000000..8c44a2853c7e114d01c1b667a7c2b62b385ee395 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h @@ -0,0 +1,32 @@ +/* + * 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) {} + FlowItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} + ~FlowItemComponent() = default; +}; +} // 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 100755 index 0000000000000000000000000000000000000000..4fcbf0b516edaefc6917bae35546d3dbf6ea33fc --- /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 100755 index 0000000000000000000000000000000000000000..269dbd7ffce34280f24dba0e9877d30312e6d84f --- /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) {} + GridItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; + +class GridComponent : public Component { +public: + GridComponent() : Component(ARKUI_NODE_GRID) {} + 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 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 100755 index 0000000000000000000000000000000000000000..70c16d54887f77247eb45b3038c55803750aee14 --- /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 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 100755 index 0000000000000000000000000000000000000000..daad3fabeb6f43a3f98e69af1e81d0c6da81583b --- /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) {} + 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 100755 index 0000000000000000000000000000000000000000..fe913a2e1e09a30458c773fe6482f77f984529eb --- /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 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 100755 index 0000000000000000000000000000000000000000..1c0423b1a2aa1cdb023001ea6ae2bdb36e7a8d95 --- /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) {} + 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 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 100755 index 0000000000000000000000000000000000000000..7a74ee781b6ac2cc3920b400ba060db64bd91dab --- /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 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 100755 index 0000000000000000000000000000000000000000..70f078853af60cb20b237eb633a13aa396c15c43 --- /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) {} + 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 100755 index 0000000000000000000000000000000000000000..4fd01b55a127caec7e81cfbb1d9afdb6b529965d --- /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 100755 index 0000000000000000000000000000000000000000..706d73d5cda7a0f87be843d8b5e81a2c2849e514 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h @@ -0,0 +1,212 @@ +/* + * 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) {} + 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) {} + 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: + 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) {} + 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 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 100755 index 0000000000000000000000000000000000000000..91651cce8350e119183cf2813f232f9d7ae37129 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h @@ -0,0 +1,308 @@ +/* + * 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: + 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 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 100755 index 0000000000000000000000000000000000000000..02c85ad2bca935053185089689a839a8baac7c96 --- /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 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 100755 index 0000000000000000000000000000000000000000..b391cfaf9ef4f7025e602915969ad466bb1af154 --- /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) {} + 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 100755 index 0000000000000000000000000000000000000000..8b4e85c1714e9857e63ba2bb7b93fb68f9c4ca8e --- /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 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 100755 index 0000000000000000000000000000000000000000..b4e0e9394a8200bd455f972bef3057ef619b8a59 --- /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) {} + 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 100755 index 0000000000000000000000000000000000000000..1c1589619871109c307495af8bf344e67bc41dc6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h @@ -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. + */ + +#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) {} + RelativeContainerComponent(ArkUI_NodeHandle handle) : Component(handle) {} + ~RelativeContainerComponent() = default; + + 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 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 100755 index 0000000000000000000000000000000000000000..397e6c6824d62a2fff8cedc0e55b39363c129087 --- /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) {} + 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 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 100755 index 0000000000000000000000000000000000000000..320f08f22d7afa98d35ef179b5539862e5a4e775 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.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 "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); + 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 100755 index 0000000000000000000000000000000000000000..882e64b1d031c865c9919d244298c2ccfdd29782 --- /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) {} + 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 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 100755 index 0000000000000000000000000000000000000000..10e913c610e58c67fa106eaa963999a4dbfee631 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.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 "swiper_component.h" + +#include +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) +{ + assert(_component && _nodeAPI && 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 100755 index 0000000000000000000000000000000000000000..3d756035dd0fa5b4c27baf74b442f7a4bd295daf --- /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) {} + 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 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 100755 index 0000000000000000000000000000000000000000..d1d1f88266d9d08d170bb141b0eaee8101612e7a --- /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 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 100755 index 0000000000000000000000000000000000000000..71eea91cdfa6c03c9171aa94f4c69fb93b1b1fed --- /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) {} + TextComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetFontSize(float fontSize); + 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 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 100755 index 0000000000000000000000000000000000000000..f1540cb2fde1bee37e3e716903418cd6cd12f2fb --- /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 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 100755 index 0000000000000000000000000000000000000000..51f138a53bb3a38ea5a33510db5b84be453804c7 --- /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) {} + 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 diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/flex/flex_options_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/flex/flex_options_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a5a2e02c859543bf18b0bd1e7f1b0c4591ba83f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/flex/flex_options_test.cpp @@ -0,0 +1,159 @@ +/* + * 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 "flex_options_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t backgroundColor) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_BUTTON); + // set width + ArkUI_NumberValue button_width_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem button_width_item = { button_width_value, + sizeof(button_width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &button_width_item); + // set height + ArkUI_NumberValue button_height_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_height_item = { button_height_value, + sizeof(button_height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &button_height_item); + + // set background color + ArkUI_NumberValue button1_background_color_value[] = { { .u32 = backgroundColor } }; + ArkUI_AttributeItem button1_background_color_item = { button1_background_color_value, + sizeof(button1_background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &button1_background_color_item); + return nodeHandle; +} + +static auto createFlexNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t* options) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_FLEX); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 200 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 70 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_BLUE)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, 0xFFC100FF)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_WHITE)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_PURPLE)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_LIGHT_BLUE)); + // set justifyContent + ArkUI_NumberValue options_value[] = { { .i32 = options[0] }, { .i32 = options[1] }, { .i32 = options[2] }, + { .i32 = options[3] }, { .i32 = options[4] } }; + ArkUI_AttributeItem options_item = { options_value, sizeof(options_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FLEX_OPTION, &options_item); + return nodeHandle; +} + +napi_value FlexOptionsTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "FlexOptionsTest", "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, "FlexOptionsTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + int32_t options1[] = { ARKUI_FLEX_DIRECTION_ROW, ARKUI_FLEX_WRAP_NO_WRAP, ARKUI_FLEX_ALIGNMENT_START, + ARKUI_ITEM_ALIGNMENT_AUTO, ARKUI_FLEX_ALIGNMENT_START }; + int32_t options2[] = { ARKUI_FLEX_DIRECTION_COLUMN, ARKUI_FLEX_WRAP_WRAP, ARKUI_FLEX_ALIGNMENT_CENTER, + ARKUI_ITEM_ALIGNMENT_START, ARKUI_FLEX_ALIGNMENT_CENTER }; + int32_t options3[] = { ARKUI_FLEX_DIRECTION_ROW_REVERSE, ARKUI_FLEX_WRAP_WRAP_REVERSE, ARKUI_FLEX_ALIGNMENT_END, + ARKUI_ITEM_ALIGNMENT_CENTER, ARKUI_FLEX_ALIGNMENT_END }; + int32_t options4[] = { ARKUI_FLEX_DIRECTION_COLUMN_REVERSE, ARKUI_FLEX_WRAP_WRAP, + ARKUI_FLEX_ALIGNMENT_SPACE_BETWEEN, ARKUI_ITEM_ALIGNMENT_END, ARKUI_FLEX_ALIGNMENT_SPACE_BETWEEN }; + int32_t options5[] = { ARKUI_FLEX_DIRECTION_COLUMN, ARKUI_FLEX_WRAP_WRAP, ARKUI_FLEX_ALIGNMENT_SPACE_AROUND, + ARKUI_ITEM_ALIGNMENT_STRETCH, ARKUI_FLEX_ALIGNMENT_SPACE_AROUND }; + int32_t options6[] = { ARKUI_FLEX_DIRECTION_COLUMN, ARKUI_FLEX_WRAP_NO_WRAP, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY, + ARKUI_ITEM_ALIGNMENT_BASELINE, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY }; + int32_t options7[] = { ARKUI_FLEX_DIRECTION_COLUMN, ARKUI_FLEX_WRAP_NO_WRAP, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY, + ARKUI_ITEM_ALIGNMENT_BASELINE, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY }; + int32_t options8[] = { ARKUI_FLEX_DIRECTION_COLUMN, ARKUI_FLEX_WRAP_NO_WRAP, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY, + ARKUI_ITEM_ALIGNMENT_BASELINE, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY }; + int32_t options9[] = { ARKUI_FLEX_DIRECTION_COLUMN, ARKUI_FLEX_WRAP_NO_WRAP, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY, + ARKUI_ITEM_ALIGNMENT_BASELINE, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY }; + int32_t options10[] = { -1, -1, -1, -1, -1 }; + auto flex1 = createFlexNode(nodeAPI, options1); + auto flex2 = createFlexNode(nodeAPI, options2); + auto flex3 = createFlexNode(nodeAPI, options3); + auto flex4 = createFlexNode(nodeAPI, options4); + auto flex5 = createFlexNode(nodeAPI, options5); + auto flex6 = createFlexNode(nodeAPI, options6); + auto flex7 = createFlexNode(nodeAPI, options7); + auto flex8 = createFlexNode(nodeAPI, options8); + auto flex9 = createFlexNode(nodeAPI, options9); + auto flex10 = createFlexNode(nodeAPI, options10); + nodeAPI->addChild(parentColumn, flex1); + nodeAPI->addChild(parentColumn, flex2); + nodeAPI->addChild(parentColumn, flex3); + nodeAPI->addChild(parentColumn, flex4); + nodeAPI->addChild(parentColumn, flex5); + nodeAPI->addChild(parentColumn, flex6); + nodeAPI->addChild(parentColumn, flex7); + nodeAPI->addChild(parentColumn, flex8); + nodeAPI->addChild(parentColumn, flex9); + nodeAPI->addChild(parentColumn, flex10); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "FlexOptionsTest", "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/flex/flex_options_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/flex/flex_options_test.h new file mode 100644 index 0000000000000000000000000000000000000000..4e6c3e3814043c2c23790a0fc117916109b16db2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/flex/flex_options_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_FLEX_OPTIONS_TEST_H +#define ARKUI_CAPI_DEMO_FLEX_OPTIONS_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class FlexOptionsTest { +public: + ~FlexOptionsTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_FLEX_OPTIONS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/grid/grid_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/grid/grid_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..63e26db1ee0acf9114c06387891efc322942c819 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/grid/grid_test.cpp @@ -0,0 +1,502 @@ +/* + * 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_test.h" + +#include + +#include "../manager/plugin_manager.h" +#include "button_component.h" +#include "column_component.h" +#include "component.h" +#include "flowitem_component.h" +#include "grid_component.h" +#include "text_component.h" + +namespace ArkUICApiDemo { +constexpr int32_t GRID_ITEM_COUNT = 24; +constexpr int32_t GRID_ITEM_COUNT_80 = 80; +static void OnAdapterEventReceive(ArkUI_NodeAdapterEvent* event) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + int type = OH_ArkUI_NodeAdapterEvent_GetType(event); + if (type == NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER) { + int32_t index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + auto gridItem = nodeAPI->createNode(ARKUI_NODE_GRID_ITEM); + + ArkUI_NumberValue width_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + + ArkUI_NumberValue height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + + ArkUI_NumberValue border_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem border_item = { border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue) }; + + ArkUI_NumberValue border_color_value[] = { { .u32 = COLOR_GRAY } }; + ArkUI_AttributeItem border_color_item = { border_color_value, + sizeof(border_color_value) / sizeof(ArkUI_NumberValue) }; + + auto text = nodeAPI->createNode(ARKUI_NODE_TEXT); + if (index == GRID_ITEM_COUNT_80 - 1) { + 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(gridItem, NODE_BACKGROUND_COLOR, &background_color_item); + + } else { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_YELLOW } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(gridItem, NODE_BACKGROUND_COLOR, &background_color_item); + } + + nodeAPI->setAttribute(gridItem, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(gridItem, NODE_BORDER_COLOR, &border_color_item); + nodeAPI->setAttribute(gridItem, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(gridItem, NODE_HEIGHT, &height_item); + nodeAPI->addChild(gridItem, text); + OH_ArkUI_NodeAdapterEvent_SetItem(event, gridItem); + } +} +void CreateGridItem(const std::shared_ptr>& adapter, bool isShowText = false) +{ + for (int i = 0; i < GRID_ITEM_COUNT; i++) { + auto item = std::make_shared(); + item->SetWidth(100); + item->SetHeight(100); + item->SetBackgroundColor(COLOR_YELLOW); + item->SetBorderWidth(1); + item->SetMargin(10); + auto text = std::make_shared(); + if (isShowText) { + text->SetTextContent(std::to_string(i)); + } + item->AddChild(text); + adapter->InsertItem(i, item); + } +} +napi_value GridTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "GridTest", "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, "GridTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置Grid宽 + ArkUI_NumberValue width_value[] = { { .f32 = 450 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Grid高 + ArkUI_NumberValue height_value[] = { { .f32 = 180 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + + // 设置margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + + ArkUI_NumberValue border_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem border_item = { border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue) }; + //------------------------------------------------------------------------------------------------------ + // 设置columnsTemplate:NODE_GRID_COLUMN_TEMPLATE + ArkUI_AttributeItem columnsTemplate_item = { .string = "1fr 1fr 1fr 1fr 1fr" }; + // 设置rowTemplate:NODE_GRID_ROW_TEMPLATE + ArkUI_AttributeItem rowTemplate_item = { .string = "1fr 1fr 1fr 1fr" }; + // 设置columnsGap:NODE_GRID_COLUMN_GAP + ArkUI_NumberValue columnsGap_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem columnsGap_item = { columnsGap_value, sizeof(columnsGap_value) / sizeof(ArkUI_NumberValue) }; + // 设置rowGap:NODE_GRID_ROW_GAP + ArkUI_NumberValue rowsGap_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem rowsGap_item = { rowsGap_value, sizeof(rowsGap_value) / sizeof(ArkUI_NumberValue) }; + + // 设置columnsTemplate异常值,NODE_GRID_COLUMN_TEMPLATE + ArkUI_AttributeItem outlier_columnsTemplate_item = { .string = "abc" }; + // 设置rowTemplate异常值,NODE_GRID_ROW_TEMPLATE + ArkUI_AttributeItem outlier_rowTemplate_item = { .string = "ddd,ccc" }; + // 设置columnsGap异常值,NODE_GRID_COLUMN_GAP + ArkUI_NumberValue outlier_columnsGap_value[] = { { .f32 = -1 } }; + ArkUI_AttributeItem outlier_columnsGap_item = { outlier_columnsGap_value, + sizeof(outlier_columnsGap_value) / sizeof(ArkUI_NumberValue) }; + // 设置rowGap异常值,NODE_GRID_ROW_GAP + ArkUI_NumberValue outlier_rowsGap_value[] = { { .f32 = -1 } }; + ArkUI_AttributeItem outlier_rowsGap_item = { outlier_rowsGap_value, + sizeof(outlier_rowsGap_value) / sizeof(ArkUI_NumberValue) }; + + // 设置cached count + ArkUI_NumberValue cachedValue[] = { { .i32 = 6 } }; + ArkUI_AttributeItem cachedItem = { cachedValue, sizeof(cachedValue) / sizeof(ArkUI_NumberValue) }; + + // 设置cached count + ArkUI_NumberValue outlier_cachedValue[] = { { .i32 = -1 } }; + ArkUI_AttributeItem outlier_cachedItem = { outlier_cachedValue, + sizeof(outlier_cachedValue) / sizeof(ArkUI_NumberValue) }; + + // 创建grid组件懒加载回调 + auto adapter = OH_ArkUI_NodeAdapter_Create(); + OH_ArkUI_NodeAdapter_RegisterEventReceiver(adapter, nullptr, &OnAdapterEventReceive); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(adapter, GRID_ITEM_COUNT_80); + ArkUI_AttributeItem adapterItem { .object = adapter }; + + auto adapter1 = OH_ArkUI_NodeAdapter_Create(); + OH_ArkUI_NodeAdapter_RegisterEventReceiver(adapter1, nullptr, &OnAdapterEventReceive); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(adapter1, GRID_ITEM_COUNT_80); + ArkUI_AttributeItem adapterItem1 { .object = adapter1 }; + + auto adapter2 = OH_ArkUI_NodeAdapter_Create(); + OH_ArkUI_NodeAdapter_RegisterEventReceiver(adapter2, nullptr, &OnAdapterEventReceive); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(adapter2, GRID_ITEM_COUNT_80); + ArkUI_AttributeItem adapterItem2 { .object = adapter2 }; + + auto adapter3 = OH_ArkUI_NodeAdapter_Create(); + OH_ArkUI_NodeAdapter_RegisterEventReceiver(adapter3, nullptr, &OnAdapterEventReceive); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(adapter3, GRID_ITEM_COUNT_80); + ArkUI_AttributeItem adapterItem3 { .object = adapter3 }; + + auto adapter4 = OH_ArkUI_NodeAdapter_Create(); + OH_ArkUI_NodeAdapter_RegisterEventReceiver(adapter4, nullptr, &OnAdapterEventReceive); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(adapter4, GRID_ITEM_COUNT_80); + ArkUI_AttributeItem adapterItem4 { .object = adapter4 }; + + // 创建grid组件,同时设置NODE_GRID_COLUMN_TEMPLATE,NODE_GRID_ROW_TEMPLATE,NODE_GRID_COLUMN_GAP,NODE_GRID_ROW_GAP + auto grid = nodeAPI->createNode(ARKUI_NODE_GRID); + nodeAPI->setAttribute(grid, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(grid, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(grid, NODE_GRID_COLUMN_TEMPLATE, &columnsTemplate_item); + nodeAPI->setAttribute(grid, NODE_GRID_ROW_TEMPLATE, &rowTemplate_item); + nodeAPI->setAttribute(grid, NODE_GRID_COLUMN_GAP, &columnsGap_item); + nodeAPI->setAttribute(grid, NODE_GRID_ROW_GAP, &rowsGap_item); + nodeAPI->setAttribute(grid, NODE_GRID_NODE_ADAPTER, &adapterItem); + nodeAPI->setAttribute(grid, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(grid, NODE_MARGIN, &margin_item); + + // 创建grid组件,只设置NODE_GRID_COLUMN_TEMPLATE,NODE_GRID_COLUMN_GAP,NODE_GRID_ROW_GAP,,NODE_GRID_CACHED_COUNT异常值 + auto grid1Column = new ColumnComponent(); + grid1Column->SetId("grid1"); + auto grid1 = nodeAPI->createNode(ARKUI_NODE_GRID); + nodeAPI->setAttribute(grid1, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(grid1, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(grid1, NODE_GRID_COLUMN_TEMPLATE, &columnsTemplate_item); + nodeAPI->setAttribute(grid1, NODE_GRID_COLUMN_GAP, &columnsGap_item); + nodeAPI->setAttribute(grid1, NODE_GRID_ROW_GAP, &rowsGap_item); + nodeAPI->setAttribute(grid1, NODE_GRID_NODE_ADAPTER, &adapterItem1); + nodeAPI->setAttribute(grid1, NODE_GRID_CACHED_COUNT, &outlier_cachedItem); + nodeAPI->setAttribute(grid1, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(grid1, NODE_MARGIN, &margin_item); + + // 创建grid组件,只设置NODE_GRID_ROW_TEMPLATE,NODE_GRID_COLUMN_GAP,NODE_GRID_ROW_GAP,NODE_GRID_CACHED_COUNT正常值 + auto grid2Column = new ColumnComponent(); + grid2Column->SetId("grid2"); + auto grid2 = nodeAPI->createNode(ARKUI_NODE_GRID); + nodeAPI->setAttribute(grid2, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(grid2, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(grid2, NODE_GRID_ROW_TEMPLATE, &rowTemplate_item); + nodeAPI->setAttribute(grid2, NODE_GRID_COLUMN_GAP, &columnsGap_item); + nodeAPI->setAttribute(grid2, NODE_GRID_ROW_GAP, &rowsGap_item); + nodeAPI->setAttribute(grid2, NODE_GRID_NODE_ADAPTER, &adapterItem2); + nodeAPI->setAttribute(grid2, NODE_GRID_CACHED_COUNT, &cachedItem); + nodeAPI->setAttribute(grid2, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(grid2, NODE_MARGIN, &margin_item); + + // 创建grid组件,设置异常值:NODE_GRID_COLUMN_GAP,NODE_GRID_ROW_TEMPLATE + ArkUI_NumberValue width_value3[] = { { .f32 = 230 } }; + ArkUI_AttributeItem width_item3 = { width_value3, sizeof(width_value3) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue height_value3[] = { { .f32 = 180 } }; + ArkUI_AttributeItem height_item3 = { height_value3, sizeof(height_value3) / sizeof(ArkUI_NumberValue) }; + auto grid3 = nodeAPI->createNode(ARKUI_NODE_GRID); + nodeAPI->setAttribute(grid3, NODE_WIDTH, &width_item3); + nodeAPI->setAttribute(grid3, NODE_HEIGHT, &height_item3); + nodeAPI->setAttribute(grid3, NODE_GRID_COLUMN_TEMPLATE, &outlier_columnsTemplate_item); + nodeAPI->setAttribute(grid3, NODE_GRID_ROW_TEMPLATE, &outlier_rowTemplate_item); + nodeAPI->setAttribute(grid3, NODE_GRID_NODE_ADAPTER, &adapterItem3); + nodeAPI->setAttribute(grid3, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(grid3, NODE_MARGIN, &margin_item); + + // 创建grid组件,设置异常值:NODE_GRID_COLUMN_GAP,NODE_GRID_ROW_GAP + auto grid4 = nodeAPI->createNode(ARKUI_NODE_GRID); + nodeAPI->setAttribute(grid4, NODE_WIDTH, &width_item3); + nodeAPI->setAttribute(grid4, NODE_HEIGHT, &height_item3); + nodeAPI->setAttribute(grid4, NODE_GRID_COLUMN_GAP, &outlier_columnsGap_item); + nodeAPI->setAttribute(grid4, NODE_GRID_ROW_GAP, &outlier_rowsGap_item); + nodeAPI->setAttribute(grid4, NODE_GRID_NODE_ADAPTER, &adapterItem4); + nodeAPI->setAttribute(grid4, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(grid4, NODE_MARGIN, &margin_item); + + // parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + nodeAPI->addChild(parentColumn, grid); + nodeAPI->addChild(parentColumn, grid1Column->GetComponent()); + nodeAPI->addChild(grid1Column->GetComponent(), grid1); + nodeAPI->addChild(parentColumn, grid2Column->GetComponent()); + nodeAPI->addChild(grid2Column->GetComponent(), grid2); + nodeAPI->addChild(parentColumn, row); + nodeAPI->addChild(row, grid3); + nodeAPI->addChild(row, grid4); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "GridTest", "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 GridTest::CreateNativeNodeForCachedCount(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "GridTest", "CreateNativeNodeForCachedCount"); + 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, "GridTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto parentColumn = new ColumnComponent(); + auto grid1Column = new ColumnComponent(); + grid1Column->SetId("gridCachedCount1"); + auto grid1 = new GridComponent(); + grid1->SetWidth(450); + grid1->SetHeight(200); + grid1->SetGridRowsTemplate("1fr 1fr 1fr 1fr"); + grid1->SetBorderWidth(5); + + std::vector> input1; + auto adapter1 = std::make_shared>(input1); + grid1->SetLazyAdapter(adapter1); + // 设置cacheCount异常值:-1 + grid1->SetGridCachedCount(-1); + CreateGridItem(adapter1); + + auto grid2 = new GridComponent(); + auto grid2Column = new ColumnComponent(); + grid2Column->SetId("gridCachedCount2"); + grid2->SetWidth(450); + grid2->SetHeight(200); + grid2->SetGridColumnsTemplate("1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr"); + grid2->SetBorderWidth(5); + std::vector> input2; + auto adapter2 = std::make_shared>(input2); + grid2->SetLazyAdapter(adapter2); + // 设置cacheCount异常值:0 + grid2->SetGridCachedCount(0); + CreateGridItem(adapter2); + + auto grid3 = new GridComponent(); + auto grid3Column = new ColumnComponent(); + grid3Column->SetId("gridCachedCount3"); + grid3->SetWidth(450); + grid3->SetHeight(200); + grid3->SetBorderWidth(5); + grid3->SetGridRowsTemplate("1fr 1fr 1fr"); + std::vector> input3; + auto adapter3 = std::make_shared>(input3); + grid3->SetLazyAdapter(adapter3); + // 设置cacheCount正常值2 + grid3->SetGridCachedCount(2); + CreateGridItem(adapter3); + + auto button = new ButtonComponent(); + button->SetWidth(100); + button->SetHeight(50); + button->SetMargin(10); + button->SetId("gridClick"); + button->RegisterOnClick([adapter1, adapter2, adapter3]() { + adapter1->SetAllItem([](std::shared_ptr item, uint32_t index) { + auto children = item->GetChildren(); + if (!children.empty()) { + children.front()->SetBackgroundColor(COLOR_GREEN); + } + }); + adapter2->SetAllItem([](std::shared_ptr item, uint32_t index) { + auto children = item->GetChildren(); + if (!children.empty()) { + children.front()->SetBackgroundColor(COLOR_GREEN); + } + }); + adapter3->SetAllItem([](std::shared_ptr item, uint32_t index) { + auto children = item->GetChildren(); + if (!children.empty()) { + children.front()->SetBackgroundColor(COLOR_GREEN); + } + }); + }); + + parentColumn->AddChild(std::shared_ptr(grid1Column)); + grid1Column->AddChild(std::shared_ptr(grid1)); + + parentColumn->AddChild(std::shared_ptr(grid2Column)); + grid2Column->AddChild(std::shared_ptr(grid2)); + + parentColumn->AddChild(std::shared_ptr(grid3Column)); + grid3Column->AddChild(std::shared_ptr(grid3)); + + parentColumn->AddChild(std::shared_ptr(button)); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "GridTest", "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 GridTest::CreateNativeNodeForResetAttribute(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "GridTest", "CreateNativeNodeForResetAttribute"); + 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, "GridTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto parentColumn = new ColumnComponent(); + auto grid1Column = new ColumnComponent(); + auto grid1 = new GridComponent(); + grid1->SetWidth(400); + grid1->SetHeight(180); + grid1->SetGridRowsTemplate("1fr 1fr 1fr 1fr"); + grid1->SetBorderWidth(5); + + std::vector> input1; + auto adapter1 = std::make_shared>(input1); + grid1->SetLazyAdapter(adapter1); + CreateGridItem(adapter1, false); + + auto grid2 = new GridComponent(); + auto grid2Column = new ColumnComponent(); + grid2->SetWidth(400); + grid2->SetHeight(180); + grid2->SetGridColumnsTemplate("1fr 1fr 1fr 1fr 1fr"); + grid2->SetBorderWidth(5); + std::vector> input2; + auto adapter2 = std::make_shared>(input2); + grid2->SetLazyAdapter(adapter2); + CreateGridItem(adapter2, false); + + auto grid3 = new GridComponent(); + auto grid3Column = new ColumnComponent(); + grid3->SetWidth(400); + grid3->SetHeight(180); + grid3->SetBorderWidth(5); + grid3->SetGridColumnsTemplate("1fr 1fr 1fr 1fr 1fr"); + grid3->SetGridRowsGap(10); + grid3->SetGridColumnsGap(10); + std::vector> input3; + auto adapter3 = std::make_shared>(input3); + grid3->SetLazyAdapter(adapter3); + CreateGridItem(adapter3, false); + + auto grid4 = new GridComponent(); + auto grid4Column = new ColumnComponent(); + grid4->SetWidth(400); + grid4->SetHeight(180); + grid4->SetBorderWidth(5); + grid4->SetGridRowsGap(10); + grid4->SetGridRowsTemplate("1fr 1fr 1fr 1fr"); + std::vector> input4; + auto adapter4 = std::make_shared>(input4); + grid4->SetLazyAdapter(adapter4); + CreateGridItem(adapter4, false); + + auto button = new ButtonComponent(); + button->SetWidth(100); + button->SetHeight(50); + button->SetMargin(10); + button->SetId("GridReset"); + button->RegisterOnClick([grid1, grid2, grid3, grid4]() { + grid1->resetAttribute(NODE_GRID_ROW_TEMPLATE); // 默认值:"1r" + grid2->resetAttribute(NODE_GRID_COLUMN_TEMPLATE); // 默认值:"1r" + grid3->resetAttribute(NODE_GRID_COLUMN_GAP); // 默认值:0 + grid4->resetAttribute(NODE_GRID_ROW_GAP); // 默认值:0 + }); + + parentColumn->AddChild(std::shared_ptr(grid1Column)); + grid1Column->AddChild(std::shared_ptr(grid1)); + + parentColumn->AddChild(std::shared_ptr(grid2Column)); + grid2Column->AddChild(std::shared_ptr(grid2)); + + parentColumn->AddChild(std::shared_ptr(grid3Column)); + grid3Column->AddChild(std::shared_ptr(grid3)); + + parentColumn->AddChild(std::shared_ptr(grid4Column)); + grid3Column->AddChild(std::shared_ptr(grid4)); + + parentColumn->AddChild(std::shared_ptr(button)); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "GridTest", "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/grid/grid_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/grid/grid_test.h new file mode 100644 index 0000000000000000000000000000000000000000..e06b1256ffb9d2915df6c35a6424d13c4640670f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/grid/grid_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_GRID_TEST_H +#define ARKUI_CAPI_DEMO_GRID_TEST_H +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class GridTest { +public: + ~GridTest(); + // GridTest:testGrid001 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + // Testcase:testGrid002 + static napi_value CreateNativeNodeForCachedCount(napi_env env, napi_callback_info info); + // Testcase:testGrid003 + static napi_value CreateNativeNodeForResetAttribute(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_GRID_TEST_H 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 100755 index 0000000000000000000000000000000000000000..1a052cd14a2d4faf31964e32ee40181ec8eac383 --- /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 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 100755 index 0000000000000000000000000000000000000000..6ee79d601f5b1512be5baee3d3628e43691b9474 --- /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 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 100755 index 0000000000000000000000000000000000000000..605e45ff64a34fd0027ab8554578444c41414790 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,99 @@ +/* + * 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 "column/column_align_items_test.h" +#include "column/column_justify_content_test.h" +#include "flex/flex_options_test.h" +#include "grid/grid_test.h" +#include "manager/plugin_manager.h" +#include "radio/radio_checked_test.h" +#include "radio/radio_reset_attribute_test.h" +#include "radio/radio_style_test.h" +#include "radio/radio_value_group_test.h" +#include "refresh/refresh_test.h" +#include "row/row_align_items_test.h" +#include "row/row_justify_content_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[] = { + { "columnJustifyContentTest", nullptr, ColumnJustifyContentTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "columnAlignItemsTest", nullptr, ColumnAlignItemsTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "columnAlignItemsMoreAttributeTest", nullptr, ColumnAlignItemsTest::CreateMoreAttributeNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "rowJustifyContentTest", nullptr, RowJustifyContentTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "rowAlignItemsTest", nullptr, RowAlignItemsTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "rowAlignItemsMoreAttributeTest", nullptr, RowAlignItemsTest::CreateMoreAttributeNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "flexOptionsTest", nullptr, FlexOptionsTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "radioCheckedTest", nullptr, RadioCheckedTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "radioStyleTest", nullptr, RadioStyleTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "radioValueAndGroupTest", nullptr, RadioValueAndGroupTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "radioResetAttributeTest", nullptr, RadioResetAttributeTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "gridTest", nullptr, GridTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "gridCachedCountTest", nullptr, GridTest::CreateNativeNodeForCachedCount, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "gridResetAttributeTest", nullptr, GridTest::CreateNativeNodeForResetAttribute, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "refreshForContentAndRatioTest", nullptr, RefreshTest::CreateNativeNodeForRefreshContentAndRatio, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "refreshForRefreshingTest", nullptr, RefreshTest::CreateNativeNodeForRefreshing, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "refreshTest", nullptr, RefreshTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "refreshNestedScrollTest", nullptr, RefreshTest::CreateNativeNodeNestedScroll, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "refreshResetAttributeTest", nullptr, RefreshTest::CreateNativeNodeForResetAttribute, 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/radio/radio_checked_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_checked_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3032c03f175e24c529638e6c527048ba7052c0b6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_checked_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 "radio_checked_test.h" + +#include + +#include "../manager/plugin_manager.h" +namespace ArkUICApiDemo { +napi_value RadioCheckedTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioCheckedTest", "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, "RadioCheckedTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置Radio组件的Checked属性 + ArkUI_NumberValue true_checked_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem true_checked_item = { true_checked_value, + sizeof(true_checked_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件的Checked属性 + ArkUI_NumberValue false_checked_value[] = { { .i32 = 0 } }; + ArkUI_AttributeItem false_checked_item = { false_checked_value, + sizeof(false_checked_value) / sizeof(ArkUI_NumberValue) }; + // 设置Radio组件的Checked属性 + ArkUI_NumberValue outlier_checked_value[] = { { .i32 = -1 } }; + ArkUI_AttributeItem outlier_checked_item = { outlier_checked_value, + sizeof(outlier_checked_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件宽度 + ArkUI_NumberValue default_width_value[] = { { .f32 = 100 } }; + ArkUI_AttributeItem default_width_item = { default_width_value, + sizeof(default_width_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件高度 + ArkUI_NumberValue default_height_value[] = { { .f32 = 100 } }; + ArkUI_AttributeItem default_height_item = { default_height_value, + sizeof(default_height_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件margin + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + + // first radio, checked 属性为1,应该为选中状态 + auto radio = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio, NODE_RADIO_CHECKED, &true_checked_item); + + // second radio, checked 属性为0,应该为未选中状态 + auto radio_second = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_second, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_second, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_second, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio_second, NODE_RADIO_CHECKED, &false_checked_item); + + // third radio, 设置异常值-1, 返回错误,应该为未选中状态 + auto radio_third = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_third, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_third, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_third, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio_second, NODE_RADIO_CHECKED, &outlier_checked_item); + + // parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto row2 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto row3 = nodeAPI->createNode(ARKUI_NODE_ROW); + + nodeAPI->addChild(parentColumn, row1); + nodeAPI->addChild(parentColumn, row2); + nodeAPI->addChild(parentColumn, row3); + nodeAPI->addChild(row1, radio); + nodeAPI->addChild(row2, radio_second); + nodeAPI->addChild(row3, radio_third); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioCheckedTest", + "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/radio/radio_checked_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_checked_test.h new file mode 100644 index 0000000000000000000000000000000000000000..276585ae7d70966196b2cd62de7d2136b21be90d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_checked_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_RADIO_CHECKED_TEST_H +#define ARKUI_CAPI_DEMO_RADIO_CHECKED_TEST_H +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RadioCheckedTest { +public: + ~RadioCheckedTest(); + // RadioTest:testRadio001 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_CHECKED_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_reset_attribute_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_reset_attribute_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a32b5218f5b22ed7665af9c8fd57b7b43985080 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_reset_attribute_test.cpp @@ -0,0 +1,113 @@ +/* + * 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_reset_attribute_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" +#include "button_component.h" +#include "column_component.h" +#include "radio_component.h" +namespace ArkUICApiDemo { +napi_value RadioResetAttributeTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioResetAttributeTest", "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, "RadioResetAttributeTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto parentColumn = new ColumnComponent(); + auto radio1 = new RadioComponent(); + radio1->SetWidth(100); + radio1->SetHeight(100); + radio1->SetChecked(true); + // 设置Radio组件的RadioStyle属性,checkedBackgroundColor:绿色;uncheckedBorderColor:紫色,indicatorColor:红色 + radio1->SetStyled((uint32_t[]) { COLOR_GREEN, COLOR_PURPLE, COLOR_RED }, 3); + radio1->SetGroup("group1"); + radio1->SetValue("radio1"); + radio1->SetMargin(10); + + auto radio2 = new RadioComponent(); + radio2->SetWidth(100); + radio2->SetHeight(100); + radio2->SetChecked(true); + // 设置Radio组件的RadioStyle属性,checkedBackgroundColor:绿色;uncheckedBorderColor:紫色,indicatorColor:红色 + radio2->SetStyled((uint32_t[]) { COLOR_GREEN, COLOR_PURPLE, COLOR_RED }, 3); + radio2->SetGroup("group2"); + radio2->SetValue("radio2"); + radio2->SetMargin(10); + + auto radio3 = new RadioComponent(); + radio3->SetWidth(100); + radio3->SetHeight(100); + // 设置Radio组件的RadioStyle属性,checkedBackgroundColor:绿色;uncheckedBorderColor:紫色,indicatorColor:红色 + // radio 非选中状态下,border颜色为紫色 + radio3->SetStyled((uint32_t[]) { COLOR_GREEN, COLOR_PURPLE, COLOR_RED }, 3); + radio3->SetMargin(10); + + auto button = new ButtonComponent(); + button->SetWidth(200); + button->SetHeight(100); + button->RegisterOnClick([radio1, radio2, radio3]() { + // Reset radio1 NODE_RADIO_CHECKED,NODE_RADIO_GROUP,NODE_RADIO_STYLE,NODE_RADIO_VALUE + radio1->resetAttribute(NODE_RADIO_CHECKED); // 默认值:false + radio1->resetAttribute(NODE_RADIO_GROUP); // 默认值:无 + radio1->resetAttribute(NODE_RADIO_STYLE); // 默认值:theme主题 + radio1->resetAttribute(NODE_RADIO_VALUE); // 默认值:无 + // Reset radio3 NODE_RADIO_STYLE + radio3->resetAttribute(NODE_RADIO_STYLE); + auto groupItem1 = radio1->getAttribute(NODE_RADIO_GROUP); + auto valueItem1 = radio1->getAttribute(NODE_RADIO_VALUE); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioResetAttributeTest", + "group1=%{public}s,valueItem1=%{public}s", groupItem1->string, valueItem1->string); + }); + button->SetId("ResetRadio"); + button->SetLable("ResetRadio"); + parentColumn->AddChild(std::shared_ptr(radio1)); + parentColumn->AddChild(std::shared_ptr(radio2)); + parentColumn->AddChild(std::shared_ptr(radio3)); + parentColumn->AddChild(std::shared_ptr(button)); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn->GetComponent()) == INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioResetAttributeTest", + "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/radio/radio_reset_attribute_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_reset_attribute_test.h new file mode 100644 index 0000000000000000000000000000000000000000..50d9da3bd090ac913b48f493281379d9e689d74d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_reset_attribute_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_RADIO_RESETATTRIBUTE_TEST_H +#define ARKUI_CAPI_DEMO_RADIO_RESETATTRIBUTE_TEST_H +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RadioResetAttributeTest { +public: + ~RadioResetAttributeTest(); + // RadioTest:testRadio005 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_RESETATTRIBUTE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_style_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_style_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cdeac8810282ce419044e304ea646e2c3919fa35 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_style_test.cpp @@ -0,0 +1,140 @@ +/* + * 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_style_test.h" + +#include + +#include "../manager/plugin_manager.h" +namespace ArkUICApiDemo { +napi_value RadioStyleTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioStyleTest", "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, "RadioStyleTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置Radio组件的RadioStyle属性,checkedBackgroundColor:绿色;uncheckedBorderColor:黄色,indicatorColor:红色 + ArkUI_NumberValue radioStyle_value[] = { { .u32 = COLOR_GREEN }, { .u32 = COLOR_YELLOW }, { .u32 = COLOR_RED } }; + ArkUI_AttributeItem radioStyle_value_item = { radioStyle_value, + sizeof(radioStyle_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件宽度 + ArkUI_NumberValue default_width_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem default_width_item = { default_width_value, + sizeof(default_width_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件高度 + ArkUI_NumberValue default_height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem default_height_item = { default_height_value, + sizeof(default_height_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件margin + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件选中 + ArkUI_NumberValue true_checked_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem true_checked_item = { true_checked_value, + sizeof(true_checked_value) / sizeof(ArkUI_NumberValue) }; + + // first radio, 设置Radio Style 并且是uncheck状态 + auto radio = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio, NODE_RADIO_STYLE, &radioStyle_value_item); + + // second radio, 不设置置Radio Style,显示默认状态 + auto radio_second = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_second, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_second, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_second, NODE_MARGIN, &margin_item); + + // third radio, 设置Radio Style 并且check状态 + auto radio_third = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_third, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_third, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_third, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio_third, NODE_RADIO_CHECKED, &true_checked_item); + nodeAPI->setAttribute(radio_third, NODE_RADIO_STYLE, &radioStyle_value_item); + + auto text = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item = { .string = "Radio_unchecked" }; + ArkUI_NumberValue fontSize[] = { 20 }; + ArkUI_AttributeItem Font_Item = { fontSize, 1 }; + ArkUI_NumberValue marginValue[] = { 20 }; + ArkUI_AttributeItem marginItem = { marginValue, 1 }; + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &LABEL_Item); + nodeAPI->setAttribute(text, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text, NODE_MARGIN, &marginItem); + + auto text2 = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item2 = { .string = "Radio_defalut" }; + nodeAPI->setAttribute(text2, NODE_TEXT_CONTENT, &LABEL_Item2); + nodeAPI->setAttribute(text2, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text2, NODE_MARGIN, &marginItem); + + auto text3 = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item3 = { .string = "Radio_checked" }; + nodeAPI->setAttribute(text3, NODE_TEXT_CONTENT, &LABEL_Item3); + nodeAPI->setAttribute(text3, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text3, NODE_MARGIN, &marginItem); + + // parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto row2 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto row3 = nodeAPI->createNode(ARKUI_NODE_ROW); + + nodeAPI->addChild(parentColumn, row1); + nodeAPI->addChild(parentColumn, row2); + nodeAPI->addChild(parentColumn, row3); + nodeAPI->addChild(row1, text); + nodeAPI->addChild(row1, radio); + nodeAPI->addChild(row2, text2); + nodeAPI->addChild(row2, radio_second); + nodeAPI->addChild(row3, text3); + nodeAPI->addChild(row3, radio_third); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioStyleTest", "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/radio/radio_style_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_style_test.h new file mode 100644 index 0000000000000000000000000000000000000000..1ced03262796e45295a90584ed4b697fa6954a2b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_style_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_RADIO_STYLE_TEST_H +#define ARKUI_CAPI_DEMO_RADIO_STYLE_TEST_H +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RadioStyleTest { +public: + ~RadioStyleTest(); + // RadioTest:testRadio002 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_STYLE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_value_group_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_value_group_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b9b052fe6e0cc8097dc4c14d9fa2e91e8b0c048 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_value_group_test.cpp @@ -0,0 +1,200 @@ +/* + * 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_value_group_test.h" + +#include + +#include "../manager/plugin_manager.h" +#include "row_component.h" +#define COLOR_RED 0xFFFF0000 +#define INVALID_PARAM 401 +#define ON_RADIO_EVENT_ID 1414 + +namespace ArkUICApiDemo { +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + // 当触发Change事件,修改背景色 + if (ON_RADIO_EVENT_ID == eventId) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_YELLOW } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + auto text = static_cast(OH_ArkUI_NodeEvent_GetUserData(event)); + auto lable_Item = nodeAPI->getAttribute(nodeHandler, NODE_RADIO_VALUE); + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, lable_Item); + } +} + +napi_value RadioValueAndGroupTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioValueAndGroupTest", "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, "RadioValueAndGroupTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置Radio组件的Checked属性 + ArkUI_NumberValue true_checked_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem true_checked_item = { true_checked_value, + sizeof(true_checked_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件宽度 + ArkUI_NumberValue default_width_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem default_width_item = { default_width_value, + sizeof(default_width_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件高度 + ArkUI_NumberValue default_height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem default_height_item = { default_height_value, + sizeof(default_height_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件margin + ArkUI_NumberValue margin_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + + //---------------------------------------------------------------------------------------------------- + // 设置Radio value + ArkUI_AttributeItem radio_value1_Item = { .string = "radio" }; + ArkUI_AttributeItem radio_value2_Item = { .string = "radio_value1.2" }; + ArkUI_AttributeItem radio_value3_Item = { .string = "radio_value2.1" }; + ArkUI_AttributeItem radio_value4_Item = { .string = "radio_value2.2" }; + // 设置Radio group + ArkUI_AttributeItem radio_group1_Item = { .string = "group1" }; + ArkUI_AttributeItem radio_group2_Item = { .string = "group2" }; + + // first radio, 设置Radio value,设置group属于group1,同一个group1有一个可以是选中状态 + auto radio = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio, NODE_RADIO_CHECKED, &true_checked_item); + nodeAPI->setAttribute(radio, NODE_RADIO_VALUE, &radio_value1_Item); + nodeAPI->setAttribute(radio, NODE_RADIO_GROUP, &radio_group1_Item); + + // second radio, 设置Radio value,设置group属于group1 + auto radio_second = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_second, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_second, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_second, NODE_RADIO_VALUE, &radio_value2_Item); + nodeAPI->setAttribute(radio_second, NODE_RADIO_GROUP, &radio_group1_Item); + + // third radio, 设置Radio value,设置group属于group2 + auto radio_third = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_third, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_third, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_third, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio_third, NODE_RADIO_CHECKED, &true_checked_item); + nodeAPI->setAttribute(radio_third, NODE_RADIO_VALUE, &radio_value3_Item); + nodeAPI->setAttribute(radio_third, NODE_RADIO_GROUP, &radio_group2_Item); + + // third radio,, 设置Radio value,设置group属于group2 + auto radio_forth = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio_forth, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio_forth, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio_forth, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(radio_forth, NODE_RADIO_VALUE, &radio_value4_Item); + nodeAPI->setAttribute(radio_forth, NODE_RADIO_GROUP, &radio_group2_Item); + + auto text = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item = { .string = "radio_value1.1" }; + ArkUI_NumberValue fontSize[] = { 20 }; + ArkUI_AttributeItem Font_Item = { fontSize, 1 }; + + ArkUI_NumberValue marginValue[] = { 20 }; + ArkUI_AttributeItem marginItem = { marginValue, 1 }; + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &LABEL_Item); + nodeAPI->setAttribute(text, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text, NODE_MARGIN, &marginItem); + + auto text2 = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item2 = { .string = "radio_value1.2" }; + nodeAPI->setAttribute(text2, NODE_TEXT_CONTENT, &LABEL_Item2); + nodeAPI->setAttribute(text2, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text2, NODE_MARGIN, &marginItem); + + auto text3 = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item3 = { .string = "radio_value2.1" }; + nodeAPI->setAttribute(text3, NODE_TEXT_CONTENT, &LABEL_Item3); + nodeAPI->setAttribute(text3, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text3, NODE_MARGIN, &marginItem); + + auto text4 = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item4 = { .string = "radio_value2.2" }; + nodeAPI->setAttribute(text4, NODE_TEXT_CONTENT, &LABEL_Item4); + nodeAPI->setAttribute(text4, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text4, NODE_MARGIN, &marginItem); + + // parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = new RowComponent(); + auto row2 = new RowComponent(); + auto row3 = new RowComponent(); + auto row4 = new RowComponent(); + + nodeAPI->addChild(parentColumn, row1->GetComponent()); + nodeAPI->addChild(parentColumn, row2->GetComponent()); + nodeAPI->addChild(parentColumn, row3->GetComponent()); + nodeAPI->addChild(parentColumn, row4->GetComponent()); + nodeAPI->addChild(row1->GetComponent(), text); + nodeAPI->addChild(row1->GetComponent(), radio); + nodeAPI->addChild(row2->GetComponent(), text2); + nodeAPI->addChild(row2->GetComponent(), radio_second); + nodeAPI->addChild(row3->GetComponent(), text3); + nodeAPI->addChild(row3->GetComponent(), radio_third); + nodeAPI->addChild(row4->GetComponent(), text4); + nodeAPI->addChild(row4->GetComponent(), radio_forth); + + // 设置组件Id + ArkUI_AttributeItem idItem; + idItem.string = "radioOnChange"; + nodeAPI->setAttribute(radio_second, NODE_ID, &idItem); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + nodeAPI->registerNodeEvent(radio, NODE_RADIO_EVENT_ON_CHANGE, ON_RADIO_EVENT_ID, text); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RadioValueAndGroupTest", + "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/radio/radio_value_group_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_value_group_test.h new file mode 100644 index 0000000000000000000000000000000000000000..d284f3bb5d90a8f8aa7dbfe4f7602d71920fd68c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/radio/radio_value_group_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_RADIO_VALUE_GROUP_TEST_H +#define ARKUI_CAPI_DEMO_RADIO_VALUE_GROUP_TEST_H +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RadioValueAndGroupTest { +public: + ~RadioValueAndGroupTest(); + // RadioTest:testRadio003,testRadio004 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_VALUE_GROUP_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/refresh/refresh_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/refresh/refresh_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0aedc06737a8ed6deb6415e815548d0320f5848c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/refresh/refresh_test.cpp @@ -0,0 +1,543 @@ +/* + * 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_test.h" + +#include +#include +#include + +#include "../manager/plugin_manager.h" +#include "button_component.h" +#include "column_component.h" +#include "refresh_component.h" +#include "scroll_component.h" +#include "text_component.h" +#include "waterflow_component.h" +#define COLOR_RED 0xFFFF0000 +#define INVALID_PARAM 401 +#define ON_REFRESH_EVENT_ID 1314 +#define ON_REFRESH_EVENT_ID_SLEEP 1315 // content and radio +constexpr int32_t FLOW_ITEM_COUNT = 15; + +namespace ArkUICApiDemo { + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + int32_t eventType = OH_ArkUI_NodeEvent_GetEventType(event); + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 当触发刷新事件时,设置refreshing属性为0,并通过radio的checked属性展示 + if (eventType == NODE_REFRESH_ON_REFRESH) { + if (ON_REFRESH_EVENT_ID == eventId) { + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + auto radio = static_cast(OH_ArkUI_NodeEvent_GetUserData(event)); + ArkUI_NumberValue refreshing_value[] = { { .i32 = 0 } }; + ArkUI_AttributeItem refreshing_item = { refreshing_value, + sizeof(refreshing_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_REFRESH_REFRESHING, &refreshing_item); + + auto refreshing_attr = nodeAPI->getAttribute(nodeHandler, NODE_REFRESH_REFRESHING); + ArkUI_NumberValue checked_value[] = { { .i32 = static_cast(refreshing_attr->value[0].f32) } }; + ArkUI_AttributeItem checked_item = { checked_value, sizeof(checked_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(radio, NODE_RADIO_CHECKED, &checked_item); + } else if (ON_REFRESH_EVENT_ID_SLEEP == eventId) { + std::this_thread::sleep_for(std::chrono::seconds(4)); + } + + } else if (ON_REFRESH_EVENT_ID == eventId && eventType == NODE_REFRESH_ON_OFFSET_CHANGE) { + auto refresh = OH_ArkUI_NodeEvent_GetNodeHandle(event); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + float offset = result->data[0].f32; + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "refreshTest", "offset=%{public}f", offset); + // 设置背景色 + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_YELLOW } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(refresh, NODE_BACKGROUND_COLOR, &background_color_item); + } +} +static void CreateRefreshingComponent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& refreshingComponent) +{ + // clip + ArkUI_NumberValue clip_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem clip_item = { clip_value, sizeof(clip_value) / sizeof(ArkUI_NumberValue) }; + refreshingComponent = nodeAPI->createNode(ARKUI_NODE_STACK); + nodeAPI->setAttribute(refreshingComponent, NODE_CLIP, &clip_item); + + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + // process height + ArkUI_NumberValue height_value[] = { { .f32 = 32 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + + // margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + + auto loadingProgress = nodeAPI->createNode(ARKUI_NODE_LOADING_PROGRESS); + nodeAPI->setAttribute(loadingProgress, NODE_HEIGHT, &height_item); + + auto text = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem LABEL_Item = { .string = "refreshing..." }; + ArkUI_NumberValue fontSize[] = { 16 }; + ArkUI_AttributeItem Font_Item = { fontSize, 1 }; + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &LABEL_Item); + nodeAPI->setAttribute(text, NODE_TEXT_FONT, &Font_Item); + nodeAPI->setAttribute(text, NODE_MARGIN, &margin_item); + + nodeAPI->addChild(refreshingComponent, row); + nodeAPI->addChild(row, text); +} +static void CreateList(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& list, float width = 400, float height = 230) +{ + // 创建List + ArkUI_NumberValue list_width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem list_width_item = { list_width_value, sizeof(list_width_value) / sizeof(ArkUI_NumberValue) }; + + ArkUI_NumberValue list_height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem list_height_item = { list_height_value, sizeof(list_height_value) / sizeof(ArkUI_NumberValue) }; + + list = nodeAPI->createNode(ARKUI_NODE_LIST); + nodeAPI->setAttribute(list, NODE_WIDTH, &list_width_item); + nodeAPI->setAttribute(list, NODE_HEIGHT, &list_height_item); + + // 设置list item border + ArkUI_NumberValue border_value[] = { { .f32 = 1 } }; + ArkUI_AttributeItem border_item = { border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue) }; + // 设置设置list item margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + + // 设置设置list item宽 + ArkUI_NumberValue listitem_width_value[] = { { .f32 = 350 } }; + ArkUI_AttributeItem listitem_width_item = { listitem_width_value, + sizeof(listitem_width_value) / sizeof(ArkUI_NumberValue) }; + + // 设置设置list item高 + ArkUI_NumberValue listitem_height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem listitem_height_item = { listitem_height_value, + sizeof(listitem_height_value) / sizeof(ArkUI_NumberValue) }; + + ArkUI_NumberValue listItme_value[] = { { .u32 = COLOR_PINK } }; + ArkUI_AttributeItem listItem_backgroundColor = { listItme_value, 1 }; + + ArkUI_NumberValue list_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem list_backgroundColor = { list_value, 1 }; + + for (int i = 0; i < 10; i++) { + auto listitem = nodeAPI->createNode(ARKUI_NODE_LIST_ITEM); + nodeAPI->setAttribute(listitem, NODE_WIDTH, &listitem_width_item); + nodeAPI->setAttribute(listitem, NODE_HEIGHT, &listitem_height_item); + nodeAPI->setAttribute(listitem, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(listitem, NODE_BACKGROUND_COLOR, &listItem_backgroundColor); + nodeAPI->addChild(list, listitem); + } + nodeAPI->setAttribute(list, NODE_BORDER_WIDTH, &border_item); + nodeAPI->setAttribute(list, NODE_MARGIN, &margin_item); +} +static void CreateRadio(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& radio) +{ + // 设置Radio组件宽度 + ArkUI_NumberValue default_width_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem default_width_item = { default_width_value, + sizeof(default_width_value) / sizeof(ArkUI_NumberValue) }; + + // 设置Radio组件高度 + ArkUI_NumberValue default_height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem default_height_item = { default_height_value, + sizeof(default_height_value) / sizeof(ArkUI_NumberValue) }; + // 设置Radio组件的Checked属性 + ArkUI_NumberValue true_checked_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem true_checked_item = { true_checked_value, + sizeof(true_checked_value) / sizeof(ArkUI_NumberValue) }; + + radio = nodeAPI->createNode(ARKUI_NODE_RADIO); + nodeAPI->setAttribute(radio, NODE_WIDTH, &default_width_item); + nodeAPI->setAttribute(radio, NODE_HEIGHT, &default_height_item); + nodeAPI->setAttribute(radio, NODE_RADIO_CHECKED, &true_checked_item); +} +static std::shared_ptr CreateWaterFlowByNestedScroll(int32_t forward, int32_t backward, bool up = true) +{ + auto scroll = std::make_shared(); + auto column = std::make_shared(); + auto waterFlow = std::make_shared(); + auto input = std::vector>(); + auto adapter = std::make_shared>(input); + auto reserveTop = std::make_shared(); + auto reserveDown = std::make_shared(); + // 设置上占位框 + reserveTop->SetWidth(410); + reserveTop->SetHeight(60); + reserveTop->SetBackgroundColor(COLOR_GREEN); + reserveTop->SetBorderRadius(10, 10, 10, 10); + // 设置下占位框 + reserveDown->SetWidth(410); + reserveDown->SetHeight(60); + reserveDown->SetBackgroundColor(COLOR_RED); + reserveDown->SetBorderRadius(10, 10, 10, 10); + + waterFlow->SetWidth(410); + waterFlow->SetHeight(500); + waterFlow->SetWaterFlowRowsGap(10); + waterFlow->SetBackgroundColor(COLOR_GRAY); + waterFlow->SetLazyAdapter(adapter); + waterFlow->SetBorderWidth(1, 1, 1, 1); + waterFlow->SetBorderColor(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); + waterFlow->SetColumnsTemplate("1fr 1fr 1fr"); + waterFlow->SetRowsTemplate("1fr 1fr 1fr"); + waterFlow->SetWaterFlowNestedScroll(forward, backward); + waterFlow->SetId("refreshNested"); + + auto item = waterFlow->getAttribute(NODE_SCROLL_NESTED_SCROLL); + if (item->value[0].i32 != forward || item->value[1].i32 != backward) { + waterFlow->SetBackgroundColor(COLOR_RED); + } + + for (int i = 0; i < FLOW_ITEM_COUNT; i++) { + auto col = std::make_shared(); + col->SetWidth(100); + col->SetHeight(100); + col->SetMargin(10); + if (i == 0) { + col->SetBackgroundColor(COLOR_PURPLE); + } else { + col->SetBackgroundColor(COLOR_WHITE); + } + adapter->InsertItem(i, col); + } + column->AddChild(reserveTop); + column->AddChild(waterFlow); + column->AddChild(reserveDown); + // 设置scroll选项 + scroll->SetHeight(600); + scroll->AddChild(column); + scroll->SetBorderWidth(1, 1, 1, 1); + scroll->SetBorderColor(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); + if (up) { + scroll->SetScrollTo(0, 200, {}); + waterFlow->SetWaterFlowScrollToIndex(FLOW_ITEM_COUNT - 1, 0, 0); + } + return scroll; +} +napi_value RefreshTest::CreateNativeNodeForRefreshContentAndRatio(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "refreshTest", "CreateNativeNodeForRefreshContent"); + // 获取id + size_t argc = 2; + napi_value args[2] = { 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, "refreshTest", "GetContext env or info is null"); + return nullptr; + } + + double ratio = 1; + napi_get_value_double(env, args[1], &ratio); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "refreshTest", "ratio=%{public}lf", ratio); + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "refreshTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置refresh pullToRefresh属性 + ArkUI_NumberValue pullToRefresh_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem pullToRefresh_item = { pullToRefresh_value, 1 }; + + // 创建refresh组件并添加到容器内 + auto refresh = nodeAPI->createNode(ARKUI_NODE_REFRESH); + nodeAPI->setAttribute(refresh, NODE_REFRESH_PULL_TO_REFRESH, &pullToRefresh_item); + ArkUI_NodeHandle refreshingComponent; + CreateRefreshingComponent(nodeAPI, refreshingComponent); + ArkUI_AttributeItem refreshingComponent_item { .object = refreshingComponent }; + nodeAPI->setAttribute(refresh, NODE_REFRESH_CONTENT, &refreshingComponent_item); + + // 设置refresh pullDownRatio属性正常值0~1:NODE_REFRESH_PULL_DOWN_RATIO + ArkUI_NumberValue pullDownRatio_value[] = { { .f32 = static_cast(ratio) } }; + ArkUI_AttributeItem pullDownRatio_item = { pullDownRatio_value, + sizeof(pullDownRatio_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(refresh, NODE_REFRESH_PULL_DOWN_RATIO, &pullDownRatio_item); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + nodeAPI->registerNodeEvent(refresh, NODE_REFRESH_ON_REFRESH, ON_REFRESH_EVENT_ID_SLEEP, nullptr); + + // 设置组件Id + ArkUI_AttributeItem idItem; + idItem.string = "refreshcontent"; + nodeAPI->setAttribute(refresh, NODE_ID, &idItem); + + ArkUI_NodeHandle list; + CreateList(nodeAPI, list); + + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(parentColumn, refresh); + nodeAPI->addChild(refresh, list); + // 挂载组件 + std::string id(xComponentID); + OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn); + + napi_value exports; + napi_create_object(env, &exports); + return exports; +} +napi_value RefreshTest::CreateNativeNodeForRefreshing(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "refreshTest", "CreateNativeNodeForRefreshing"); + // 获取id + 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, "refreshTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置refresh属性:NODE_REFRESH_REFRESHING + ArkUI_NumberValue refreshing_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem refreshing_item = { refreshing_value, sizeof(refreshing_value) / sizeof(ArkUI_NumberValue) }; + + // 创建refresh组件 + auto refresh = nodeAPI->createNode(ARKUI_NODE_REFRESH); + nodeAPI->setAttribute(refresh, NODE_REFRESH_REFRESHING, &refreshing_item); + // 设置refresh组件Id + ArkUI_AttributeItem idItem; + idItem.string = "refresh"; + nodeAPI->setAttribute(refresh, NODE_ID, &idItem); + // 创建list并放到refresh组件下 + ArkUI_NodeHandle list; + CreateList(nodeAPI, list); + nodeAPI->addChild(refresh, list); + // 创建list并放到radio组件下 + ArkUI_NodeHandle radio; + CreateRadio(nodeAPI, radio); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + nodeAPI->registerNodeEvent(refresh, NODE_REFRESH_ON_REFRESH, ON_REFRESH_EVENT_ID, radio); + nodeAPI->registerNodeEvent(refresh, NODE_REFRESH_ON_OFFSET_CHANGE, ON_REFRESH_EVENT_ID, nullptr); + + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(parentColumn, refresh); + nodeAPI->addChild(refresh, list); + nodeAPI->addChild(parentColumn, radio); + + // 挂载组件 + std::string id(xComponentID); + OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn); + + napi_value exports; + napi_create_object(env, &exports); + + return exports; +} +napi_value RefreshTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + // 获取id + size_t argc = 3; + napi_value args[3] = { 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, "refreshTest", "GetContext env or info is null"); + return nullptr; + } + if (args[1] == nullptr || args[2] == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "refreshTest", "args[1] == nullptr || args[2] == nullptr"); + } + double offset = 64; + napi_get_value_double(env, args[1], &offset); + + int32_t pullToRefresh = 1; + napi_get_value_int32(env, args[2], &pullToRefresh); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "refreshTest", "pullToRefresh = %{public}d,offset=%{public}lf", + pullToRefresh, offset); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 设置refreshOffset属性:NODE_REFRESH_OFFSET + ArkUI_NumberValue refreshOffset_value[] = { { .f32 = static_cast(offset) } }; + ArkUI_AttributeItem refreshOffset_item = { refreshOffset_value, + sizeof(refreshOffset_value) / sizeof(ArkUI_NumberValue) }; + + // 设置refresh pullToRefresh属性 + ArkUI_NumberValue pullToRefresh_value[] = { { .i32 = pullToRefresh } }; + ArkUI_AttributeItem pullToRefresh_item = { pullToRefresh_value, + sizeof(pullToRefresh_value) / sizeof(ArkUI_NumberValue) }; + + // 创建refresh组件并添加到容器内,设置NODE_REFRESH_OFFSET,NODE_REFRESH_PULL_TO_REFRESH + auto refresh = nodeAPI->createNode(ARKUI_NODE_REFRESH); + nodeAPI->setAttribute(refresh, NODE_REFRESH_OFFSET, &refreshOffset_item); + nodeAPI->setAttribute(refresh, NODE_REFRESH_PULL_TO_REFRESH, &pullToRefresh_item); + // 设置组件Id + ArkUI_AttributeItem idItem; + idItem.string = "refresh"; + nodeAPI->setAttribute(refresh, NODE_ID, &idItem); + + ArkUI_NodeHandle list; + CreateList(nodeAPI, list); + ArkUI_NodeHandle radio; + CreateRadio(nodeAPI, radio); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + nodeAPI->registerNodeEvent(refresh, NODE_REFRESH_ON_REFRESH, ON_REFRESH_EVENT_ID, radio); + + // parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + nodeAPI->addChild(parentColumn, refresh); + nodeAPI->addChild(refresh, list); + nodeAPI->addChild(parentColumn, radio); + + // 挂载组件 + std::string id(xComponentID); + OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn); + + napi_value exports; + napi_create_object(env, &exports); + + return exports; +} +napi_value RefreshTest::CreateNativeNodeNestedScroll(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "refreshTest", "CreateNativeNodeNestedScroll"); + // 获取id + 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, "refreshTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto parentColumn = new ColumnComponent(); + auto refresh = std::make_shared(ARKUI_NODE_REFRESH); + + ArkUI_NodeHandle refreshingComponent; + CreateRefreshingComponent(nodeAPI, refreshingComponent); + ArkUI_AttributeItem refreshingComponent_item { .object = refreshingComponent }; + nodeAPI->setAttribute(refresh->GetComponent(), NODE_REFRESH_CONTENT, &refreshingComponent_item); + + auto nestedScroll = CreateWaterFlowByNestedScroll(ArkUI_ScrollNestedMode::ARKUI_SCROLL_NESTED_MODE_PARENT_FIRST, + ArkUI_ScrollNestedMode::ARKUI_SCROLL_NESTED_MODE_PARENT_FIRST); + refresh->AddChild(nestedScroll); + parentColumn->AddChild(refresh); + + // 挂载组件 + std::string id(xComponentID); + OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn->GetComponent()); + + napi_value exports; + napi_create_object(env, &exports); + + return exports; +} + +napi_value RefreshTest::CreateNativeNodeForResetAttribute(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "refreshTest", "CreateNativeNodeForResetAttribute"); + // 获取id + 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, "refreshTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto parentColumn = new ColumnComponent(); + auto refresh = std::make_shared(); + refresh->SetPullToRefresh(0); // 默认值:1 + refresh->SetPullDownRatio(0.5); // 默认值:0.0f + refresh->SetRefreshOffset(20); // 默认值:0.0f + + ArkUI_NodeHandle list; + CreateList(nodeAPI, list); + + auto text = new TextComponent(); + text->SetWidth(300); + text->SetHeight(200); + text->SetBackgroundColor(COLOR_PINK); + + auto button = new ButtonComponent(); + button->SetWidth(200); + button->SetHeight(100); + button->SetId("ResetRefresh"); + button->SetLable("ResetRefresh"); + button->SetMargin(10); + button->RegisterOnClick([refresh, text]() { + refresh->resetAttribute(NODE_REFRESH_PULL_TO_REFRESH); + refresh->resetAttribute(NODE_REFRESH_PULL_DOWN_RATIO); + refresh->resetAttribute(NODE_REFRESH_OFFSET); + + auto pullToRefreshItem = refresh->getAttribute(NODE_REFRESH_PULL_TO_REFRESH); + auto pullDownRatio = refresh->getAttribute(NODE_REFRESH_PULL_TO_REFRESH); + auto refreshOffset = refresh->getAttribute(NODE_REFRESH_PULL_TO_REFRESH); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "refreshTest", + "pullToRefreshItem=%{public}d,pullDownRatio=%{public}f,refreshOffset=%{public}f", + pullToRefreshItem->value[0].i32, pullDownRatio->value[0].f32, refreshOffset->value[0].f32); + + std::string str = "pullToRefresh:" + std::to_string(pullToRefreshItem->value[0].i32) + "\n" + + "pullDownRatio:" + std::to_string(pullDownRatio->value[0].f32) + "\n" + + "refreshOffset:" + std::to_string(refreshOffset->value[0].f32) + "\n"; + + text->SetFontSize(20); + text->SetTextContent(str); + }); + + parentColumn->AddChild(std::shared_ptr(refresh)); + parentColumn->AddChild(std::shared_ptr(button)); + nodeAPI->addChild(refresh->GetComponent(), list); + parentColumn->AddChild(std::shared_ptr(text)); + // 挂载组件 + std::string id(xComponentID); + OH_NativeXComponent_AttachNativeRootNode( + PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn->GetComponent()); + + napi_value exports; + napi_create_object(env, &exports); + + return exports; +} +} // namespace ArkUICApiDemo diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/refresh/refresh_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/refresh/refresh_test.h new file mode 100644 index 0000000000000000000000000000000000000000..516167ce463a666c3b76aa79f701f5f01c23f8a4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/refresh/refresh_test.h @@ -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. + */ + +#ifndef ARKUI_CAPI_DEMO_REFRESH_TEST_H +#define ARKUI_CAPI_DEMO_REFRESH_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RefreshTest { +public: + ~RefreshTest(); + // RefreshTest:testRefresh001,testRefresh002,testRefresh003,testRefresh004 + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + // RefreshTest:testRefresh005,testRefresh006 + static napi_value CreateNativeNodeForRefreshContentAndRatio(napi_env env, napi_callback_info info); + // RefreshTest:testRefresh007 + static napi_value CreateNativeNodeForRefreshing(napi_env env, napi_callback_info info); + // RefreshTest:testRefresh008 + static napi_value CreateNativeNodeNestedScroll(napi_env env, napi_callback_info info); + // RefreshTest:testRefresh009 + static napi_value CreateNativeNodeForResetAttribute(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_REFRESH_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/row/row_align_items_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_align_items_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4026213cdc0c83e189733279ce43088ec5118f25 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_align_items_test.cpp @@ -0,0 +1,202 @@ +/* + * 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 "row_align_items_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t backgroundColor) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_BUTTON); + // set width + ArkUI_NumberValue button_width_value[] = { { .f32 = 30 } }; + ArkUI_AttributeItem button_width_item = { button_width_value, + sizeof(button_width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &button_width_item); + // set height + ArkUI_NumberValue button_height_value[] = { { .f32 = 30 } }; + ArkUI_AttributeItem button_height_item = { button_height_value, + sizeof(button_height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &button_height_item); + + // set background color + ArkUI_NumberValue button1_background_color_value[] = { { .u32 = backgroundColor } }; + ArkUI_AttributeItem button1_background_color_item = { button1_background_color_value, + sizeof(button1_background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &button1_background_color_item); + return nodeHandle; +} + +static auto createRowNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t verticalAlign) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_ROW); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 150 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 150 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + // set AlignItems + ArkUI_NumberValue alignItems_value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem alignItems_item = { alignItems_value, sizeof(alignItems_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ROW_ALIGN_ITEMS, &alignItems_item); + return nodeHandle; +} + +static auto createRowNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t verticalAlign, int32_t flexAlign) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_ROW); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 150 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 150 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + // set AlignItems + ArkUI_NumberValue alignItems_value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem alignItems_item = { alignItems_value, sizeof(alignItems_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ROW_ALIGN_ITEMS, &alignItems_item); + // set justifyContent + ArkUI_NumberValue justifyContent_value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem justifyContent_item = { justifyContent_value, + sizeof(justifyContent_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ROW_JUSTIFY_CONTENT, &justifyContent_item); + return nodeHandle; +} + +napi_value RowAlignItemsTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RowAlignItemsTest", "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, "RowAlignItemsTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto rowTop = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_TOP); + auto rowCenter = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_CENTER); + auto rowBottom = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_BOTTOM); + auto rowSpaceError = createRowNode(nodeAPI, -1); + nodeAPI->addChild(parentColumn, rowTop); + nodeAPI->addChild(parentColumn, rowCenter); + nodeAPI->addChild(parentColumn, rowBottom); + nodeAPI->addChild(parentColumn, rowSpaceError); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RowAlignItemsTest", + "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 RowAlignItemsTest::CreateMoreAttributeNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RowAlignItemsTest", "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, "RowAlignItemsTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_TOP, ARKUI_FLEX_ALIGNMENT_END); + auto row2 = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_CENTER, ARKUI_FLEX_ALIGNMENT_SPACE_BETWEEN); + auto row3 = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_BOTTOM, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY); + auto row4 = createRowNode(nodeAPI, ARKUI_VERTICAL_ALIGNMENT_CENTER, ARKUI_FLEX_ALIGNMENT_SPACE_AROUND); + nodeAPI->addChild(parentColumn, row1); + nodeAPI->addChild(parentColumn, row2); + nodeAPI->addChild(parentColumn, row3); + nodeAPI->addChild(parentColumn, row4); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RowAlignItemsTest", + "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/row/row_align_items_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_align_items_test.h new file mode 100644 index 0000000000000000000000000000000000000000..485023302c7d812cc40408c777e417c240b53c8b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_align_items_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_ROW_ALIGN_ITEMS_TEST_H +#define ARKUI_CAPI_DEMO_ROW_ALIGN_ITEMS_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RowAlignItemsTest { +public: + ~RowAlignItemsTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + static napi_value CreateMoreAttributeNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_ROW_ALIGN_ITEMS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/row/row_justify_content_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_justify_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b54039bf14b330f31d561eef7e1a4a36f55da4f8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_justify_content_test.cpp @@ -0,0 +1,128 @@ +/* + * 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 "row_justify_content_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t backgroundColor) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_BUTTON); + // set width + ArkUI_NumberValue button_width_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_width_item = { button_width_value, + sizeof(button_width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &button_width_item); + // set height + ArkUI_NumberValue button_height_value[] = { { .f32 = 20 } }; + ArkUI_AttributeItem button_height_item = { button_height_value, + sizeof(button_height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &button_height_item); + + // set background color + ArkUI_NumberValue button1_background_color_value[] = { { .u32 = backgroundColor } }; + ArkUI_AttributeItem button1_background_color_item = { button1_background_color_value, + sizeof(button1_background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &button1_background_color_item); + return nodeHandle; +} + +static auto createRowNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t flexAlign) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_ROW); + // set background color + 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(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 200 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + // set height + ArkUI_NumberValue height_value[] = { { .f32 = 80 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + // set margin + ArkUI_NumberValue margin_value[] = { { .f32 = 5 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + // set children + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_RED)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_GREEN)); + nodeAPI->addChild(nodeHandle, createChildNode(nodeAPI, COLOR_YELLOW)); + // set justifyContent + ArkUI_NumberValue justifyContent_value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem justifyContent_item = { justifyContent_value, + sizeof(justifyContent_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_ROW_JUSTIFY_CONTENT, &justifyContent_item); + return nodeHandle; +} + +napi_value RowJustifyContentTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RowJustifyContentTest", "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, "RowJustifyContentTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // set parent node + auto parentColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto rowStart = createRowNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_START); + auto rowCenter = createRowNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_CENTER); + auto rowEnd = createRowNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_END); + auto rowSpaceBetween = createRowNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_SPACE_BETWEEN); + auto rowSpaceAround = createRowNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_SPACE_AROUND); + auto rowSpaceEvenly = createRowNode(nodeAPI, ARKUI_FLEX_ALIGNMENT_SPACE_EVENLY); + auto rowSpaceError = createRowNode(nodeAPI, -1); + nodeAPI->addChild(parentColumn, rowStart); + nodeAPI->addChild(parentColumn, rowCenter); + nodeAPI->addChild(parentColumn, rowEnd); + nodeAPI->addChild(parentColumn, rowSpaceBetween); + nodeAPI->addChild(parentColumn, rowSpaceAround); + nodeAPI->addChild(parentColumn, rowSpaceEvenly); + nodeAPI->addChild(parentColumn, rowSpaceError); + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), parentColumn) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RowJustifyContentTest", + "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/row/row_justify_content_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_justify_content_test.h new file mode 100644 index 0000000000000000000000000000000000000000..5b270d4a6d664997aed1b279c5a7c8618437537e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/row/row_justify_content_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_ROW_JUSTIFY_CONTENT_TEST_H +#define ARKUI_CAPI_DEMO_ROW_JUSTIFY_CONTENT_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class RowJustifyContentTest { +public: + ~RowJustifyContentTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_ROW_JUSTIFY_CONTENT_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 100755 index 0000000000000000000000000000000000000000..c5fb16fbeb1cfa2f7d0fbee8a8eb69d447f6c723 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts @@ -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. + */ + +export const columnJustifyContentTest: (a: string) => void; + +export const columnAlignItemsTest: (a: string) => void; + +export const columnAlignItemsMoreAttributeTest: (a: string) => void; + +export const rowJustifyContentTest: (a: string) => void; + +export const rowAlignItemsTest: (a: string) => void; + +export const rowAlignItemsMoreAttributeTest: (a: string) => void; + +export const flexOptionsTest: (a: string) => void; + +export const radioCheckedTest: (a: string) => void; + +export const radioStyleTest: (a: string) => void; + +export const radioValueAndGroupTest: (a: string) => void; + +export const radioResetAttributeTest: (a: string) => void; + +export const gridTest: (a: string) => void; + +export const gridCachedCountTest: (a: string) => void; + +export const gridResetAttributeTest: (a: string) => void; + +export const refreshForContentAndRatioTest: (a: string, b: number) => void; + +export const refreshForRefreshingTest: (a: string) => void; + +export const refreshTest: (a: string, b: number, c: number) => void; + +export const refreshNestedScrollTest: (a: string) => void; + +export const refreshResetAttributeTest: (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 100755 index 0000000000000000000000000000000000000000..c696c592ecfee7f80e46f55e790cf8353ede0fb9 --- /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 100755 index 0000000000000000000000000000000000000000..1ee72503510a6c6a0d7a6c684c4d5bb9b6c1aad7 --- /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 100755 index 0000000000000000000000000000000000000000..831ac54dfe1ba983183a629f64819a0366d0c325 --- /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 100755 index 0000000000000000000000000000000000000000..c7f4ee43788d45f15e56fb439ccf4f4b9aee167e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,26 @@ +/* + * 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 100755 index 0000000000000000000000000000000000000000..4916aa2b5f51b09d6113574a586e25fe2ce8682c --- /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 100755 index 0000000000000000000000000000000000000000..8ac5e62f80c98914dd5680508a0177b99b91f913 --- /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 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /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 100755 index 0000000000000000000000000000000000000000..6b976fb6d0379b826204087d18a5f01872ce4d54 --- /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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 index 0000000000000000000000000000000000000000..16cf3219a2997a071cd6f0cd4816d3e173b18d15 --- /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 100755 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 100755 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 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /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 100755 index 0000000000000000000000000000000000000000..14bbd62cb9de385b1f5551945d749bb5e0e5fc2c --- /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 100755 index 0000000000000000000000000000000000000000..6b976fb6d0379b826204087d18a5f01872ce4d54 --- /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 100755 index 0000000000000000000000000000000000000000..cab069eb230dd1cc6d3c24cd0f1aa46d54af9cc9 --- /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 100755 index 0000000000000000000000000000000000000000..252a037b7bb5bb0fbeb7fc5fed3007a54b33392e --- /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 100755 index 0000000000000000000000000000000000000000..95e23de1a65c1baf1902e873a8252812cff9f025 --- /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 100755 index 0000000000000000000000000000000000000000..cd3064660aec25ff11ba1d30f4e9a335baad02b3 --- /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 100755 index 0000000000000000000000000000000000000000..a6b9102852b403ed32b49e742095547cfcc7a1cc --- /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/column/ColumnAlignItemsMoreAttributeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnAlignItemsMoreAttributeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..3bdb8844708b601d32e57269a44c97d92ed34677 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnAlignItemsMoreAttributeTest.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 ColumnAlignItemsMoreAttributeTest { + PAGE_TAG: string = 'ColumnAlignItemsMoreAttributeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.columnAlignItemsMoreAttributeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnAlignItemsTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnAlignItemsTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c56c6b6eb37c0301b6ae4591114460f77c924887 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnAlignItemsTest.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 ColumnAlignItemsTest { + PAGE_TAG: string = 'ColumnAlignItemsTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.columnAlignItemsTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnJustifyContentTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnJustifyContentTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..5316260d32c3d1dadee44aab2fb5a95f6092d564 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/column/ColumnJustifyContentTest.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 ColumnJustifyContentTest { + PAGE_TAG: string = 'ColumnJustifyContentTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.columnJustifyContentTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/flex/FlexOptionsTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/flex/FlexOptionsTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b24bcf7e3e27ef58fa20416d7b194aa1c2ae57d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/flex/FlexOptionsTest.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 FlexOptionsTest { + PAGE_TAG: string = 'FlexOptionsTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.flexOptionsTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridCachedCountTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridCachedCountTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..7267c855d19bc6e0107ba0ade7bf1e8ebafd3f86 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridCachedCountTest.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 GridCachedCountTest { + PAGE_TAG: string = 'GridCachedCountTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.gridCachedCountTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridResetAttributeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridResetAttributeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ccdfc8a63b2632b92e81420cd78902739a8c3c5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridResetAttributeTest.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 render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct GridResetAttributeTest { + PAGE_TAG: string = 'GridResetAttributeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.gridResetAttributeTest(this.PAGE_TAG); + }) + } + } +} + diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..92810e85f9b1070e3e6f55c8b9ac6955f23faee5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/grid/GridTest.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 GridTest { + PAGE_TAG: string = 'GridTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.gridTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioCheckedTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioCheckedTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..1942424dc1d2d844081d8babfef5d4419f2f6201 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioCheckedTest.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 RadioCheckedTest { + PAGE_TAG: string = 'RadioCheckedTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.radioCheckedTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioResetAttributeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioResetAttributeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..4753336ba23371561439a3b2788f257b52f5d8bb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioResetAttributeTest.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 RadioRestAttributeTest { + PAGE_TAG: string = 'RadioResetAttributeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.radioResetAttributeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioStyleTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioStyleTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..82ab817cee3bedc5b75891cb0bd6622a8ef2aa2e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioStyleTest.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 RadioStyleTest { + PAGE_TAG: string = 'RadioStyleTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.radioStyleTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioValueAndGroupTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioValueAndGroupTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..efc0f46fc917323af751f99f0e3f1e6d293fb7ea --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/radio/RadioValueAndGroupTest.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 RadioValueAndGroupTest { + PAGE_TAG: string = 'RadioValueAndGroupTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.radioValueAndGroupTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForContentAndRatioAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForContentAndRatioAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..f10cdb466dde97e4dd36f85afead3ce9e2586cd3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForContentAndRatioAbnormalTest.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 RefreshForContentAndRatioAbnormalTest { + PAGE_TAG: string = 'RefreshForContentAndRatioAbnormalTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshForContentAndRatioTest(this.PAGE_TAG,-1); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForContentAndRatioTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForContentAndRatioTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..e31c7842bf7844b702bad988b371397d11c30683 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForContentAndRatioTest.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 RefreshForContentAndRatioTest { + PAGE_TAG: string = 'RefreshForContentAndRatioTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshForContentAndRatioTest(this.PAGE_TAG,0.3); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForRefreshingTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForRefreshingTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b651fe5ea9dfe142ba49266b9601d0ff24f8084 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshForRefreshingTest.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 RefreshForRefreshingTest { + PAGE_TAG: string = 'RefreshForRefreshingTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshForRefreshingTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshNestedScrollTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshNestedScrollTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c10058886c02a4409d0b87230f539a506dafb60d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshNestedScrollTest.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 RefreshNestedScrollTest { + PAGE_TAG: string = 'RefreshNestedScrollTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshNestedScrollTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..882e2af89cf3ab41bae39e5531ee4db70d7d1e6f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshAbnormalTest.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 RefreshTest { + PAGE_TAG: string = 'RefreshTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshTest(this.PAGE_TAG,-100,-1); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshFalseTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshFalseTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4bdc0ad81c2629a10a334371e6712031cb56a39 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshFalseTest.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 RefreshTest { + PAGE_TAG: string = 'RefreshTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshTest(this.PAGE_TAG,20,0); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshTrueAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshTrueAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..89d2745d0034b9914a4591080ce02e2988c8ada2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshTrueAbnormalTest.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 RefreshTest { + PAGE_TAG: string = 'RefreshTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshTest(this.PAGE_TAG,800,1); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshTrueTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshTrueTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..793bedac9200298a0e72911275a969a2d35bb39d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshPullToRefreshTrueTest.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 RefreshTest { + PAGE_TAG: string = 'RefreshTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshTest(this.PAGE_TAG,20,1); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshResetAttributeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshResetAttributeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5d32ab49ee0457f37829baabde64afcc51af38b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/refresh/RefreshResetAttributeTest.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 RefreshResetAttributeTest { + PAGE_TAG: string = 'RefreshResetAttributeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.refreshResetAttributeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowAlignItemsMoreAttributeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowAlignItemsMoreAttributeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..42ff62488a3d21f8d0b486c4f3fdd9d34c948680 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowAlignItemsMoreAttributeTest.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 RowAlignItemsMoreAttributeTest { + PAGE_TAG: string = 'RowAlignItemsMoreAttributeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.rowAlignItemsMoreAttributeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowAlignItemsTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowAlignItemsTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..aff4b851f3cf49accff3a1742e1bc307dab2be6b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowAlignItemsTest.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 RowAlignItemsTest { + PAGE_TAG: string = 'RowAlignItemsTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.rowAlignItemsTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowJustifyContentTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowJustifyContentTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e68ae8e07a39d12f88380b4416033ef17f0b788 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/row/RowJustifyContentTest.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 RowJustifyContentTest { + PAGE_TAG: string = 'RowJustifyContentTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.rowJustifyContentTest(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 100755 index 0000000000000000000000000000000000000000..b0e43da86aef2238311c922f7e8de90fc7554468 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.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 columnJustifyContentTest from './column/ColumnJustifyContentTest.test' +import columnAlignItemsTest from './column/ColumnAlignItemsTest.test' +import rowJustifyContentTest from './row/RowJustifyContentTest.test' +import rowAlignItemsTest from './row/RowAlignItemsTest.test' +import flexOptionsTest from './flex/FlexOptinsTest.test' +import radioTest from './radio/RadioTest.test' +import gridTest from './grid/GridTest.test' +import refreshTest from './refresh/RefreshTest.test' + +export default function testsuite() { + columnJustifyContentTest() + columnAlignItemsTest() + rowJustifyContentTest() + rowAlignItemsTest() + flexOptionsTest() + radioTest() + gridTest() + refreshTest() +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/column/ColumnAlignItemsTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/column/ColumnAlignItemsTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1d5905597263121f49e828857fca9bda1ad8266 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/column/ColumnAlignItemsTest.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 columnAlignItemsTest() { + + describe('ColumnAlignItemsTest', () => { + + let PAGE_TAG = 'ColumnAlignItemsTest'; + let PAGE_TAG2 = 'ColumnAlignItemsMoreAttributeTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testColumnAlignItems001', 0, async (done: Function) => { + await Utils.pushPage(`column/${PAGE_TAG}`, done); + }); + + it('testColumnAlignItems002', 0, async (done: Function) => { + await Utils.pushPage(`column/${PAGE_TAG2}`, done); + }); + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/column/ColumnJustifyContentTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/column/ColumnJustifyContentTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f60119c15c27aa90081ec07a375d7365f8da525f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/column/ColumnJustifyContentTest.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 columnJustifyContentTest() { + + describe('ColumnJustifyContentTest', () => { + + let PAGE_TAG = 'ColumnJustifyContentTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testColumnJustifyContent001', 0, async (done: Function) => { + await Utils.pushPage(`column/${PAGE_TAG}`, done); + }); + }) +} 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 100755 index 0000000000000000000000000000000000000000..1ad4cf063e2f0a6fe3fa8fb292f1dcf4f11b1b0b --- /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 100755 index 0000000000000000000000000000000000000000..9e47b1a646656f114dc650c0bdee25ee5fdad04e --- /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 100755 index 0000000000000000000000000000000000000000..827a1cb472983758539d2c9e278713cd72578f0b --- /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 100755 index 0000000000000000000000000000000000000000..da612f94c43222f36aa6d8816f256d12701fb0fd --- /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/flex/FlexOptinsTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/flex/FlexOptinsTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ef9e992b019667db8044939d0f17aed1257466f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/flex/FlexOptinsTest.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 flexOptionsTest() { + + describe('FlexOptionsTest', () => { + + let PAGE_TAG = 'FlexOptionsTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testFlexOptions001', 0, async (done: Function) => { + await Utils.pushPage(`flex/${PAGE_TAG}`, done); + }); + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/grid/GridTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/grid/GridTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..73d946b982e3f4d2093217c34184f3f6f3a5e96a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/grid/GridTest.test.ets @@ -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. + */ + +import { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver, ON } from '@ohos.UiTest'; + +export default function gridTest() { + + describe('GridTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + //Grid组件测试 + // NODE_GRID_COLUMN_TEMPLATE + // NODE_GRID_ROW_TEMPLATE + // NODE_GRID_COLUMN_GAP + // NODE_GRID_ROW_GAP + // NODE_GRID_NODE_ADAPTER + it('testGrid001', 0, async (done: Function) => { + let PAGE_TAG = 'GridTest'; + await Utils.pushPage(`grid/${PAGE_TAG}`, () => setTimeout(() => { + }, 20000)); + let driver = Driver.create(); + await Utils.sleep(1000); + let component = await driver.findComponent(ON.id("grid1")); + let point = await component.getBounds(); + await driver.swipe(point.left + 20, point.bottom - 10, point.left + 20, point.top - 200, 4000); + + component = await driver.findComponent(ON.id("grid2")); + point = await component.getBounds(); + await driver.swipe(point.right - 20, point.bottom - 20, point.left + 100, point.bottom - 20, 40000); + await Utils.sleep(5000) + done(); + }); + + // NODE_GRID_CACHED_COUNT + it('testGrid002', 0, async (done: Function) => { + let PAGE_TAG = 'GridCachedCountTest'; + await Utils.pushPage(`grid/${PAGE_TAG}`, () => setTimeout(() => { + }, 20000)); + await Utils.clickComponent('gridClick'); + let driver = Driver.create(); + let component = await driver.findComponent(ON.id("gridCachedCount1")); + let point = await component.getBounds(); + await driver.drag(point.right - 20, point.bottom - 20, point.left + 100 , point.bottom - 20, 40000); + + component = await driver.findComponent(ON.id("gridCachedCount2")); + point = await component.getBounds(); + await driver.drag(point.left + 20, point.bottom - 10, point.left + 20 , point.bottom - 200, 4000); + + component = await driver.findComponent(ON.id("gridCachedCount3")); + point = await component.getBounds(); + await driver.drag(point.right, point.bottom - 20, point.left - 20 , point.bottom - 20, 40000); + await Utils.sleep(5000) + done(); + }); + + // Reset Grid的属性: NODE_GRID_COLUMN_TEMPLATE, NODE_GRID_ROW_TEMPLATE,NODE_GRID_COLUMN_GAP, NODE_GRID_ROW_GAP + it('testGrid003', 0, async (done: Function) => { + let PAGE_TAG = 'GridResetAttributeTest'; + await Utils.pushPage(`grid/${PAGE_TAG}`, done); + await Utils.clickComponent('GridReset'); + await Utils.sleep(3000) + done(); + }); + }) +} + diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/radio/RadioTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/radio/RadioTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..40ef2a871ce394eb8768ff74600c99a269c2ec8d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/radio/RadioTest.test.ets @@ -0,0 +1,60 @@ +/* + * 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 radioTest() { + + describe('RadioTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + //Radio组件Check属性分别设置为true、false时的显示效果测试。 默认值:false + it('testRadio001', 0, async (done: Function) => { + let PAGE_TAG = 'RadioCheckedTest'; + await Utils.pushPage(`radio/${PAGE_TAG}`, done); + }); + //Radio组件Style属性设置显示效果测试。 + it('testRadio002', 0, async (done: Function) => { + let PAGE_TAG = 'RadioStyleTest'; + await Utils.pushPage(`radio/${PAGE_TAG}`, done); + }); + //Radio组设置Value和Group + it('testRadio003', 0, async (done: Function) => { + let PAGE_TAG = 'RadioValueAndGroupTest'; + await Utils.pushPage(`radio/${PAGE_TAG}`, done); + }); + //Radio组件OnChange回调函数测试 + it('testRadio004', 0, async (done: Function) => { + let PAGE_TAG = 'RadioValueAndGroupTest'; + await Utils.pushPage(`radio/${PAGE_TAG}`); + await Utils.clickComponent('radioOnChange') + await Utils.sleep(2000); + done(); + }); + //Radio组件测试Reset以下属性:checked, radioStyle,value,group + it('testRadio005', 0, async (done: Function) => { + let PAGE_TAG = 'RadioResetAttributeTest'; + await Utils.pushPage(`radio/${PAGE_TAG}`); + await Utils.clickComponent('ResetRadio') + await Utils.sleep(3000); + done(); + }); + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/refresh/RefreshTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/refresh/RefreshTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2100a2e24633e49a171dade94a8bbe522b47f0d3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/refresh/RefreshTest.test.ets @@ -0,0 +1,148 @@ +/* + * 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 { describe, it, afterEach } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver, ON } from '@kit.TestKit'; + +async function doIt(id: string, done: Function, speed: number = 400, x = 100, y = 300) { + let driver = Driver.create(); + let refresh = await driver.findComponent(ON.id(id)); + let point = await refresh.getBounds(); + driver.swipe(point.left + x, point.bottom - x, point.left + x, point.bottom + y , speed); + WindowSnap.snapShot(globalThis.context, 'test',done); + await Utils.sleep(2000); +} +async function doItNext(id: string, done: Function, speed: number = 400, x = 100, y = 300) { + let driver = Driver.create(); + let refresh = await driver.findComponent(ON.id(id)); + let point = await refresh.getBounds(); + driver.swipe(point.left + x, point.bottom - x, point.left + x, point.bottom + y , speed); + WindowSnap.snapShotNext(globalThis.context, 'test',done); + await Utils.sleep(2000); +} + +export default function refreshTest() { + + describe('RefreshTest', () => { + afterEach(async (done: Function) => { + // WindowSnap.snapShot(globalThis.context, 'test', done) + await Utils.sleep(5000) + done() + }) + + // Refresh设置NODE_REFRESH_REFRESHING + // NODE_REFRESH_OFFSET:20 + // NODE_REFRESH_PULL_TO_REFRESH:1 + // 能够刷新,对应radio组件从选中状态变到非选中状态 + it('testRefresh001', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshPullToRefreshTrueTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await doIt('refresh', done, 10000); + done() + }) + // Refresh设置NODE_REFRESH_REFRESHING + // NODE_REFRESH_OFFSET:20 + // NODE_REFRESH_PULL_TO_REFRESH:0 + // 不能刷新,对应radio组件仍然是选中状态 + it('testRefresh002', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshPullToRefreshFalseTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + doIt('refresh', done, 40000); + done() + }) + // Refresh设置NODE_REFRESH_REFRESHING + // NODE_REFRESH_OFFSET:-100 + // NODE_REFRESH_PULL_TO_REFRESH:-1 + // 能够刷新,对应radio组件从选中状态变到非选中状态 + it('testRefresh003', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshPullToRefreshAbnormalTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await doIt('refresh', done, 40000); + done() + }) + + // Refresh设置NODE_REFRESH_REFRESHING + // NODE_REFRESH_OFFSET:800 + // NODE_REFRESH_PULL_TO_REFRESH:1 + // 不能刷新,对应radio组件仍然是选中状态 + it('testRefresh004', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshPullToRefreshTrueAbnormalTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await doIt('refresh', done, 10000); + await Utils.sleep(5000) + done() + }) + + // Refresh组件设置 NODE_REFRESH_CONTENT:自定义component + // NODE_REFRESH_PULL_DOWN_RATIO:0.3 + it('testRefresh005', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshForContentAndRatioTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + doItNext('refreshcontent', done, 3000); + await Utils.sleep(5000) + done() + }) + // Refresh组件设置 NODE_REFRESH_CONTENT:自定义component + // NODE_REFRESH_PULL_DOWN_RATIO:-1 + it('testRefresh006', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshForContentAndRatioAbnormalTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 12000)); + doItNext('refreshcontent', done, 2000); + await Utils.sleep(5000) + done() + }) + // Refresh测试refresing属性,在onRefresh回调中设置NODE_REFRESH_REFRESHING为0, 结束刷新状态 + // Refresh组件测试onOffsetChange回调函数,在回调中设置背景颜色变成黄色 + it('testRefresh007', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshForRefreshingTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await doIt('refresh', done, 40000); + await Utils.sleep(5000) + done() + }) + // Refresh组件中方式嵌套滚动组件,正常刷新 + it('testRefresh008', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshNestedScrollTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`, () => setTimeout(() => { + }, 12000)); + let driver = Driver.create(); + let refresh = await driver.findComponent(ON.id('refreshNested')); + let point = await refresh.getBounds(); + await driver.swipe(point.left + 20, point.bottom - 300, point.left + 20, point.bottom + 300, 10000); + WindowSnap.snapShot(globalThis.context, 'test', done); + await Utils.sleep(5000) + done() + }) + // Refresh组件中Reset属性:refreshOffset默认值为1,pullToRefresh默认值为0,pullDownRatio默认值为0 + it('testRefresh009', 0, async (done: Function) => { + let PAGE_TAG = 'RefreshResetAttributeTest'; + await Utils.pushPage(`refresh/${PAGE_TAG}`,() => setTimeout(() => { + }, 10000)); + await Utils.clickComponent("ResetRefresh"); + WindowSnap.snapShot(globalThis.context, 'test', done) + await Utils.sleep(5000) + done() + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/row/RowAlignItemsTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/row/RowAlignItemsTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a4bda8fe6dda3f4ccb154b816c6c080a414df7d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/row/RowAlignItemsTest.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 rowAlignItemsTest() { + + describe('RowAlignItemsTest', () => { + + let PAGE_TAG = 'RowAlignItemsTest'; + let PAGE_TAG2 = 'RowAlignItemsMoreAttributeTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testRowAlignItems001', 0, async (done: Function) => { + await Utils.pushPage(`row/${PAGE_TAG}`, done); + }); + + it('testRowAlignItems002', 0, async (done: Function) => { + await Utils.pushPage(`row/${PAGE_TAG2}`, done); + }); + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/row/RowJustifyContentTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/row/RowJustifyContentTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f18b66c6800323b8bc80d07ef80b6c7b2351e3d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/row/RowJustifyContentTest.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 rowJustifyContentTest() { + + describe('RowJustifyContentTest', () => { + + let PAGE_TAG = 'RowJustifyContentTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testRowJustifyContent001', 0, async (done: Function) => { + await Utils.pushPage(`row/${PAGE_TAG}`, 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 100755 index 0000000000000000000000000000000000000000..02823b530ec8c6074063266c903d39823509bacf --- /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 100755 index 0000000000000000000000000000000000000000..d5c61594f391ce3885ed9482b43d28a0f3257a58 --- /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 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /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 100755 index 0000000000000000000000000000000000000000..789ad804a9877b106f6c08be3ad7dc31d1812eab --- /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 100755 index 0000000000000000000000000000000000000000..6b976fb6d0379b826204087d18a5f01872ce4d54 --- /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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 index 0000000000000000000000000000000000000000..5f3052c1f000f6efafda3d57d771e3b477e34a6c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json @@ -0,0 +1,28 @@ +{ + "src": [ + "MainAbility/pages/DemoIndex", + "MainAbility/pages/column/ColumnJustifyContentTest", + "MainAbility/pages/column/ColumnAlignItemsTest", + "MainAbility/pages/column/ColumnAlignItemsMoreAttributeTest", + "MainAbility/pages/row/RowJustifyContentTest", + "MainAbility/pages/row/RowAlignItemsTest", + "MainAbility/pages/row/RowAlignItemsMoreAttributeTest", + "MainAbility/pages/flex/FlexOptionsTest", + "MainAbility/pages/radio/RadioCheckedTest", + "MainAbility/pages/radio/RadioStyleTest", + "MainAbility/pages/radio/RadioValueAndGroupTest", + "MainAbility/pages/radio/RadioResetAttributeTest", + "MainAbility/pages/grid/GridTest", + "MainAbility/pages/grid/GridCachedCountTest", + "MainAbility/pages/grid/GridResetAttributeTest", + "MainAbility/pages/refresh/RefreshForContentAndRatioTest", + "MainAbility/pages/refresh/RefreshForContentAndRatioAbnormalTest", + "MainAbility/pages/refresh/RefreshForRefreshingTest", + "MainAbility/pages/refresh/RefreshPullToRefreshTrueTest", + "MainAbility/pages/refresh/RefreshPullToRefreshFalseTest", + "MainAbility/pages/refresh/RefreshPullToRefreshAbnormalTest", + "MainAbility/pages/refresh/RefreshPullToRefreshTrueAbnormalTest", + "MainAbility/pages/refresh/RefreshResetAttributeTest" + ] +} + diff --git a/function/ui_compare/capidemo/hvigor/hvigor-config.json5 b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4886e292b5c51a798793e64804b56fd936d4f45 --- /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 100755 index 0000000000000000000000000000000000000000..159890e9ee8c4dc8cfff2a03e6207edb86abb0b5 --- /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/oh-package-lock.json5 b/function/ui_compare/capidemo/oh-package-lock.json5 new file mode 100755 index 0000000000000000000000000000000000000000..7881b4786a345baa51093806bef721c04732cfcc --- /dev/null +++ b/function/ui_compare/capidemo/oh-package-lock.json5 @@ -0,0 +1,27 @@ +{ + "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 100755 index 0000000000000000000000000000000000000000..43db2326cd8ae2711424045885d23a5c4c7bb394 --- /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