diff --git a/function/ui_compare/capidemo/.gitignore b/function/ui_compare/capidemo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0e158c3f26319059b259982c0f05f4537e86b13f --- /dev/null +++ b/function/ui_compare/capidemo/.gitignore @@ -0,0 +1,11 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test diff --git a/function/ui_compare/capidemo/AppScope/app.json5 b/function/ui_compare/capidemo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5ff6b7cabfbd38de7eb8e5bef44b341c6f1c979b --- /dev/null +++ b/function/ui_compare/capidemo/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.openharmony.arkui_capi_demo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/function/ui_compare/capidemo/AppScope/resources/base/element/string.json b/function/ui_compare/capidemo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0053930df2a5d99cd3bcd6bbd91defc4995799c4 --- /dev/null +++ b/function/ui_compare/capidemo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ArkUI_CAPI_Demo" + } + ] +} diff --git a/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png b/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/AppScope/resources/base/media/app_icon.png differ diff --git a/function/ui_compare/capidemo/README.md b/function/ui_compare/capidemo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8058e141d8a0ef2bd0f9fd4d99fea071078e3e6d --- /dev/null +++ b/function/ui_compare/capidemo/README.md @@ -0,0 +1,3 @@ +# capidemo + +c api demo project \ No newline at end of file diff --git a/function/ui_compare/capidemo/code-linter.json5 b/function/ui_compare/capidemo/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3311c9280cd317b17b4b2745922184ac805051d8 --- /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 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/build-profile.json5 b/function/ui_compare/capidemo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b4ebac31a62c3558f1b1e4558eea73ed0ad99cf --- /dev/null +++ b/function/ui_compare/capidemo/entry/build-profile.json5 @@ -0,0 +1,20 @@ +{ + "apiType": 'stageMode', + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "armeabi-v7a", "x86_64"], + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/hvigorfile.ts b/function/ui_compare/capidemo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/function/ui_compare/capidemo/entry/oh-package-lock.json5 b/function/ui_compare/capidemo/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bc742a8ec89ba83feb678d4a4c8c3eb97f4ebdbf --- /dev/null +++ b/function/ui_compare/capidemo/entry/oh-package-lock.json5 @@ -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. + */ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@types/libnativerender.so@src/main/cpp/types/libnativerender": "@types/libnativerender.so@src/main/cpp/types/libnativerender" + }, + "packages": { + "@types/libnativerender.so@src/main/cpp/types/libnativerender": { + "name": "libnativerender.so", + "version": "0.1.0", + "resolved": "src/main/cpp/types/libnativerender", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/oh-package.json5 b/function/ui_compare/capidemo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6f851a79ebe31f104ce352d7dd6f7b0ce313fd26 --- /dev/null +++ b/function/ui_compare/capidemo/entry/oh-package.json5 @@ -0,0 +1,12 @@ +{ + "license": "", + "devDependencies": { + "@types/libnativerender.so": "file:./src/main/cpp/types/libnativerender" + }, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt b/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f13e38b237bf042f043eec7d1b4a3db3233a1c8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,99 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(XComponent) + +# Automatically refresh source files +file(GLOB_RECURSE ALL_CPP_FILES ${PROJECT_SOURCE_DIR}/*.cpp) +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +add_definitions(-DOHOS_PLATFORM) + + +function(getAllCpp path parentDir exclude) + set(LOCAL_LIST) + file(GLOB ALL_DIR RELATIVE ${parentDir} ${parentDir}/*) + foreach(ITEM ${ALL_DIR}) + set(ITEM_DIR ${parentDir}/${ITEM}) + set(FIND_BOOL FALSE) + foreach(dir ${exclude}) + if("${dir}" STREQUAL "${ITEM}") + set(FIND_BOOL TRUE) + break() + endif() + endforeach() + if ("${FIND_BOOL}" STREQUAL "FALSE") + if(EXISTS ${ITEM_DIR}) + file(GLOB ALL_FILE ${ITEM_DIR}/*.cpp) + list(APPEND LOCAL_LIST ${ALL_FILE}) + endif() + endif () + endforeach() + set(path ${LOCAL_LIST} PARENT_SCOPE) +endfunction() + +set(path) +set(exclude "types") +set(CMAKE_CXX_STANDARD 17) +getAllCpp("${path}" ${PROJECT_SOURCE_DIR} "${exclude}") + +add_library(nativerender SHARED + napi_init.cpp + ${path} +) +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + +find_library( + # Sets the name of the path variable. + libace-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_ndk.z +) + +find_library( + # Sets the name of the path variable. + libnapi-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_napi.z +) + +find_library( + # Sets the name of the path variable. + libuv-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + uv +) + +find_library( + # Sets the name of the path variable. + EGL-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + EGL +) + +find_library( + # Sets the name of the path variable. + GLES-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + GLESv3 +) + +target_include_directories(nativerender PUBLIC + ${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include + PUBLIC component +) + +target_link_libraries(nativerender PUBLIC + libnative_drawing.so ${EGL-lib} ${GLES-lib} ${hilog-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib}) +target_link_libraries(nativerender PUBLIC libhilog_ndk.z.so libpixelmap.so libudmf.so) + diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h new file mode 100644 index 0000000000000000000000000000000000000000..b347ab879e54d4c471a2c45b9f0456b2ddcb6df1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/common/common.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_COMMON_TEST_H +#define ARKUI_CAPI_DEMO_COMMON_TEST_H + +#include +#include + +namespace ArkUICApiDemo { + +#define PARAM_0 0 +#define PARAM_1 1 +#define PARAM_2 2 +#define PARAM_3 3 +#define PARAM_4 4 +#define PARAM_5 5 +#define PARAM_6 6 +#define PARAM_7 7 +#define PARAM_8 8 +#define PARAM_9 9 +#define PARAM_10 10 +#define PARAM_11 11 +#define PARAM_12 12 +#define PARAM_64 64 +#define DEFAULT_MARGIN 10 +#define SIZE_5 5 +#define SIZE_10 10 +#define SIZE_30 30 +#define SIZE_50 50 +#define SIZE_100 100 +#define SIZE_150 150 +#define SIZE_180 180 +#define SIZE_200 200 +#define SIZE_230 230 +#define SIZE_250 250 +#define SIZE_300 300 +#define SIZE_350 350 +#define SIZE_400 400 +#define SIZE_450 450 +#define SIZE_500 500 +#define SIZE_600 600 +#define DEFAULT_VALUE_TAG 7000 +#define ENUM_ABNORMAL_VALUE 500 +#define INVALID_PARAM 401 +#define COLOR_RED 0xFFFF0000 +#define COLOR_GREEN 0xFF00FF00 +#define COLOR_BLUE 0xFF0000FF +#define COLOR_YELLOW 0xFFFFFF00 +#define COLOR_PURPLE 0xFFFF11FF +#define COLOR_PINK 0xFFFFC0CB +#define COLOR_GRAY 0xFFDDDDDD +#define COLOR_TRANSPARENT 0x00000000 +#define COLOR_BLACK 0xFF000000 +#define COLOR_WHITE 0xFFFFFFFF +#define COLOR_LIGHT_BLUE 0xFF00FFFF +#define ON_CLICK_EVENT_ID 6001 +#define ON_FOCUS_EVENT_ID 6002 +#define ON_TOUCH_EVENT_ID 6003 +#define ON_AREA_CHANGE_EVENT_ID 6004 +#define ON_APPEAR_EVENT_ID 6005 +#define ON_BLUR_EVENT_ID 6006 +#define ON_CHANGE_EVENT_ID 6007 +#define ON_SUBMIT_EVENT_ID 6008 +#define ON_CUT_EVENT_ID 6009 +#define ON_PASTE_EVENT_ID 6010 +#define ON_MEASURE_EVENT_ID 6011 +#define ON_LAYOUT_EVENT_ID 6012 +#define ON_DRAW_EVENT_ID 6013 +#define ON_CUSTOM_EVENT_1_ID 9001 +#define ON_CUSTOM_EVENT_2_ID 9002 +#define ON_CUSTOM_EVENT_3_ID 9003 +#define ON_CUSTOM_EVENT_4_ID 9004 +#define ON_CUSTOM_EVENT_5_ID 9005 +#define ON_CUSTOM_EVENT_6_ID 9006 +#define PARAM_NEGATIVE_1 (-1) +#define PARAM_NEGATIVE_100 (-100) + +/** + * Log print domain. + */ +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_COMMON_TEST_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1210d977110c439f92959be591b2d6278a698ec5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "button_component.h" + +namespace ArkUICApiDemo { + +void ButtonComponent::SetLable(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + _nodeAPI->setAttribute(_component, NODE_BUTTON_LABEL, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h new file mode 100644 index 0000000000000000000000000000000000000000..2873acfb4be6f6642f3e44532ae1e4d1e0366214 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/button_component.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H +#define ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ButtonComponent : public Component { +public: + ButtonComponent() : Component(ARKUI_NODE_BUTTON) {} + explicit ButtonComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetLable(const std::string& content); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_BUTTON_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h new file mode 100644 index 0000000000000000000000000000000000000000..b06726b2d300307e8277f258544672d7d49b84d5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/column_component.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H +#define ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ColumnComponent : public Component { +public: + ColumnComponent() : Component(ARKUI_NODE_COLUMN) {} + explicit ColumnComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetAlignItems(int32_t verticalAlign) + { + ArkUI_NumberValue value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_COLUMN_ALIGN_ITEMS, &item); + } + void SetJustifyContent(int32_t flexAlign) + { + ArkUI_NumberValue value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_COLUMN_JUSTIFY_CONTENT, &item); + } +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_COLUMN_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1363b989fa44240c3e6d8dd1ddcbd2fc2a80bce6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "component.h" + +#include +#include + +namespace ArkUICApiDemo { + +Component::Component(ArkUI_NodeType type) +{ + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + _component = _nodeAPI->createNode(type); + _nodeAPI->setUserData(_component, this); + _nodeAPI->addNodeEventReceiver(_component, Component::NodeEventReceiver); +} + +Component::Component(ArkUI_NodeHandle handle) +{ + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + _component = handle; + _nodeAPI->setUserData(_component, this); + _nodeAPI->addNodeEventReceiver(_component, Component::NodeEventReceiver); + + int32_t count = _nodeAPI->getTotalChildCount(_component); + for (int32_t i = 0; i < count; i++) { + auto temp = _nodeAPI->getChildAt(_component, i); + children_.emplace_back(std::make_shared(temp)); + } +} + +int32_t Component::setAttribute(ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* item) +{ + return _nodeAPI->setAttribute(_component, attribute, item); +} + +const ArkUI_AttributeItem* Component::getAttribute(ArkUI_NodeAttributeType attribute) +{ + return _nodeAPI->getAttribute(_component, attribute); +} + +int32_t Component::resetAttribute(ArkUI_NodeAttributeType attribute) +{ + return _nodeAPI->resetAttribute(_component, attribute); +} + +void Component::SetWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WIDTH, &item); +} +void Component::SetPercentWidth(float percent) +{ + ArkUI_NumberValue value[] = { { .f32 = percent } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WIDTH_PERCENT, &item); +} +void Component::SetHeight(float height) +{ + ArkUI_NumberValue value[] = { { .f32 = height } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_HEIGHT, &item); +} +void Component::SetPercentHeight(float percent) +{ + ArkUI_NumberValue value[] = { { .f32 = percent } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_HEIGHT_PERCENT, &item); +} +void Component::SetBackgroundColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_COLOR, &item); +} +void Component::SetBackgroundImage(const std::string& backgroundImage) +{ + ArkUI_AttributeItem item = { nullptr, 0, backgroundImage.c_str() }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_IMAGE, &item); +} +void Component::SetBackgroundImageSizeWithStyle(int32_t imageSize) +{ + ArkUI_NumberValue value[] = { { .i32 = imageSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_BACKGROUND_IMAGE_SIZE_WITH_STYLE, &item); +} +void Component::SetBorderRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) +{ + ArkUI_NumberValue value[] = { { .f32 = topLeft }, { .f32 = topRight }, { .f32 = bottomLeft }, + { .f32 = bottomRight } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_RADIUS, &item); +} + +void Component::SetPadding(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_PADDING, &item); +} + +void Component::SetPaddingPercent(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_PADDING_PERCENT, &item); +} + +void Component::SetMargin(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN, &item); +} +void Component::SetMargin(float margin) +{ + ArkUI_NumberValue value[] = { { .f32 = margin }, { .f32 = margin }, { .f32 = margin }, { .f32 = margin } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN, &item); +} + +void Component::SetMarginPercent(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_MARGIN_PERCENT, &item); +} + +void Component::SetEnabled(int32_t enable) +{ + ArkUI_NumberValue value[] = { { .i32 = enable } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ENABLED, &item); +} + +void Component::SetAlign(int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ALIGNMENT, &item); +} + +void Component::SetAlignRules(ArkUI_AlignmentRuleOption* option) +{ + ArkUI_AttributeItem item = { .object = option }; + _nodeAPI->setAttribute(_component, NODE_ALIGN_RULES, &item); +} + +void Component::SetAlignSelf(int32_t value) +{ + ArkUI_NumberValue val[] = { { .i32 = value } }; + ArkUI_AttributeItem item = { val, 1 }; + _nodeAPI->setAttribute(_component, NODE_ALIGN_SELF, &item); +} + +void Component::SetOpacity(float opacity) +{ + ArkUI_NumberValue value[] = { { .f32 = opacity } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_OPACITY, &item); +} + +void Component::SetBorderWidth(float top, float right, float bottom, float left) +{ + ArkUI_NumberValue value[] = { { .f32 = top }, { .f32 = right }, { .f32 = bottom }, { .f32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_WIDTH, &item); +} + +void Component::SetBorderWidth(float borderWidth) +{ + ArkUI_NumberValue value[] = { { .f32 = borderWidth }, { .f32 = borderWidth }, { .f32 = borderWidth }, + { .f32 = borderWidth } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_WIDTH, &item); +} + +void Component::SetBorderColor(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left) +{ + ArkUI_NumberValue value[] = { { .u32 = top }, { .u32 = right }, { .u32 = bottom }, { .u32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_COLOR, &item); +} + +void Component::SetBorderStyle(int32_t top, int32_t right, int32_t bottom, int32_t left) +{ + ArkUI_NumberValue value[] = { { .i32 = top }, { .i32 = right }, { .i32 = bottom }, { .i32 = left } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_BORDER_STYLE, &item); +} + +void Component::SetVisibility(int32_t visibility) +{ + ArkUI_NumberValue value[] = { { .i32 = visibility } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_VISIBILITY, &item); +} +void Component::SetId(const std::string& id) +{ + ArkUI_AttributeItem item = { nullptr, 0, id.c_str() }; + _nodeAPI->setAttribute(_component, NODE_ID, &item); +} +void Component::AddChild(const std::shared_ptr& child) +{ + children_.emplace_back(child); + OnAddChild(child); +} + +void Component::RemoveChild(const std::shared_ptr& child) +{ + children_.remove(child); + OnRemoveChild(child); +} + +void Component::RemoveAll() +{ + children_.clear(); + OnRemoveAll(); +} + +void Component::InsertChild(const std::shared_ptr& child, int32_t index) +{ + if (index >= children_.size()) { + AddChild(child); + } else { + auto iter = children_.begin(); + std::advance(iter, index); + children_.insert(iter, child); + OnInsertChild(child, index); + } +} + +std::shared_ptr Component::GetPreviousSibling() +{ + auto previousSibling = _nodeAPI->getPreviousSibling(_component); + return std::make_shared(previousSibling); +}; + +std::shared_ptr Component::GetNextSibling() +{ + auto nextSibling = _nodeAPI->getNextSibling(_component); + return std::make_shared(nextSibling); +}; + +void Component::NodeEventReceiver(ArkUI_NodeEvent* event) +{ + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + // 获取事件发生的UI组件对象。 + auto nodeHandle = OH_ArkUI_NodeEvent_GetNodeHandle(event); + // 获取保持在UI组件对象中的自定义数据,返回封装类指针。 + auto* node = reinterpret_cast(nodeAPI->getUserData(nodeHandle)); + // 基于封装类实例对象处理事件。 + if (node) { + node->ProcessNodeEvent(event); + } +} +void Component::SetFontSize(float fontSize) +{ + ArkUI_NumberValue value[] = { { .f32 = fontSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_SIZE, &item); +} +void Component::ProcessNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "ProcessNodeEvent eventType=%{public}d", eventType); + switch (eventType) { + case NODE_ON_CLICK: { + if (onClick_) { + onClick_(); + } + break; + } + case NODE_TOUCH_EVENT: { + if (onTouch_) { + onTouch_(event); + } + break; + } + case NODE_EVENT_ON_DISAPPEAR: { + if (onDisappear_) { + onDisappear_(); + } + break; + } + case NODE_EVENT_ON_APPEAR: { + if (onAppear_) { + onAppear_(); + } + break; + } + case NODE_ON_HOVER: { + if (onHover_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "NODE_ON_HOVER"); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + int32_t isHover = result->data[0].i32; + onHover_(static_cast(isHover)); + } + break; + } + case NODE_EVENT_ON_VISIBLE_AREA_CHANGE: { + if (onVisibleAreaChange_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "commonEvent", "NODE_EVENT_ON_VISIBLE_AREA_CHANGE"); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + bool visible = static_cast(result->data[0].i32); + float ratio = result->data[1].f32; + onVisibleAreaChange_(visible, ratio); + } + break; + } + case NODE_ON_MOUSE: { + if (onMouse_) { + onMouse_(event); + } + break; + } + case NODE_ON_TOUCH_INTERCEPT: { + if (onTouchIntercept_) { + onTouchIntercept_(event); + } + break; + } + case NODE_ON_FOCUS: { + if (onFocus_) { + onFocus_(); + } + break; + } + default: { + OnNodeEvent(event); + } + } +} + +void Component::RegisterOnVisibleAreaChange( + const std::function& onVisibleAreaChange, std::vector ratioArray) +{ + ArkUI_NumberValue value[ratioArray.size()]; + + for (size_t i = 0; i < ratioArray.size(); i++) { + value[i].f32 = { ratioArray[i] }; + } + ArkUI_AttributeItem item = { value, static_cast(ratioArray.size()) }; + + onVisibleAreaChange_ = onVisibleAreaChange; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_VISIBLE_AREA_CHANGE, 0, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h new file mode 100644 index 0000000000000000000000000000000000000000..890ed5f9caceadd21d64ed30de537c908886ba8b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/component.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_COMPONENT_H +#define ARKUI_CAPI_DEMO_COMPONENT_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class Component { +public: + explicit Component(ArkUI_NodeType type); + explicit Component(ArkUI_NodeHandle handle); + virtual ~Component() = default; + + int32_t setAttribute(ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* item); + const ArkUI_AttributeItem* getAttribute(ArkUI_NodeAttributeType attribute); + int32_t resetAttribute(ArkUI_NodeAttributeType attribute); + + void SetWidth(float width); + void SetPercentWidth(float percent); + void SetHeight(float height); + void SetPercentHeight(float percent); + void SetBackgroundColor(uint32_t color); + void SetBackgroundImage(const std::string& backgroundImage); + void SetBackgroundImageSizeWithStyle(int32_t imageSize); + void SetBorderRadius(float topLeft, float topRight, float bottomLeft, float bottomRight); + void SetPadding(float top, float right, float bottom, float left); + void SetPaddingPercent(float top, float right, float bottom, float left); + void SetMargin(float top, float right, float bottom, float left); + void SetMargin(float margin); + void SetMarginPercent(float top, float right, float bottom, float left); + void SetEnabled(int32_t enable); + void SetAlign(int32_t align); + void SetAlignRules(ArkUI_AlignmentRuleOption* option); + void SetAlignSelf(int32_t value); + void SetOpacity(float opacity); + void SetBorderWidth(float top, float right, float bottom, float left); + void SetBorderWidth(float borderWidth); + void SetBorderColor(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left); + void SetBorderStyle(int32_t top, int32_t right, int32_t bottom, int32_t left); + void SetVisibility(int32_t visibility); + virtual void SetFontSize(float fontSize); + void SetId(const std::string& id); + void AddChild(const std::shared_ptr& child); + void RemoveChild(const std::shared_ptr& child); + void RemoveAll(); + void InsertChild(const std::shared_ptr& child, int32_t index); + std::list> GetChildren() + { + return children_; + } + std::shared_ptr GetPreviousSibling(); + std::shared_ptr GetNextSibling(); + + ArkUI_NodeHandle GetComponent() + { + return _component; + } + // 处理通用事件。 + void RegisterOnClick(const std::function& onClick) + { + onClick_ = onClick; + _nodeAPI->registerNodeEvent(_component, NODE_ON_CLICK, 0, nullptr); + } + + void RegisterOnTouch(const std::function& onTouch) + { + onTouch_ = onTouch; + _nodeAPI->registerNodeEvent(_component, NODE_TOUCH_EVENT, 0, nullptr); + } + + void RegisterOnDisappear(const std::function& onDisappear) + { + onDisappear_ = onDisappear; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_DISAPPEAR, 0, nullptr); + } + + void RegisterOnAppear(const std::function& onAppear) + { + onAppear_ = onAppear; + _nodeAPI->registerNodeEvent(_component, NODE_EVENT_ON_APPEAR, 0, nullptr); + } + void RegisterOnHover(const std::function& onHover) + { + onHover_ = onHover; + _nodeAPI->registerNodeEvent(_component, NODE_ON_HOVER, 0, nullptr); + } + void RegisterOnMouse(const std::function& onMouse) + { + onMouse_ = onMouse; + _nodeAPI->registerNodeEvent(_component, NODE_ON_MOUSE, 0, nullptr); + } + void RegisterOnTouchIntercept(const std::function& onTouchIntercept) + { + onTouchIntercept_ = onTouchIntercept; + _nodeAPI->registerNodeEvent(_component, NODE_ON_TOUCH_INTERCEPT, 0, nullptr); + } + void RegisterOnFocus(const std::function& onFocus) + { + onFocus_ = onFocus; + _nodeAPI->registerNodeEvent(_component, NODE_ON_FOCUS, 0, nullptr); + } + void RegisterOnVisibleAreaChange( + const std::function& onVisibleAreaChange, std::vector ratioArray); + + static void NodeEventReceiver(ArkUI_NodeEvent* event); + void ProcessNodeEvent(ArkUI_NodeEvent* event); + virtual void OnNodeEvent(ArkUI_NodeEvent* event) {} + +protected: + // 组件树操作的实现类对接。 + void OnAddChild(const std::shared_ptr& child) + { + _nodeAPI->addChild(_component, child->GetComponent()); + } + void OnRemoveChild(const std::shared_ptr& child) + { + _nodeAPI->removeChild(_component, child->GetComponent()); + } + void OnRemoveAll() + { + _nodeAPI->removeAllChildren(_component); + } + void OnInsertChild(const std::shared_ptr& child, int32_t index) + { + _nodeAPI->insertChildAt(_component, child->GetComponent(), index); + } + +protected: + std::list> children_; + ArkUI_NodeHandle _component { nullptr }; + ArkUI_NativeNodeAPI_1* _nodeAPI { nullptr }; + +private: + std::function onClick_; + std::function onDisappear_; + std::function onAppear_; + std::function onTouch_; + std::function onHover_; + std::function onVisibleAreaChange_; + std::function onMouse_; + std::function onTouchIntercept_; + std::function onFocus_; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h new file mode 100644 index 0000000000000000000000000000000000000000..c08a3d861df679909e55245207697f00ea4c4165 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/flowitem_component.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H +#define ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { + +class FlowItemComponent : public Component { +public: + FlowItemComponent() : Component(ARKUI_NODE_FLOW_ITEM) {} + explicit FlowItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_FLOWITEM_COMPONENT_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd9d34569c930225f826b5f641a1c9a231439661 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "grid_component.h" + +namespace ArkUICApiDemo { +void GridComponent::SetGridColumnsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_GRID_COLUMN_TEMPLATE, &item); +} +void GridComponent::SetGridRowsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_GRID_ROW_TEMPLATE, &item); +} +void GridComponent::SetGridColumnsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_COLUMN_GAP, &item); +} +void GridComponent::SetGridRowsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_ROW_GAP, &item); +} +void GridComponent::SetGridCachedCount(int32_t cachedCount) +{ + ArkUI_NumberValue value[] = { { .i32 = cachedCount } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_GRID_CACHED_COUNT, &item); +} +void GridComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h new file mode 100644 index 0000000000000000000000000000000000000000..751041f87208c9b152c9b59f345ba5863effc216 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/grid_component.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_GRID_COMPONENT_H +#define ARKUI_CAPI_DEMO_GRID_COMPONENT_H + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { + +class GridItemComponent : public Component { +public: + GridItemComponent() : Component(ARKUI_NODE_GRID_ITEM) {} + explicit GridItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} +}; + +class GridComponent : public Component { +public: + GridComponent() : Component(ARKUI_NODE_GRID) {} + explicit GridComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_GRID_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetGridColumnsTemplate(const std::string& str); + void SetGridRowsTemplate(const std::string& str); + void SetGridColumnsGap(float val); + void SetGridRowsGap(float val); + void SetGridCachedCount(int32_t cachedCount); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + * [4] canOverScroll. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + void ReleaseAdapter() + { + return _adapter.reset(); + } + +private: + std::shared_ptr> _adapter; +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_GRID_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9349ba6b9ce8bb046f658a9f7deebb7607e463e8 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "image_component.h" + +#include + +namespace ArkUICApiDemo { + +int32_t ImageComponent::SetImageSrc(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SRC, &item); +} +int32_t ImageComponent::SetImageSrc(ArkUI_DrawableDescriptor* descriptors) +{ + ArkUI_AttributeItem item = { .object = descriptors }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SRC, &item); +} +int32_t ImageComponent::SetObjectFit(const int32_t objectFit) +{ + ArkUI_NumberValue value[] = { { .i32 = objectFit } }; + ArkUI_AttributeItem item = { value, 1 }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_OBJECT_FIT, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h new file mode 100644 index 0000000000000000000000000000000000000000..a3a30cc05fda6e773c23ed34d9c8694cfccb0935 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/image_component.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageComponent : public Component { +public: + ImageComponent() : Component(ARKUI_NODE_IMAGE) {} + explicit ImageComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + int32_t SetImageSrc(const std::string& content); + int32_t SetImageSrc(ArkUI_DrawableDescriptor* descriptors); + int32_t SetObjectFit(const int32_t objectFit); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGE_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45254af2c26bd9c9d1416b1af5a77bfc2297a4ce --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "imageanimator_component.h" + +namespace ArkUICApiDemo { +void ImageAnimatorComponent::SetState(int32_t state) +{ + ArkUI_NumberValue value[] = { { .i32 = state } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_STATE, &item); +} + +void ImageAnimatorComponent::SetIteration(int32_t iteration) +{ + ArkUI_NumberValue value[] = { { .i32 = iteration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_ITERATION, &item); +} + +void ImageAnimatorComponent::SetImage(ArkUI_AttributeItem& item) +{ + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_IMAGES, &item); +} + +void ImageAnimatorComponent::SetFixedSize(int32_t fixedSize) +{ + ArkUI_NumberValue value[] = { { .i32 = fixedSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_FIXED_SIZE, &item); +} + +void ImageAnimatorComponent::SetReverse(int32_t reverse) +{ + ArkUI_NumberValue value[] = { { .i32 = reverse } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_REVERSE, &item); +} +void ImageAnimatorComponent::SetFillMode(int32_t mode) +{ + ArkUI_NumberValue value[] = { { .i32 = mode } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_FILL_MODE, &item); +} + +void ImageAnimatorComponent::SetDuration(int32_t duration) +{ + ArkUI_NumberValue value[] = { { .i32 = duration } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_IMAGE_ANIMATOR_DURATION, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h new file mode 100644 index 0000000000000000000000000000000000000000..98a7d78b6cb85737aafcafe5240bf444a20f90be --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imageanimator_component.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageAnimatorComponent : public Component { +public: + ImageAnimatorComponent() : Component(ARKUI_NODE_IMAGE_ANIMATOR) {} + explicit ImageAnimatorComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetState(int32_t state); + void SetIteration(int32_t iteration); + void SetImage(ArkUI_AttributeItem& item); + void SetFixedSize(int32_t fixedSize); + void SetReverse(int32_t reverse); + void SetFillMode(int32_t mode); + void SetDuration(int32_t duration); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGEANIMATOR_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39141070a39e169185cfcc4a75bb3c6e5fcd0937 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "imagespan_component.h" + +namespace ArkUICApiDemo { + +int32_t ImageSpanComponent::SetImageSpanSrc(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SPAN_SRC, &item); +} +int32_t ImageSpanComponent::SetImageSpanSrc(ArkUI_DrawableDescriptor* descriptors) +{ + ArkUI_AttributeItem item = { .object = descriptors }; + return _nodeAPI->setAttribute(_component, NODE_IMAGE_SPAN_SRC, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h new file mode 100644 index 0000000000000000000000000000000000000000..c23ce64f8402c90d6296c1b00aa60718403a6632 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/imagespan_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H +#define ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class ImageSpanComponent : public Component { +public: + ImageSpanComponent() : Component(ARKUI_NODE_IMAGE_SPAN) {} + explicit ImageSpanComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + int32_t SetImageSpanSrc(const std::string& content); + int32_t SetImageSpanSrc(ArkUI_DrawableDescriptor* descriptors); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_IMAGESPAN_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27f6f903b2a7f5192a5fbf4523757f3c60d4cbf9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "list_component.h" + +namespace ArkUICApiDemo { + +void ListItemSwipeActionOption::SetStart(ArkUI_ListItemSwipeActionItem* item) +{ + OH_ArkUI_ListItemSwipeActionOption_SetStart(_option, item); +} + +void ListItemSwipeActionOption::SetEnd(ArkUI_ListItemSwipeActionItem* item) +{ + OH_ArkUI_ListItemSwipeActionOption_SetEnd(_option, item); +} + +void ListItemSwipeActionOption::SetEdgeEffect(ArkUI_ListItemSwipeEdgeEffect edgeEffect) +{ + OH_ArkUI_ListItemSwipeActionOption_SetEdgeEffect(_option, edgeEffect); +} + +int32_t ListItemSwipeActionOption::GetEdgeEffect() +{ + return OH_ArkUI_ListItemSwipeActionOption_GetEdgeEffect(_option); +} + +void ListItemSwipeActionOption::SetOnOffsetChange(OnOffsetChangeCallback callback) +{ + OH_ArkUI_ListItemSwipeActionOption_SetOnOffsetChange(_option, callback); +} + +void ListItemSwipeActionOption::SetOnOffsetChangWithUserData( + OnOffsetChangeWithUserDataCallback callback, void* userData) +{ + OH_ArkUI_ListItemSwipeActionOption_SetOnOffsetChangeWithUserData(_option, userData, callback); +} + +int32_t ListChildrenMainSizeOption::SetDefaultMainSize(float defaultMainSize) +{ + return OH_ArkUI_ListChildrenMainSizeOption_SetDefaultMainSize(_option, defaultMainSize); +} + +float ListChildrenMainSizeOption::GetDefaultMainSize() +{ + return OH_ArkUI_ListChildrenMainSizeOption_GetDefaultMainSize(_option); +} + +void ListChildrenMainSizeOption::Resize(int32_t totalSize) +{ + OH_ArkUI_ListChildrenMainSizeOption_Resize(_option, totalSize); +} + +int32_t ListChildrenMainSizeOption::Splice(int32_t index, int32_t deleteCount, int32_t addCount) +{ + return OH_ArkUI_ListChildrenMainSizeOption_Splice(_option, index, deleteCount, addCount); +} + +int32_t ListChildrenMainSizeOption::UpdateSize(int32_t index, float mainSize) +{ + return OH_ArkUI_ListChildrenMainSizeOption_UpdateSize(_option, index, mainSize); +} + +float ListChildrenMainSizeOption::GetMainSize(int32_t index) +{ + return OH_ArkUI_ListChildrenMainSizeOption_GetMainSize(_option, index); +} + +void ListItemComponent::SetListItemSwiperAction(ListItemSwipeActionOption* option) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, option->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_SWIPE_ACTION, &item); +} + +void ListComponent::SetListDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_DIRECTION, &item); +} + +void ListComponent::SetListSticky(int32_t stickyStyle) +{ + ArkUI_NumberValue value[] = { { .i32 = stickyStyle } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_STICKY, &item); +} + +void ListComponent::SetListSpace(float space) +{ + ArkUI_NumberValue value[] = { { .f32 = space } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_SPACE, &item); +} + +void ListComponent::SetListCachedCount(int32_t count) +{ + ArkUI_NumberValue value[] = { { .i32 = count } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_CACHED_COUNT, &item); +} + +void ListComponent::SetListScrollToIndex(const std::vector& data) +{ + ArkUI_AttributeItem item = { data.data(), static_cast(data.size()) }; + _nodeAPI->setAttribute(_component, NODE_LIST_SCROLL_TO_INDEX, &item); +} + +void ListComponent::SetListAlignListItem(int32_t align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_ALIGN_LIST_ITEM, &item); +} + +void ListComponent::SetListChildrenMainSize(ListChildrenMainSizeOption* mainSize) +{ + ArkUI_AttributeItem item = { .object = mainSize->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_CHILDREN_MAIN_SIZE, &item); + _childrenMainSize.reset(mainSize); +} + +void ListComponent::SetListInitialIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_LIST_INITIAL_INDEX, &item); +} + +void ListComponent::SetListDivider(uint32_t color, float width, float distanceStart, float distanceEnd) +{ + ArkUI_NumberValue value[] = { { .u32 = color }, { .f32 = width }, { .f32 = distanceStart }, + { .f32 = distanceEnd } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_LIST_DIVIDER, &item); +} + +void ListItemGroupComponent::SetListItemGroupHeader(Component* node) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, node->GetComponent() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_HEADER, &item); +} + +void ListItemGroupComponent::SetListItemGroupFooter(Component* node) +{ + ArkUI_AttributeItem item = { nullptr, 0, nullptr, node->GetComponent() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_FOOTER, &item); +} + +void ListItemGroupComponent::SetListItemGroupDivider( + uint32_t color, float width, float distanceStart, float distanceEnd) +{ + ArkUI_NumberValue value[] = { { .u32 = color }, { .f32 = width }, { .f32 = distanceStart }, + { .f32 = distanceEnd } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_SET_DIVIDER, &item); +} + +void ListItemGroupComponent::SetListItemGroupChildrenMainSize(ListChildrenMainSizeOption* mainSize) +{ + ArkUI_AttributeItem item = { .object = mainSize->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_LIST_ITEM_GROUP_CHILDREN_MAIN_SIZE, &item); + _childrenMainSize.reset(mainSize); +} + +void ListItemGroupAdapter::OnNewItemAttached(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + ArkUI_NodeHandle handle = nullptr; + int32_t start = index > 0 ? _groupList[index - 1] : 0, end = _groupList[index]; + if (end - start != 1) { + handle = UpdateNewItemByGroup(start, end); + } else { + handle = UpdateNewItem(start, end); + } + // 设置需要展示的元素。 + OH_ArkUI_NodeAdapterEvent_SetItem(event, handle); +} + +void ListItemGroupAdapter::OnItemDetached(ArkUI_NodeAdapterEvent* event) +{ + auto item = OH_ArkUI_NodeAdapterEvent_GetRemovedNode(event); + if (_removedNodeCallback) { + _removedNodeCallback(std::make_shared(item)); + } + // 放置到缓存池中进行回收复用。 + if (Component(item).GetChildren().size() == 1) { + _cachedListItems.emplace(_listItems[item]); + } else { + _cachedItems.emplace(_items[item]); + } +} + +ArkUI_NodeHandle ListItemGroupAdapter::UpdateNewItemByGroup(int32_t start, int32_t end) +{ + ArkUI_NodeHandle handle = nullptr; + if (!_cachedItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedItems.top(); + recycledItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + recycledItem->AddChild(_data[i]); + } + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedItems.pop(); + } else { + // 创建新的元素。 + auto groupItem = std::make_shared(); + groupItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + groupItem->AddChild(_data[i]); + } + groupItem->SetBorderWidth(1); + handle = groupItem->GetComponent(); + // 保持文本列表项的引用。 + _items.emplace(handle, groupItem); + } + return handle; +} + +ArkUI_NodeHandle ListItemGroupAdapter::UpdateNewItem(int32_t start, int32_t end) +{ + ArkUI_NodeHandle handle = nullptr; + if (!_cachedListItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedListItems.top(); + recycledItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + recycledItem->AddChild(_data[i]); + } + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedListItems.pop(); + } else { + // 创建新的元素。 + auto listItem = std::make_shared(); + listItem->RemoveAll(); + for (int32_t i = start; i < end; i++) { + listItem->AddChild(_data[i]); + } + handle = listItem->GetComponent(); + // 保持文本列表项的引用。 + _listItems.emplace(handle, listItem); + } + return handle; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h new file mode 100644 index 0000000000000000000000000000000000000000..d372f10ed44a87d6e71176769bef3a23324ca72b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/list_component.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CAPIDEMO_LIST_COMPONENT_H +#define CAPIDEMO_LIST_COMPONENT_H +#include + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { + +typedef void (*OnOffsetChangeCallback)(float offset); +typedef void (*OnOffsetChangeWithUserDataCallback)(float offset, void* userData); +typedef void (*OnFinish)(void* userData); + +class ListItemSwipeActionOption { +public: + ListItemSwipeActionOption() : _option(OH_ArkUI_ListItemSwipeActionOption_Create()) {} + ~ListItemSwipeActionOption() + { + OH_ArkUI_ListItemSwipeActionOption_Dispose(_option); + } + + void SetStart(ArkUI_ListItemSwipeActionItem* item); + void SetEnd(ArkUI_ListItemSwipeActionItem* item); + void SetEdgeEffect(ArkUI_ListItemSwipeEdgeEffect edgeEffect); + int32_t GetEdgeEffect(); + void SetOnOffsetChange(OnOffsetChangeCallback callback); + void SetOnOffsetChangWithUserData(OnOffsetChangeWithUserDataCallback callback, void* userData); + + ArkUI_ListItemSwipeActionOption* GetOption() + { + return _option; + } + +private: + ArkUI_ListItemSwipeActionOption* _option; +}; + +class ListItemComponent : public Component { +public: + ListItemComponent() : Component(ARKUI_NODE_LIST_ITEM) {} + explicit ListItemComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetListItemSwiperAction(ListItemSwipeActionOption* option); + std::shared_ptr GetSwipeActionOption() const + { + return _swipeActionOption; + } + void ReleaseSwipeActionOption() + { + _swipeActionOption.reset(); + } + +private: + std::shared_ptr _swipeActionOption; +}; + +class ListChildrenMainSizeOption { +public: + ListChildrenMainSizeOption() : _option(OH_ArkUI_ListChildrenMainSizeOption_Create()) {} + ~ListChildrenMainSizeOption() + { + OH_ArkUI_ListChildrenMainSizeOption_Dispose(_option); + } + int32_t SetDefaultMainSize(float defaultMainSize); + float GetDefaultMainSize(); + void Resize(int32_t totalSize); + int32_t Splice(int32_t index, int32_t deleteCount, int32_t addCount); + int32_t UpdateSize(int32_t index, float mainSize); + float GetMainSize(int32_t index); + + ArkUI_ListChildrenMainSize* GetOption() + { + return _option; + } + +private: + ArkUI_ListChildrenMainSize* _option; +}; + +class ListItemGroupComponent : public Component { +public: + ListItemGroupComponent() : Component(ARKUI_NODE_LIST_ITEM_GROUP) {} + explicit ListItemGroupComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetListItemGroupHeader(Component* node); + void SetListItemGroupFooter(Component* node); + void SetListItemGroupDivider(uint32_t color, float width, float distanceStart, float distanceEnd); + void SetListItemGroupChildrenMainSize(ListChildrenMainSizeOption* mainSize); + + std::shared_ptr GetSizeOption() const + { + return _childrenMainSize; + } + void ReleaseSizeOption() + { + _childrenMainSize.reset(); + } + +private: + std::shared_ptr _childrenMainSize; +}; + +class ListItemGroupAdapter : public ItemAdapter { +public: + explicit ListItemGroupAdapter(std::vector>& dataSource, + const std::vector& groupList) + : ItemAdapter(dataSource) + { + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, groupList.size()); + int32_t sum = 0; + for (auto& item : groupList) { + sum += item; + _groupList.push_back(sum); + } + } + virtual ~ListItemGroupAdapter() {} + +protected: + void OnNewItemAttached(ArkUI_NodeAdapterEvent* event) override; + void OnItemDetached(ArkUI_NodeAdapterEvent* event) override; + ArkUI_NodeHandle UpdateNewItemByGroup(int32_t start, int32_t end); + ArkUI_NodeHandle UpdateNewItem(int32_t start, int32_t end); + +private: + std::vector _groupList; + // 缓存listItemComponent + std::stack> _cachedListItems; + // 存储list嵌套的单个listItem + std::unordered_map> _listItems; +}; + +class ListComponent : public Component { +public: + ListComponent() : Component(ARKUI_NODE_LIST) {} + explicit ListComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + // 引入懒加载模块。 + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_LIST_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetLazyAdapterByGroup(const std::shared_ptr& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_LIST_NODE_ADAPTER, &item); + _groupAdapter = adapter; + } + /** + * @param direction ArkUI_Axis + */ + void SetListDirection(int32_t direction); + /** + * @param stickyStyle ArkUI_StickyStyle + */ + void SetListSticky(int32_t stickyStyle); + void SetListSpace(float space); + void SetListCachedCount(int32_t count); + /** + * data[0].i32:The index value of the target element to be slid to in the current container.\n + * data[1]?.i32:Set whether there is an action when sliding to the index value of a list item in the list, where + * 1 indicates an action and 0 indicates no action. Default value: 0。\n + * data[2]?.i32:ArkUI_ScrollAlignment + */ + void SetListScrollToIndex(const std::vector& data); + /** + * @param align ArkUI_ListItemAlignment + */ + void SetListAlignListItem(int32_t align); + void SetListChildrenMainSize(ListChildrenMainSizeOption* mainSize); + void SetListInitialIndex(int32_t index); + void SetListDivider(uint32_t color, float width, float distanceStart, float distanceEnd); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + std::shared_ptr GetGroupAdapter() const + { + return _groupAdapter; + } + std::shared_ptr GetSizeOption() const + { + return _childrenMainSize; + } + void ReleaseSizeOption() + { + _childrenMainSize.reset(); + } + +private: + std::shared_ptr> _adapter; + std::shared_ptr _groupAdapter; + std::shared_ptr _childrenMainSize; +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_LIST_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/node_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..921e68957f6d96105977a7e7fed0e5cd08e47c5e --- /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: + explicit ItemAdapter(std::vector>& dataSource); + virtual ~ItemAdapter(); + ArkUI_NodeAdapterHandle GetAdapter() const + { + return _adapter; + } + void RemoveItem(int32_t index); + void RemoveItems(int32_t startPosition, int32_t itemCount); + void InsertItem(int32_t index, const std::shared_ptr& value); + void InsertItems(int32_t index, std::vector>& dataSource); + void MoveItem(int32_t oldIndex, int32_t newIndex); + void ReloadItem(int32_t index, const std::shared_ptr& value); + void ReloadItems(int32_t startPosition, std::vector>& dataSource); + void ReloadAllItem(); + void SetAllItem(AllItemCallBack callback); + void UnregisterEventReceiver(); + void SetNodeAdapterEvent(const std::function& callback); + void RegisterRemovedNodeCallback(std::function)> callback) + { + _removedNodeCallback = callback; + } + void SetTotalNodeCount(uint32_t count) + { + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, count); + } + uint32_t GetTotalNodeCount() + { + return OH_ArkUI_NodeAdapter_GetTotalNodeCount(_adapter); + } + +protected: + static void OnStaticAdapterEvent(ArkUI_NodeAdapterEvent* event); + virtual void OnAdapterEvent(ArkUI_NodeAdapterEvent* event); + // 分配ID给需要显示的Item,用于ReloadAllItems场景的元素diff。 + virtual void OnNewItemIdCreated(ArkUI_NodeAdapterEvent* event); + // 需要新的Item显示在可见区域。 + virtual void OnNewItemAttached(ArkUI_NodeAdapterEvent* event); + // Item从可见区域移除。 + virtual void OnItemDetached(ArkUI_NodeAdapterEvent* event); + + std::vector> _data; + ArkUI_NativeNodeAPI_1* _nodeAPI = nullptr; + ArkUI_NodeAdapterHandle _adapter = nullptr; + // 管理NodeAdapter生成的元素。 + std::unordered_map> _items; + // 管理回收复用组件池。 + std::stack> _cachedItems; + std::function _eventCallBack; + std::function)> _removedNodeCallback; +}; + +template +ItemAdapter::ItemAdapter(std::vector>& dataSource) + : _adapter(OH_ArkUI_NodeAdapter_Create()) +{ + // 使用NodeAdapter创建函数。 + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, _nodeAPI); + std::swap(_data, dataSource); + // 设置懒加载数据。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); + // 设置懒加载回调事件。 + OH_ArkUI_NodeAdapter_RegisterEventReceiver(_adapter, this, OnStaticAdapterEvent); +} + +template +ItemAdapter::~ItemAdapter() +{ + // 释放创建的组件。 + while (!_cachedItems.empty()) { + _cachedItems.pop(); + } + _items.clear(); + // 释放Adapter相关资源。 + OH_ArkUI_NodeAdapter_UnregisterEventReceiver(_adapter); + OH_ArkUI_NodeAdapter_Dispose(_adapter); +} + +template +void ItemAdapter::RemoveItem(int32_t index) +{ + // 删除第index个数据。 + _data.erase(_data.begin() + index); + // 如果index会导致可视区域元素发生可见性变化,则会回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER事件删除元素, + // 根据是否有新增元素回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_RemoveItem(_adapter, index, 1); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::RemoveItems(int32_t startPosition, int32_t itemCount) +{ + auto end = _data.begin() + startPosition + itemCount; + if (startPosition + itemCount > _data.size()) { + end = _data.end(); + } + _data.erase(_data.begin() + startPosition, end); + OH_ArkUI_NodeAdapter_RemoveItem(_adapter, startPosition, itemCount); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::InsertItem(int32_t index, const std::shared_ptr& value) +{ + _data.insert(_data.begin() + index, value); + // 如果index会导致可视区域元素发生可见性变化,则会回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件, + // 根据是否有删除元素回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER事件。 + OH_ArkUI_NodeAdapter_InsertItem(_adapter, index, 1); + // 更新新的数量。 + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::InsertItems(int32_t index, std::vector>& dataSource) +{ + _data.insert(_data.begin() + index, dataSource.begin(), dataSource.end()); + OH_ArkUI_NodeAdapter_InsertItem(_adapter, index, dataSource.size()); + OH_ArkUI_NodeAdapter_SetTotalNodeCount(_adapter, _data.size()); +} + +template +void ItemAdapter::MoveItem(int32_t oldIndex, int32_t newIndex) +{ + auto temp = _data[oldIndex]; + _data.insert(_data.begin() + newIndex, temp); + _data.erase(_data.begin() + oldIndex); + // 移到位置如果未发生可视区域内元素的可见性变化,则不回调事件,反之根据新增和删除场景回调对应的事件。 + OH_ArkUI_NodeAdapter_MoveItem(_adapter, oldIndex, newIndex); +} + +template +void ItemAdapter::ReloadItem(int32_t index, const std::shared_ptr& value) +{ + _data[index] = value; + // 如果index位于可视区域内,先回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素, + // 再回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_ReloadItem(_adapter, index, 1); +} + +template +void ItemAdapter::ReloadItems(int32_t startPosition, std::vector>& dataSource) +{ + if (startPosition + dataSource.size() > _data.size()) { + // 防止nodeAdapter崩溃 + return; + } + for (int32_t i = 0; i < dataSource.size(); i++) { + _data[startPosition + i] = dataSource[i]; + } + // 如果index位于可视区域内,先回调NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素, + // 再回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID和NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件。 + OH_ArkUI_NodeAdapter_ReloadItem(_adapter, startPosition, dataSource.size()); +} + +template +void ItemAdapter::SetAllItem(AllItemCallBack callback) +{ + ArkUI_NodeHandle* items = nullptr; + uint32_t size = 0; + OH_ArkUI_NodeAdapter_GetAllItems(_adapter, &items, &size); + for (uint32_t i = 0; i < size; i++) { + if (!items[i]) + continue; + auto temp = std::make_shared(items[i]); + if (callback) { + callback(temp, i); + } + } +} + +template +void ItemAdapter::UnregisterEventReceiver() +{ + OH_ArkUI_NodeAdapter_UnregisterEventReceiver(_adapter); +} + +template +void ItemAdapter::SetNodeAdapterEvent(const std::function& callback) +{ + _eventCallBack = callback; +} + +template +void ItemAdapter::ReloadAllItem() +{ + std::reverse(_data.begin(), _data.end()); + // 全部重新加载场景下,会回调NODE_ADAPTER_EVENT_ON_GET_NODE_ID接口获取新的组件ID, + // 根据新的组件ID进行对比,ID不发生变化的进行复用, + // 针对新增ID的元素,调用NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER事件创建新的组件, + // 然后判断老数据中遗留的未使用ID,调用NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER删除老元素。 + OH_ArkUI_NodeAdapter_ReloadAllItems(_adapter); +} + +template +void ItemAdapter::OnStaticAdapterEvent(ArkUI_NodeAdapterEvent* event) +{ + // 获取实例对象,回调实例事件。 + auto itemAdapter = reinterpret_cast(OH_ArkUI_NodeAdapterEvent_GetUserData(event)); + itemAdapter->OnAdapterEvent(event); +} + +template +void ItemAdapter::OnAdapterEvent(ArkUI_NodeAdapterEvent* event) +{ + auto type = OH_ArkUI_NodeAdapterEvent_GetType(event); + switch (type) { + case NODE_ADAPTER_EVENT_WILL_ATTACH_TO_NODE: + break; + case NODE_ADAPTER_EVENT_WILL_DETACH_FROM_NODE: + break; + case NODE_ADAPTER_EVENT_ON_GET_NODE_ID: + OnNewItemIdCreated(event); + break; + case NODE_ADAPTER_EVENT_ON_ADD_NODE_TO_ADAPTER: + OnNewItemAttached(event); + break; + case NODE_ADAPTER_EVENT_ON_REMOVE_NODE_FROM_ADAPTER: + OnItemDetached(event); + break; + default: + break; + } + if (_eventCallBack) + _eventCallBack(event); +} +template +void ItemAdapter::OnNewItemIdCreated(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + static std::hash hashId = std::hash(); + auto id = hashId(std::to_string(index)); + OH_ArkUI_NodeAdapterEvent_SetNodeId(event, id); +} + +// 需要新的Item显示在可见区域。 +template +void ItemAdapter::OnNewItemAttached(ArkUI_NodeAdapterEvent* event) +{ + auto index = OH_ArkUI_NodeAdapterEvent_GetItemIndex(event); + ArkUI_NodeHandle handle = nullptr; + auto showNode = _data[index]; + if (!_cachedItems.empty()) { + // 使用并更新回收复用的缓存。 + auto recycledItem = _cachedItems.top(); + recycledItem->RemoveAll(); + recycledItem->AddChild(showNode); + handle = recycledItem->GetComponent(); + // 释放缓存池的引用。 + _cachedItems.pop(); + } else { + // 创建新的元素。 + auto flowItem = std::make_shared(); + flowItem->RemoveAll(); + flowItem->AddChild(showNode); + handle = flowItem->GetComponent(); + // 保持文本列表项的引用。 + _items.emplace(handle, flowItem); + } + // 设置需要展示的元素。 + OH_ArkUI_NodeAdapterEvent_SetItem(event, handle); +} + +// Item从可见区域移除。 +template +void ItemAdapter::OnItemDetached(ArkUI_NodeAdapterEvent* event) +{ + auto item = OH_ArkUI_NodeAdapterEvent_GetRemovedNode(event); + if (_removedNodeCallback) { + _removedNodeCallback(std::make_shared(item)); + } + // 放置到缓存池中进行回收复用。 + _cachedItems.emplace(_items[item]); +} +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_NODE_ADAPTER_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..975473d6357a9dc1910a500a172877e4b04ddba5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "radio_component.h" + +#include + +namespace ArkUICApiDemo { +constexpr size_t ALLOW_SIZE_3 = 3; +void RadioComponent::SetChecked(const bool& isChecked) +{ + ArkUI_NumberValue value[] = { { .i32 = static_cast(isChecked) } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_RADIO_CHECKED, &item); +} +void RadioComponent::SetGroup(const std::string& group) +{ + ArkUI_AttributeItem item = { .string = group.c_str() }; + _nodeAPI->setAttribute(_component, NODE_RADIO_GROUP, &item); +} +void RadioComponent::SetStyled(const uint32_t* colorArray, size_t size) +{ + if (size == ALLOW_SIZE_3) { + ArkUI_NumberValue radioStyle_value[] = { { .u32 = colorArray[0] }, { .u32 = colorArray[1] }, + { .u32 = colorArray[2] } }; + ArkUI_AttributeItem radioStyle_value_item = { radioStyle_value, ALLOW_SIZE_3 }; + _nodeAPI->setAttribute(_component, NODE_RADIO_STYLE, &radioStyle_value_item); + } +} +void RadioComponent::SetValue(const std::string& value) +{ + ArkUI_AttributeItem item = { .string = value.c_str() }; + _nodeAPI->setAttribute(_component, NODE_RADIO_VALUE, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h new file mode 100644 index 0000000000000000000000000000000000000000..b40239197998d9b4f9a52c3cd1803b03d68ce060 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/radio_component.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_RADIO_COMPONENT_H +#define ARKUI_CAPI_DEMO_RADIO_COMPONENT_H + +#include +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class RadioComponent : public Component { +public: + RadioComponent() : Component(ARKUI_NODE_RADIO) {} + explicit RadioComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetChecked(const bool& isChecked); + void SetGroup(const std::string& group); + void SetStyled(const uint32_t* colorArray, size_t size); + void SetValue(const std::string& value); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RADIO_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06f55393c9345a0249f924305ddf8be34fe047c6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "refresh_component.h" + +#include + +namespace ArkUICApiDemo { + +void RefreshComponent::SetPullToRefresh(int32_t pullToRefresh) +{ + ArkUI_NumberValue value[] = { { .i32 = pullToRefresh } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_PULL_TO_REFRESH, &item); +} +void RefreshComponent::SetPullDownRatio(float pullDownRatio) +{ + ArkUI_NumberValue value[] = { { .f32 = pullDownRatio } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_PULL_DOWN_RATIO, &item); +} +void RefreshComponent::SetRefreshOffset(float refreshOffset) +{ + ArkUI_NumberValue value[] = { { .f32 = refreshOffset } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_OFFSET, &item); +} +void RefreshComponent::SetRefreshing(bool refreshing) +{ + ArkUI_NumberValue value[] = { { .i32 = refreshing } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_REFRESH_REFRESHING, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h new file mode 100644 index 0000000000000000000000000000000000000000..69288ede3a5d722198a07544dd773e3a9d9906ba --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/refresh_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H +#define ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class RefreshComponent : public Component { +public: + RefreshComponent() : Component(ARKUI_NODE_REFRESH) {} + explicit RefreshComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetPullToRefresh(int32_t pullToRefresh); + void SetPullDownRatio(float pullDownRatio); + void SetRefreshOffset(float refreshOffset); + void SetRefreshing(bool refreshing); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_REFRESH_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h new file mode 100644 index 0000000000000000000000000000000000000000..12bb583e22275a328a8e0378ad98d03ba069e739 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/relativecontainer_component.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H +#define ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H + +#include +#include + +#include "./relativeContainer/ruleOption.h" +#include "component.h" +namespace ArkUICApiDemo { +class RelativeContainerComponent : public Component { +public: + RelativeContainerComponent() : Component(ARKUI_NODE_RELATIVE_CONTAINER) {} + explicit RelativeContainerComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetRelativeContainerGuideLine(const std::shared_ptr guidelineOption) + { + ArkUI_AttributeItem item = { .object = guidelineOption->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_RELATIVE_CONTAINER_GUIDE_LINE, &item); + guidelineOption_ = guidelineOption; + } + + void SetRelativeContainerBarrier(const std::shared_ptr barrierOption) + { + ArkUI_AttributeItem item = { .object = barrierOption->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_RELATIVE_CONTAINER_BARRIER, &item); + barrierOption_ = barrierOption; + } + + std::shared_ptr GetRuleOption() const + { + return ruleOption_; + } + std::shared_ptr GetGuideLineOption() const + { + return guidelineOption_; + } + std::shared_ptr GetBarrierOption() const + { + return barrierOption_; + } + +private: + std::shared_ptr ruleOption_ = nullptr; + std::shared_ptr guidelineOption_ = nullptr; + std::shared_ptr barrierOption_ = nullptr; +}; +; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_RELATIVECONTAINER_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h new file mode 100644 index 0000000000000000000000000000000000000000..89e04a0300d895575d0a7c08d3acd715521f1008 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/row_component.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_ROW_COMPONENT_H +#define ARKUI_CAPI_DEMO_ROW_COMPONENT_H + +#include "component.h" +namespace ArkUICApiDemo { +class RowComponent : public Component { +public: + RowComponent() : Component(ARKUI_NODE_ROW) {} + explicit RowComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetAlignItems(int32_t verticalAlign) + { + ArkUI_NumberValue value[] = { { .i32 = verticalAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ROW_ALIGN_ITEMS, &item); + } + void SetJustifyContent(int32_t flexAlign) + { + ArkUI_NumberValue value[] = { { .i32 = flexAlign } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_ROW_JUSTIFY_CONTENT, &item); + } +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_ROW_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5575c157d7c3b2d05ce7451913dfc9f335c69222 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "scroll_component.h" +namespace ArkUICApiDemo { + +void ScrollComponent::SetScrollScrollBar(int32_t barState) +{ + ArkUI_NumberValue value[] = { { .i32 = barState } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_DISPLAY_MODE, &item); +} +void ScrollComponent::SetScrollScrollBarWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_WIDTH, &item); +} +void ScrollComponent::SetScrollScrollBarColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_COLOR, &item); +} +void ScrollComponent::SetScrollScrollable(int32_t scrollable) +{ + ArkUI_NumberValue value[] = { { .i32 = scrollable } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SCROLL_DIRECTION, &item); +} +void ScrollComponent::SetScrollEdgeEffect(int32_t edgeEffect, bool alwaysEnabled) +{ + ArkUI_NumberValue value[] = { { .i32 = edgeEffect }, { .i32 = alwaysEnabled } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE_EFFECT, &item); +} +void ScrollComponent::SetScrollEnableScrollInteraction(bool enableScrollInteraction) +{ + ArkUI_NumberValue value[] = { { .i32 = enableScrollInteraction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_SCROLL_INTERACTION, &item); +} +void ScrollComponent::SetScrollFriction(float friction) +{ + ArkUI_NumberValue value[] = { { .f32 = friction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_FRICTION, &item); +} +void ScrollComponent::SetScrollScrollSnap( + int32_t snapAlign, int32_t enableSnapToStart, int32_t enableSnapToEnd, const std::vector& pagination) +{ + auto value = new ArkUI_NumberValue[3 + static_cast(pagination.size())]; + value[0] = { .i32 = snapAlign }; + value[1] = { .i32 = enableSnapToStart }; + value[2] = { .i32 = enableSnapToEnd }; + for (int32_t i = 0; i < pagination.size(); i++) { + value[3 + i] = { .f32 = pagination[i] }; + } + ArkUI_AttributeItem item = { value, 3 + static_cast(pagination.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SNAP, &item); +} +void ScrollComponent::SetScrollNestedScroll(int32_t forward, int32_t backward) +{ + ArkUI_NumberValue value[] = { { .i32 = forward }, { .i32 = backward } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_NESTED_SCROLL, &item); +} +void ScrollComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +void ScrollComponent::SetScrollEdge(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE, &item); +} +void ScrollComponent::SetScrollEnablePaging(int32_t enablePaging) +{ + ArkUI_NumberValue value[] = { { .i32 = enablePaging } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_PAGING, &item); +} +void ScrollComponent::SetScrollPage(int32_t next) +{ + ArkUI_NumberValue value[] = { { .i32 = next } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void ScrollComponent::SetScrollPage(int32_t next, int32_t animation) +{ + ArkUI_NumberValue value[] = { { .i32 = next }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void ScrollComponent::SetScrollBy(float hDistance, float vDistance) +{ + ArkUI_NumberValue value[] = { { .f32 = hDistance }, { .f32 = vDistance } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BY, &item); +} +void ScrollComponent::SetScrollScrollDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_SCROLL_DIRECTION, &item); +} +void ScrollComponent::AddChildWithNumber(int32_t number, ArkUI_NodeType type) +{ + SetBorderWidth(2); + auto node = std::make_shared(type); + if (type == ARKUI_NODE_LIST) { + ArkUI_NumberValue value[] = { { .i32 = ARKUI_AXIS_HORIZONTAL } }; + ArkUI_AttributeItem item = { value, 1 }; + node->setAttribute(NODE_LIST_DIRECTION, &item); + node->SetMargin(DEFAULT_MARGIN); + } + for (int32_t i = 0; i < number; ++i) { + auto column = std::make_shared(ARKUI_NODE_COLUMN); + column->SetWidth(SIZE_50); + column->SetHeight(SIZE_50); + column->SetMargin(DEFAULT_MARGIN); + if (number == 0) { + number = 1; + } + column->SetBackgroundColor((i * 0xFFFFFF / number) | 0xFF000000); + node->AddChild(column); + } + AddChild(node); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h new file mode 100644 index 0000000000000000000000000000000000000000..52cb6ffeb62e0cdbc197815fcc85bfc6caa6edd9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/scroll_component.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CAPIDEMO_SCROLL_COMPONENT_H +#define CAPIDEMO_SCROLL_COMPONENT_H + +#include "component.h" + +namespace ArkUICApiDemo { +class ScrollComponent : public Component { +public: + ScrollComponent() : Component(ARKUI_NODE_SCROLL) {} + explicit ScrollComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetScrollScrollBar(int32_t barState); + void SetScrollScrollBarWidth(float width); + void SetScrollScrollBarColor(uint32_t color); + void SetScrollScrollable(int32_t scrollable); + void SetScrollEdgeEffect(int32_t edgeEffect, bool alwaysEnabled); + void SetScrollEnableScrollInteraction(bool enableScrollInteraction); + void SetScrollFriction(float friction); + void SetScrollScrollSnap( + int32_t snapAlign, int32_t enableSnapToStart, int32_t enableSnapToEnd, const std::vector& pagination); + void SetScrollNestedScroll(int32_t forward, int32_t backward); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + void SetScrollEdge(int32_t type); + void SetScrollEnablePaging(int32_t enablePaging); + void SetScrollPage(int32_t next); + void SetScrollPage(int32_t next, int32_t animation); + void SetScrollBy(float hDistance, float vDistance); + void SetScrollScrollDirection(int32_t direction); + void AddChildWithNumber(int32_t number, ArkUI_NodeType type); +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_SCROLL_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9500a64aede50cc3317a3fd2a85834e9ef514678 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "swiper_component.h" + +namespace ArkUICApiDemo { + +void SwiperComponent::SetSwiperLoop(int32_t loop) +{ + ArkUI_NumberValue value[] = { { .i32 = loop } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_LOOP, &item); +} + +void SwiperComponent::SetSwiperAutoPlay(int32_t playValue) +{ + ArkUI_NumberValue value[] = { { .i32 = playValue } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_AUTO_PLAY, &item); +} + +void SwiperComponent::SetSwiperPrevMigration(float migration, int32_t ignoreBlank) +{ + ArkUI_NumberValue value[] = { { .f32 = migration }, { .i32 = ignoreBlank } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_PREV_MARGIN, &item); +} + +void SwiperComponent::SetSwiperNextMigration(float migration, int32_t ignoreBlank) +{ + ArkUI_NumberValue value[] = { { .f32 = migration }, { .i32 = ignoreBlank } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_NEXT_MARGIN, &item); +} + +void SwiperComponent::SetSwiperDisplayCount(int32_t count) +{ + ArkUI_NumberValue value[] = { { .i32 = count } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_DISPLAY_COUNT, &item); +} + +void SwiperComponent::SetSwiperIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INDEX, &item); +} + +void SwiperComponent::SetSwiperVertical(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_VERTICAL, &item); +} + +void SwiperComponent::SetSwiperEffectMode(int32_t effect) +{ + ArkUI_NumberValue value[] = { { .i32 = effect } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_EDGE_EFFECT_MODE, &item); +} + +void SwiperComponent::SetSwiperNestedScroll(int32_t nestedScroll) +{ + ArkUI_NumberValue value[] = { { .i32 = nestedScroll } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_NESTED_SCROLL, &item); +} + +void SwiperComponent::SetSwiperInterval(float interval) +{ + ArkUI_NumberValue value[] = { { .f32 = interval } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INTERVAL, &item); +} + +void SwiperComponent::SetSwiperDirection(int32_t direction) +{ + ArkUI_NumberValue value[] = { { .i32 = direction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_DIRECTION, &item); +} + +void SwiperComponent::SetSwiperIndicator(ArkUI_SwiperIndicator* indicator) +{ + ArkUI_NumberValue indicator_value[] = { { .i32 = ARKUI_SWIPER_INDICATOR_TYPE_DOT } }; + ArkUI_AttributeItem indicator_item = { indicator_value, sizeof(indicator_value) / sizeof(ArkUI_NumberValue), "", + indicator }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_INDICATOR, &indicator_item); +} + +void SwiperComponent::SetSwiperToIndex(int32_t index, int32_t useAnimation) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = useAnimation } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SWIPER_SWIPE_TO_INDEX, &item); +} + +void SwiperComponent::RegisterOnGesture(const std::function& onGesture) +{ + onGesture_ = onGesture; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_GESTURE_SWIPE, 0, nullptr); +} + +void SwiperComponent::RegisterOnChange(const std::function& onChange) +{ + onChange_ = onChange; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_CHANGE, 0, nullptr); +} + +void SwiperComponent::RegisterOnDidScrollContext(const std::function& onDid) +{ + onDid_ = onDid; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL, 0, nullptr); +} + +void SwiperComponent::RegisterOnAnimationStart(const std::function& onStart) +{ + onStart_ = onStart; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_ANIMATION_START, 0, nullptr); +} + +void SwiperComponent::RegisterOnAnimationEnd(const std::function& onEnd) +{ + onEnd_ = onEnd; + _nodeAPI->registerNodeEvent(_component, NODE_SWIPER_EVENT_ON_ANIMATION_END, 0, nullptr); +} + +void SwiperComponent::OnNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + switch (eventType) { + case NODE_SWIPER_EVENT_ON_GESTURE_SWIPE: + if (onGesture_) { + onGesture_(event); + } + break; + case NODE_SWIPER_EVENT_ON_CHANGE: + if (onChange_) { + onChange_(event); + } + break; + case NODE_SWIPER_EVENT_ON_CONTENT_DID_SCROLL: + if (onDid_) { + onDid_(event); + } + break; + case NODE_SWIPER_EVENT_ON_ANIMATION_START: + if (onStart_) { + onStart_(event); + } + break; + case NODE_SWIPER_EVENT_ON_ANIMATION_END: + if (onEnd_) { + onEnd_(event); + } + break; + default: + break; + } +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h new file mode 100644 index 0000000000000000000000000000000000000000..f8ee03c9875a802d61260ec9ffb231f12c1f96cb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/swiper_component.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CAPIDEMO_SWIPER_COMPONENT_H +#define CAPIDEMO_SWIPER_COMPONENT_H + +#include + +#include "component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { +class SwiperComponent : public Component { +public: + SwiperComponent() : Component(ARKUI_NODE_SWIPER) {} + explicit SwiperComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + void SetSwiperLoop(int32_t loop); + void SetSwiperAutoPlay(int32_t playValue); + void SetSwiperPrevMigration(float migration, int32_t ignoreBlank = false); + void SetSwiperNextMigration(float migration, int32_t ignoreBlank = false); + void SetSwiperDisplayCount(int32_t count); + void SetSwiperIndex(int32_t index); + void SetSwiperVertical(int32_t index); + void SetSwiperNestedScroll(int32_t nestedScroll); + void SetSwiperEffectMode(int32_t effect); + void SetSwiperInterval(float interval); + void SetSwiperDirection(int32_t direction); + void SetSwiperIndicator(ArkUI_SwiperIndicator* indicator); + void SetSwiperToIndex(int32_t index, int32_t useAnimation = false); + void RegisterOnGesture(const std::function& onGesture); + void RegisterOnChange(const std::function& onChange); + void RegisterOnDidScrollContext(const std::function& onDid); + void RegisterOnAnimationStart(const std::function& onStart); + void RegisterOnAnimationEnd(const std::function& onEnd); + void OnNodeEvent(ArkUI_NodeEvent* event) override; + + std::function onGesture_; + std::function onDid_; + std::function onChange_; + std::function onStart_; + std::function onEnd_; +}; +} // namespace ArkUICApiDemo +#endif // CAPIDEMO_SWIPER_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d7de2b2b9a21354658f2a31429384ef681673e7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "text_component.h" + +namespace ArkUICApiDemo { + +void TextComponent::SetFontSize(float fontSize) +{ + ArkUI_NumberValue value[] = { { .f32 = fontSize } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_SIZE, &item); +} +void TextComponent::SetFontColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_FONT_COLOR, &item); +} +void TextComponent::SetTextContent(const std::string& content) +{ + ArkUI_AttributeItem item = { nullptr, 0, content.c_str() }; + _nodeAPI->setAttribute(_component, NODE_TEXT_CONTENT, &item); +} +void TextComponent::SetTextAlign(ArkUI_TextAlignment align) +{ + ArkUI_NumberValue value[] = { { .i32 = align } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_TEXT_ALIGN, &item); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h new file mode 100644 index 0000000000000000000000000000000000000000..ce370faaf3b9f1df9823c4c6b3cd1309a455b601 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/text_component.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXT_COMPONENT_H +#define ARKUI_CAPI_DEMO_TEXT_COMPONENT_H + +#include + +#include "component.h" + +namespace ArkUICApiDemo { +class TextComponent : public Component { +public: + TextComponent() : Component(ARKUI_NODE_TEXT) {} + explicit TextComponent(ArkUI_NodeHandle handle) : Component(handle) {} + void SetFontSize(float fontSize) override; + void SetFontColor(uint32_t color); + void SetTextContent(const std::string& content); + void SetTextAlign(ArkUI_TextAlignment align); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXT_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..05fd85f3c34ed77a9d019c6244b4999b2bd3d29d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.cpp @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "waterflow_component.h" + +namespace ArkUICApiDemo { + +void WaterFlowSectionOption::SetSection(int32_t index, WaterFlowSection section) +{ + OH_ArkUI_WaterFlowSectionOption_SetItemCount(_option, index, section.itemsCount); + OH_ArkUI_WaterFlowSectionOption_SetCrossCount(_option, index, section.crossCount); + OH_ArkUI_WaterFlowSectionOption_SetColumnGap(_option, index, section.columnsGap); + OH_ArkUI_WaterFlowSectionOption_SetRowGap(_option, index, section.rowsGap); + OH_ArkUI_WaterFlowSectionOption_SetMargin( + _option, index, section.margin.top, section.margin.right, section.margin.bottom, section.margin.left); + OH_ArkUI_WaterFlowSectionOption_RegisterGetItemMainSizeCallbackByIndex( + _option, index, section.onGetItemMainSizeByIndex); +} +WaterFlowSection WaterFlowSectionOption::GetSection(int32_t index) +{ + return { OH_ArkUI_WaterFlowSectionOption_GetItemCount(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetCrossCount(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetColumnGap(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetRowGap(_option, index), + OH_ArkUI_WaterFlowSectionOption_GetMargin(_option, index) }; +} + +void WaterFlowSectionOption::SetSize(int32_t size) +{ + OH_ArkUI_WaterFlowSectionOption_SetSize(_option, size); +} +int32_t WaterFlowSectionOption::GetSize() +{ + return OH_ArkUI_WaterFlowSectionOption_GetSize(_option); +} + +void WaterFlowComponent::SetLayoutDirection(int32_t layoutDirection) +{ + ArkUI_NumberValue value[] = { { .i32 = layoutDirection } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_LAYOUT_DIRECTION, &item); +} + +void WaterFlowComponent::SetColumnsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_COLUMN_TEMPLATE, &item); +} + +void WaterFlowComponent::SetRowsTemplate(const std::string& str) +{ + ArkUI_AttributeItem item = { .string = str.c_str() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ROW_TEMPLATE, &item); +} + +void WaterFlowComponent::SetWaterFlowColumnsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_COLUMN_GAP, &item); +} + +void WaterFlowComponent::SetWaterFlowRowsGap(float val) +{ + ArkUI_NumberValue value[] = { { .f32 = val } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ROW_GAP, &item); +} + +void WaterFlowComponent::SetWaterFlowSectionOption(int32_t start, const std::shared_ptr& option) +{ + ArkUI_NumberValue value[] = { { .i32 = start } }; + ArkUI_AttributeItem item = { value, 1, nullptr, option->GetOption() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SECTION_OPTION, &item); + _sectionsOption = option; +} + +void WaterFlowComponent::SetWaterFlowCachedCount(int32_t cachedCount) +{ + ArkUI_NumberValue value[] = { { .i32 = cachedCount } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_CACHED_COUNT, &item); +} + +void WaterFlowComponent::SetWaterFlowFooter(ArkUI_NodeHandle node) +{ + ArkUI_AttributeItem item = { .object = node }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_FOOTER, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index) +{ + ArkUI_NumberValue value[] = { { .i32 = index } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index, int32_t animation) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetWaterFlowScrollToIndex(int32_t index, int32_t animation, int32_t alignment) +{ + ArkUI_NumberValue value[] = { { .i32 = index }, { .i32 = animation }, { .i32 = alignment } }; + ArkUI_AttributeItem item = { value, 3 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_SCROLL_TO_INDEX, &item); +} + +void WaterFlowComponent::SetItemConstraintSize(float minWidth, float maxWidth, float minHeight, float maxHeight) +{ + ArkUI_NumberValue value[] = { { .f32 = minWidth }, { .f32 = maxWidth }, { .f32 = minHeight }, + { .f32 = maxHeight } }; + ArkUI_AttributeItem item = { value, 4 }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_ITEM_CONSTRAINT_SIZE, &item); +} +void WaterFlowComponent::SetWaterFlowNestedScroll(int32_t forward, int32_t backward) +{ + ArkUI_NumberValue value[] = { { .i32 = forward }, { .i32 = backward } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_NESTED_SCROLL, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBar(int32_t barState) +{ + ArkUI_NumberValue value[] = { { .i32 = barState } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_DISPLAY_MODE, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBarWidth(float width) +{ + ArkUI_NumberValue value[] = { { .f32 = width } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_WIDTH, &item); +} +void WaterFlowComponent::SetWaterFlowScrollBarColor(uint32_t color) +{ + ArkUI_NumberValue value[] = { { .u32 = color } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BAR_COLOR, &item); +} +void WaterFlowComponent::SetWaterFlowEnableScrollInteraction(bool enableScrollInteraction) +{ + ArkUI_NumberValue value[] = { { .i32 = enableScrollInteraction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_ENABLE_SCROLL_INTERACTION, &item); +} +void WaterFlowComponent::SetWaterFlowFriction(float friction) +{ + ArkUI_NumberValue value[] = { { .f32 = friction } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_FRICTION, &item); +} +void WaterFlowComponent::SetWaterFlowEdgeEffect(int32_t edgeEffect, bool alwaysEnabled) +{ + ArkUI_NumberValue value[] = { { .i32 = edgeEffect }, { .i32 = alwaysEnabled } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE_EFFECT, &item); +} +void WaterFlowComponent::SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams) +{ + auto value = new ArkUI_NumberValue[2 + static_cast(optionalParams.size())]; + value[0] = { .f32 = hOffset }; + value[1] = { .f32 = vOffset }; + for (int32_t i = 0; i < optionalParams.size(); i++) { + value[2 + i] = { .i32 = optionalParams[i] }; + } + ArkUI_AttributeItem item = { value, 2 + static_cast(optionalParams.size()) }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_OFFSET, &item); +} +void WaterFlowComponent::SetScrollEdge(int32_t type) +{ + ArkUI_NumberValue value[] = { { .i32 = type } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_EDGE, &item); +} +void WaterFlowComponent::SetScrollPage(bool next) +{ + ArkUI_NumberValue value[] = { { .i32 = next } }; + ArkUI_AttributeItem item = { value, 1 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void WaterFlowComponent::SetScrollPage(bool next, bool animation) +{ + ArkUI_NumberValue value[] = { { .i32 = next }, { .i32 = animation } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_PAGE, &item); +} +void WaterFlowComponent::SetScrollBy(float hDistance, float vDistance) +{ + ArkUI_NumberValue value[] = { { .f32 = hDistance }, { .f32 = vDistance } }; + ArkUI_AttributeItem item = { value, 2 }; + _nodeAPI->setAttribute(_component, NODE_SCROLL_BY, &item); +} +void WaterFlowComponent::OnNodeEvent(ArkUI_NodeEvent* event) +{ + auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); + ArkUI_NodeComponentEvent* result = OH_ArkUI_NodeEvent_GetNodeComponentEvent(event); + switch (eventType) { + case NODE_ON_WILL_SCROLL: { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + int32_t source = result->data[2].i32; + if (_onWillScroll) { + _onWillScroll(offset, state, source); + } + break; + } + case NODE_SCROLL_EVENT_ON_REACH_START: + if (_onReachStart) { + _onReachStart(); + } + break; + case NODE_SCROLL_EVENT_ON_REACH_END: + if (_onReachEnd) { + _onReachEnd(); + } + break; + case NODE_SCROLL_EVENT_ON_SCROLL_STOP: + if (_onScrollStop) { + _onScrollStop(); + } + break; + case NODE_WATER_FLOW_ON_DID_SCROLL: + if (_onDidScroll) { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + _onDidScroll(offset, state); + } + break; + case NODE_SCROLL_EVENT_ON_SCROLL_FRAME_BEGIN: + if (_onScrollFrameBegin) { + float offset = result->data[0].f32; + int32_t state = result->data[1].i32; + _onScrollFrameBegin(offset, state); + } + break; + case NODE_WATER_FLOW_ON_SCROLL_INDEX: + if (_onScrollIndex) { + int32_t first = result->data[0].i32; + int32_t last = result->data[1].i32; + _onScrollIndex(first, last); + } + break; + default: + break; + } +} +void WaterFlowComponent::SetOnWillScroll(OnWillScroll onWillScroll) +{ + _onWillScroll = onWillScroll; + _nodeAPI->registerNodeEvent(_component, NODE_ON_WILL_SCROLL, 0, nullptr); +} +void WaterFlowComponent::SetOnReachStart(OnReachStart onReachStart) +{ + _onReachStart = onReachStart; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_REACH_START, 0, nullptr); +} +void WaterFlowComponent::SetOnReachEnd(OnReachEnd onReachEnd) +{ + _onReachEnd = onReachEnd; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_REACH_END, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollStop(OnScrollStop onScrollStop) +{ + _onScrollStop = onScrollStop; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_SCROLL_STOP, 0, nullptr); +} +void WaterFlowComponent::SetOnDidScroll(OnDidScroll onDidScroll) +{ + _onDidScroll = onDidScroll; + _nodeAPI->registerNodeEvent(_component, NODE_WATER_FLOW_ON_DID_SCROLL, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollFrameBegin(OnScrollFrameBegin onScrollFrameBegin) +{ + _onScrollFrameBegin = onScrollFrameBegin; + _nodeAPI->registerNodeEvent(_component, NODE_SCROLL_EVENT_ON_SCROLL_FRAME_BEGIN, 0, nullptr); +} +void WaterFlowComponent::SetOnScrollIndex(OnScrollIndex onScrollIndex) +{ + _onScrollIndex = onScrollIndex; + _nodeAPI->registerNodeEvent(_component, NODE_WATER_FLOW_ON_SCROLL_INDEX, 0, nullptr); +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h new file mode 100644 index 0000000000000000000000000000000000000000..20196b3f7fe346740499c18893632a8e6690618e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/component/waterflow_component.h @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H +#define ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H + +#include +#include + +#include "component.h" +#include "flowitem_component.h" +#include "node_adapter.h" + +namespace ArkUICApiDemo { +using OnWillScroll = std::function; +using OnReachStart = std::function; +using OnReachEnd = std::function; +using OnScrollStop = std::function; +using OnDidScroll = std::function; +using OnScrollFrameBegin = std::function; +using OnScrollIndex = std::function; + +struct WaterFlowSection { + int32_t itemsCount = 0; + int32_t crossCount; + float columnsGap; + float rowsGap; + // top right bottom left + ArkUI_Margin margin { 0, 0, 0, 0 }; + float (*onGetItemMainSizeByIndex)(int32_t itemIndex); + void* userData; +}; + +class WaterFlowSectionOption { +public: + WaterFlowSectionOption() : _option(OH_ArkUI_WaterFlowSectionOption_Create()) {} + ~WaterFlowSectionOption() + { + OH_ArkUI_WaterFlowSectionOption_Dispose(_option); + } + void SetSection(int32_t index, WaterFlowSection section); + WaterFlowSection GetSection(int32_t index); + + void SetSize(int32_t size); + int32_t GetSize(); + ArkUI_WaterFlowSectionOption* GetOption() + { + return _option; + } + +private: + ArkUI_WaterFlowSectionOption* _option; +}; + +class WaterFlowComponent : public Component { +public: + WaterFlowComponent() : Component(ARKUI_NODE_WATER_FLOW) {} + explicit WaterFlowComponent(ArkUI_NodeHandle handle) : Component(handle) {} + + // 引入懒加载模块。 + void SetLazyAdapter(const std::shared_ptr>& adapter) + { + ArkUI_AttributeItem item { nullptr, 0, nullptr, adapter->GetAdapter() }; + _nodeAPI->setAttribute(_component, NODE_WATER_FLOW_NODE_ADAPTER, &item); + _adapter = adapter; + } + void SetLayoutDirection(int32_t layoutDirection); + void SetColumnsTemplate(const std::string& str); + void SetRowsTemplate(const std::string& str); + void SetWaterFlowColumnsGap(float val); + void SetWaterFlowRowsGap(float val); + void SetWaterFlowSectionOption(int32_t start, const std::shared_ptr& option); + void SetWaterFlowCachedCount(int32_t cachedCount); + void SetWaterFlowFooter(ArkUI_NodeHandle node); + void SetWaterFlowScrollToIndex(int32_t index); + void SetWaterFlowScrollToIndex(int32_t index, int32_t animation); + void SetWaterFlowScrollToIndex(int32_t index, int32_t animation, int32_t alignment); + void SetItemConstraintSize(float minWidth, float maxWidth, float minHeight, float maxHeight); + void SetWaterFlowNestedScroll(int32_t forward, int32_t backward); + void SetWaterFlowScrollBar(int32_t barState); + void SetWaterFlowScrollBarWidth(float width); + void SetWaterFlowScrollBarColor(uint32_t color); + void SetWaterFlowEnableScrollInteraction(bool enableScrollInteraction); + void SetWaterFlowFriction(float friction); + void SetWaterFlowEdgeEffect(int32_t edgeEffect, bool alwaysEnabled); + /** + * @brief Set the scroll position to the specified offset. + * @param hOffset horizontal scrolling offset + * @param vOffset vertical scrolling offset + * @param optionalParams + * [0] scrolling duration, in milliseconds. + * [1] scrolling curve. The parameter type is ArkUI_AnimationCurve. + * [2] whether to enable the default spring animation. + * [3] sets whether scrolling can cross the boundary. + * [4] canOverScroll. + */ + void SetScrollTo(float hOffset, float vOffset, const std::vector& optionalParams); + void SetScrollEdge(int32_t type); + void SetScrollPage(bool next); + void SetScrollPage(bool next, bool animation); + void SetScrollBy(float hDistance, float vDistance); + + void OnNodeEvent(ArkUI_NodeEvent* event) override; + void SetOnWillScroll(OnWillScroll onWillScroll); + void SetOnReachStart(OnReachStart onReachStart); + void SetOnReachEnd(OnReachEnd onReachEnd); + void SetOnScrollStop(OnScrollStop onScrollStop); + void SetOnDidScroll(OnDidScroll onDidScroll); + void SetOnScrollFrameBegin(OnScrollFrameBegin onScrollFrameBegin); + void SetOnScrollIndex(OnScrollIndex onScrollIndex); + + std::shared_ptr> GetAdapter() const + { + return _adapter; + } + std::shared_ptr GetSectionOption() const + { + return _sectionsOption; + } + void ReleaseSectionOption() + { + _sectionsOption.reset(); + } + +private: + std::shared_ptr _sectionsOption; + std::shared_ptr> _adapter; + + OnWillScroll _onWillScroll; + OnReachStart _onReachStart; + OnReachEnd _onReachEnd; + OnScrollStop _onScrollStop; + OnDidScroll _onDidScroll; + OnScrollFrameBegin _onScrollFrameBegin; + OnScrollIndex _onScrollIndex; +}; +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_WATERFLOW_COMPONENT_H \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/customdialog/customdialog_content_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/customdialog/customdialog_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..70d7c62d6ae4908845303e5164ebe83f30d11a9f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/customdialog/customdialog_content_test.cpp @@ -0,0 +1,936 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "customdialog_content_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +ArkUI_NativeDialogAPI_1* dialogAPI_global = nullptr; +ArkUI_NativeDialogHandle dialog_global; + +static auto SetWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto SetHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto SetWidthPercent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH_PERCENT, &width_item); + return nodeHandle; +} + +static auto SetHeightPercent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT_PERCENT, &height_item); + return nodeHandle; +} + +static auto SetBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto SetMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto SetId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto SetDialog(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_200); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_300); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_BLUE); + return nodeHandle; +} + +static auto SetButton(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id) +{ + nodeHandle = SetWidth(nodeAPI, nodeHandle, SIZE_30); + nodeHandle = SetHeight(nodeAPI, nodeHandle, SIZE_30); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + nodeHandle = SetMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetId(nodeAPI, nodeHandle, id); + return nodeHandle; +} + +static auto SetColumn(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle) +{ + nodeHandle = SetWidthPercent(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetHeightPercent(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = SetBackgroundColor(nodeAPI, nodeHandle, COLOR_RED); + return nodeHandle; +} + +static auto CreateChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle parentNode, ArkUI_NodeType type) +{ + auto childNode = nodeAPI->createNode(type); + nodeAPI->addChild(parentNode, childNode); + return childNode; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CustomDialogContentTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CustomDialogContentTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CustomDialogContentTest", "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + ArkUI_NativeDialogAPI_1* dialogAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_DIALOG, ArkUI_NativeDialogAPI_1, dialogAPI); + + // Test setContent,setBackgroundColor, and create + if (eventId == ON_CLICK_EVENT_ID_1) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->show(customDialog, false); + } + // Test removeContent + if (eventId == ON_CLICK_EVENT_ID_2) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->removeContent(customDialog); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->show(customDialog, false); + } + // Test setCornerRadius + if (eventId == ON_CLICK_EVENT_ID_3) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_PURPLE); + dialogAPI->setCornerRadius(customDialog, SIZE_100, SIZE_30, PARAM_0, PARAM_NEGATIVE_100); + dialogAPI->show(customDialog, false); + } + // Test dispose + if (eventId == ON_CLICK_EVENT_ID_4) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->dispose(customDialog); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_TOP_START, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_5) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_TOP_START, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_TOP, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_6) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_TOP, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_TOP_END, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_7) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_TOP_END, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_START, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_8) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_START, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_CENTER, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_9) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_CENTER, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_END, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_10) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_END, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_BOTTOM_START, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_11) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_BOTTOM_START, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_BOTTOM, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_12) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_BOTTOM, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_BOTTOM_END, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_13) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_BOTTOM_END, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment -1, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_14) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, PARAM_NEGATIVE_1, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment 9, and offsetX = 0 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_15) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, PARAM_9, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment resetContentAlignment + if (eventId == ON_CLICK_EVENT_ID_16) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_BOTTOM_END, PARAM_0, PARAM_0); + dialogAPI->resetContentAlignment(customDialog); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_CENTER and offsetX = 200 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_17) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_CENTER, SIZE_200, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_CENTER and offsetX = 0 offsetY = 200 + if (eventId == ON_CLICK_EVENT_ID_18) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_CENTER, PARAM_0, SIZE_200); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_CENTER and offsetX = -200 offsetY = 0 + if (eventId == ON_CLICK_EVENT_ID_19) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_CENTER, PARAM_NEGATIVE_200, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setContentAlignment with ARKUI_ALIGNMENT_CENTER and offsetX = 0 offsetY = -200 + if (eventId == ON_CLICK_EVENT_ID_20) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_CENTER, PARAM_0, PARAM_NEGATIVE_200); + dialogAPI->show(customDialog, false); + } + // Test setModalMode with true + if (eventId == ON_CLICK_EVENT_ID_21) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, true); + dialogAPI->show(customDialog, false); + } + // Test setModalMode with false + if (eventId == ON_CLICK_EVENT_ID_22) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, false); + dialogAPI->show(customDialog, false); + } + // Test setAutoCancel with true (if setModalMode is not set, it defaults to true) + if (eventId == ON_CLICK_EVENT_ID_23) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setAutoCancel(customDialog, true); + dialogAPI->show(customDialog, false); + } + // Test setAutoCancel with false (if setModalMode is not set, it defaults to true) + if (eventId == ON_CLICK_EVENT_ID_24) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setAutoCancel(customDialog, false); + dialogAPI->show(customDialog, false); + } + // Test setAutoCancel with true (setModalMode is set to true) + if (eventId == ON_CLICK_EVENT_ID_25) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setAutoCancel(customDialog, true); + dialogAPI->setModalMode(customDialog, true); + dialogAPI->show(customDialog, false); + } + // Test setAutoCancel with false (setModalMode is set to true) + if (eventId == ON_CLICK_EVENT_ID_26) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setAutoCancel(customDialog, false); + dialogAPI->setModalMode(customDialog, true); + dialogAPI->show(customDialog, false); + } + // Test setAutoCancel with true (setModalMode is set to false) + if (eventId == ON_CLICK_EVENT_ID_27) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setAutoCancel(customDialog, true); + dialogAPI->setModalMode(customDialog, false); + dialogAPI->show(customDialog, false); + } + // Test setAutoCancel with false (setModalMode is set to false) + if (eventId == ON_CLICK_EVENT_ID_28) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setAutoCancel(customDialog, false); + dialogAPI->setModalMode(customDialog, false); + dialogAPI->show(customDialog, false); + } + // Test enableCustomAnimation is set to true + if (eventId == ON_CLICK_EVENT_ID_29) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->enableCustomAnimation(customDialog, true); + dialogAPI->show(customDialog, false); + } + // Test enableCustomAnimation is set to false + if (eventId == ON_CLICK_EVENT_ID_30) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->enableCustomAnimation(customDialog, false); + dialogAPI->show(customDialog, false); + } + // Test setMask with maskColor + if (eventId == ON_CLICK_EVENT_ID_31) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = SIZE_500; + maskRect.height = SIZE_800; + dialogAPI->setMask(customDialog, 0x77550000, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with maskColor + if (eventId == ON_CLICK_EVENT_ID_32) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = SIZE_500; + maskRect.height = SIZE_800; + dialogAPI->setMask(customDialog, 0x77005500, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height + if (eventId == ON_CLICK_EVENT_ID_33) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = SIZE_250; + maskRect.height = SIZE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height, and setModalMode is set to false + if (eventId == ON_CLICK_EVENT_ID_34) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, false); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = SIZE_250; + maskRect.height = SIZE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height, and set to negative values + if (eventId == ON_CLICK_EVENT_ID_35) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = PARAM_NEGATIVE_250; + maskRect.height = PARAM_NEGATIVE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask's width and height, set to 0 + if (eventId == ON_CLICK_EVENT_ID_36) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = PARAM_0; + maskRect.height = PARAM_0; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height, and x set to -100 + if (eventId == ON_CLICK_EVENT_ID_37) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_NEGATIVE_100; + maskRect.y = PARAM_0; + maskRect.width = SIZE_250; + maskRect.height = SIZE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height, and y set to -100 + if (eventId == ON_CLICK_EVENT_ID_38) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_NEGATIVE_100; + maskRect.width = SIZE_250; + maskRect.height = SIZE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height, and x set to 100 + if (eventId == ON_CLICK_EVENT_ID_39) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = SIZE_100; + maskRect.y = PARAM_0; + maskRect.width = SIZE_250; + maskRect.height = SIZE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setMask with half width and height, and y set to 100 + if (eventId == ON_CLICK_EVENT_ID_40) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = SIZE_100; + maskRect.width = SIZE_250; + maskRect.height = SIZE_400; + dialogAPI->setMask(customDialog, 0x77000055, &maskRect); + dialogAPI->show(customDialog, false); + } + // Test setGridColumnCount with default value (not set) + if (eventId == ON_CLICK_EVENT_ID_41) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->show(customDialog, false); + } + // Test setGridColumnCount set to 1 + if (eventId == ON_CLICK_EVENT_ID_42) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setGridColumnCount(customDialog, PARAM_1); + dialogAPI->show(customDialog, false); + } + // Test setGridColumnCount set to 2 + if (eventId == ON_CLICK_EVENT_ID_43) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setGridColumnCount(customDialog, PARAM_2); + dialogAPI->show(customDialog, false); + } + // Test setGridColumnCount set to 100 + if (eventId == ON_CLICK_EVENT_ID_44) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setGridColumnCount(customDialog, SIZE_100); + dialogAPI->show(customDialog, false); + } + // Test setGridColumnCount set to 0 + if (eventId == ON_CLICK_EVENT_ID_45) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setGridColumnCount(customDialog, PARAM_0); + dialogAPI->show(customDialog, false); + } + // Test setGridColumnCount set to -1 + if (eventId == ON_CLICK_EVENT_ID_46) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setGridColumnCount(customDialog, PARAM_NEGATIVE_1); + dialogAPI->show(customDialog, false); + } + // Test show as true with setModalMode as true + if (eventId == ON_CLICK_EVENT_ID_47) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, true); + dialogAPI->show(customDialog, true); + } + // Test show as false with setModalMode as true + if (eventId == ON_CLICK_EVENT_ID_48) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, true); + dialogAPI->show(customDialog, false); + } + // Test show as true with setModalMode as false + if (eventId == ON_CLICK_EVENT_ID_49) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, false); + dialogAPI->show(customDialog, true); + } + // Test show as false with setModalMode as false + if (eventId == ON_CLICK_EVENT_ID_50) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setModalMode(customDialog, false); + dialogAPI->show(customDialog, false); + } + // Test the scenario of nesting two layers of pop-up customDialog (pop up two customDialog at the same time) + if (eventId == ON_CLICK_EVENT_ID_51) { + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + auto customDialog = dialogAPI->create(); + dialogAPI->setContent(customDialog, column1); + dialogAPI->setBackgroundColor(customDialog, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog, ARKUI_ALIGNMENT_TOP, PARAM_0, PARAM_0); + dialogAPI->show(customDialog, false); + + auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column2 = SetDialog(nodeAPI, column2); + auto customDialog2 = dialogAPI->create(); + dialogAPI->setContent(customDialog2, column2); + dialogAPI->setBackgroundColor(customDialog2, COLOR_GREEN); + dialogAPI->setContentAlignment(customDialog2, ARKUI_ALIGNMENT_BOTTOM, PARAM_0, PARAM_0); + dialogAPI->show(customDialog2, false); + } + // Test registerOnWillDismiss + if (eventId == ON_CLICK_EVENT_ID_52) { + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_DIALOG, ArkUI_NativeDialogAPI_1, dialogAPI_global); + auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN); + column1 = SetDialog(nodeAPI, column1); + dialog_global = dialogAPI->create(); + dialogAPI->setContent(dialog_global, column1); + dialogAPI->setBackgroundColor(dialog_global, COLOR_GREEN); + ArkUI_Rect maskRect = {}; + maskRect.x = PARAM_0; + maskRect.y = PARAM_0; + maskRect.width = SIZE_400; + maskRect.height = SIZE_500; + dialogAPI->setMask(dialog_global, 0x77000055, &maskRect); + dialogAPI->registerOnWillDismiss(dialog_global, [](int32_t reason) -> bool { + if (reason == DIALOG_DISMISS_TOUCH_OUTSIDE) { + if (dialog_global) { + dialogAPI_global->close(dialog_global); + } + return true; + } + return true; + }); + dialogAPI->show(dialog_global, false); + } +} + +napi_value CustomDialogContentTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CustomDialogContentTest", "CreateNativeNode"); + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CustomDialogContentTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row2 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row3 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row4 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row5 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto row6 = CreateChildNode(nodeAPI, column, ARKUI_NODE_ROW); + auto button1 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button2 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button3 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button4 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button5 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button6 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button7 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button8 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button9 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button10 = CreateChildNode(nodeAPI, row1, ARKUI_NODE_BUTTON); + auto button11 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button12 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button13 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button14 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button15 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button16 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button17 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button18 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button19 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button20 = CreateChildNode(nodeAPI, row2, ARKUI_NODE_BUTTON); + auto button21 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button22 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button23 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button24 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button25 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button26 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button27 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button28 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button29 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button30 = CreateChildNode(nodeAPI, row3, ARKUI_NODE_BUTTON); + auto button31 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button32 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button33 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button34 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button35 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button36 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button37 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button38 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button39 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button40 = CreateChildNode(nodeAPI, row4, ARKUI_NODE_BUTTON); + auto button41 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button42 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button43 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button44 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button45 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button46 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button47 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button48 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button49 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button50 = CreateChildNode(nodeAPI, row5, ARKUI_NODE_BUTTON); + auto button51 = CreateChildNode(nodeAPI, row6, ARKUI_NODE_BUTTON); + auto button52 = CreateChildNode(nodeAPI, row6, ARKUI_NODE_BUTTON); + + column = SetColumn(nodeAPI, column); + button1 = SetButton(nodeAPI, button1, "button1"); + button2 = SetButton(nodeAPI, button2, "button2"); + button3 = SetButton(nodeAPI, button3, "button3"); + button4 = SetButton(nodeAPI, button4, "button4"); + button5 = SetButton(nodeAPI, button5, "button5"); + button6 = SetButton(nodeAPI, button6, "button6"); + button7 = SetButton(nodeAPI, button7, "button7"); + button8 = SetButton(nodeAPI, button8, "button8"); + button9 = SetButton(nodeAPI, button9, "button9"); + button10 = SetButton(nodeAPI, button10, "button10"); + button11 = SetButton(nodeAPI, button11, "button11"); + button12 = SetButton(nodeAPI, button12, "button12"); + button13 = SetButton(nodeAPI, button13, "button13"); + button14 = SetButton(nodeAPI, button14, "button14"); + button15 = SetButton(nodeAPI, button15, "button15"); + button16 = SetButton(nodeAPI, button16, "button16"); + button17 = SetButton(nodeAPI, button17, "button17"); + button18 = SetButton(nodeAPI, button18, "button18"); + button19 = SetButton(nodeAPI, button19, "button19"); + button20 = SetButton(nodeAPI, button20, "button20"); + button21 = SetButton(nodeAPI, button21, "button21"); + button22 = SetButton(nodeAPI, button22, "button22"); + button23 = SetButton(nodeAPI, button23, "button23"); + button24 = SetButton(nodeAPI, button24, "button24"); + button25 = SetButton(nodeAPI, button25, "button25"); + button26 = SetButton(nodeAPI, button26, "button26"); + button27 = SetButton(nodeAPI, button27, "button27"); + button28 = SetButton(nodeAPI, button28, "button28"); + button29 = SetButton(nodeAPI, button29, "button29"); + button30 = SetButton(nodeAPI, button30, "button30"); + button31 = SetButton(nodeAPI, button31, "button31"); + button32 = SetButton(nodeAPI, button32, "button32"); + button33 = SetButton(nodeAPI, button33, "button33"); + button34 = SetButton(nodeAPI, button34, "button34"); + button35 = SetButton(nodeAPI, button35, "button35"); + button36 = SetButton(nodeAPI, button36, "button36"); + button37 = SetButton(nodeAPI, button37, "button37"); + button38 = SetButton(nodeAPI, button38, "button38"); + button39 = SetButton(nodeAPI, button39, "button39"); + button40 = SetButton(nodeAPI, button40, "button40"); + button41 = SetButton(nodeAPI, button41, "button41"); + button42 = SetButton(nodeAPI, button42, "button42"); + button43 = SetButton(nodeAPI, button43, "button43"); + button44 = SetButton(nodeAPI, button44, "button44"); + button45 = SetButton(nodeAPI, button45, "button45"); + button46 = SetButton(nodeAPI, button46, "button46"); + button47 = SetButton(nodeAPI, button47, "button47"); + button48 = SetButton(nodeAPI, button48, "button48"); + button49 = SetButton(nodeAPI, button49, "button49"); + button50 = SetButton(nodeAPI, button50, "button50"); + button51 = SetButton(nodeAPI, button51, "button51"); + button52 = SetButton(nodeAPI, button52, "button52"); + + nodeAPI->registerNodeEvent(button1, NODE_ON_CLICK, ON_CLICK_EVENT_ID_1, nullptr); + nodeAPI->registerNodeEvent(button2, NODE_ON_CLICK, ON_CLICK_EVENT_ID_2, nullptr); + nodeAPI->registerNodeEvent(button3, NODE_ON_CLICK, ON_CLICK_EVENT_ID_3, nullptr); + nodeAPI->registerNodeEvent(button4, NODE_ON_CLICK, ON_CLICK_EVENT_ID_4, nullptr); + nodeAPI->registerNodeEvent(button5, NODE_ON_CLICK, ON_CLICK_EVENT_ID_5, nullptr); + nodeAPI->registerNodeEvent(button6, NODE_ON_CLICK, ON_CLICK_EVENT_ID_6, nullptr); + nodeAPI->registerNodeEvent(button7, NODE_ON_CLICK, ON_CLICK_EVENT_ID_7, nullptr); + nodeAPI->registerNodeEvent(button8, NODE_ON_CLICK, ON_CLICK_EVENT_ID_8, nullptr); + nodeAPI->registerNodeEvent(button9, NODE_ON_CLICK, ON_CLICK_EVENT_ID_9, nullptr); + nodeAPI->registerNodeEvent(button10, NODE_ON_CLICK, ON_CLICK_EVENT_ID_10, nullptr); + nodeAPI->registerNodeEvent(button11, NODE_ON_CLICK, ON_CLICK_EVENT_ID_11, nullptr); + nodeAPI->registerNodeEvent(button12, NODE_ON_CLICK, ON_CLICK_EVENT_ID_12, nullptr); + nodeAPI->registerNodeEvent(button13, NODE_ON_CLICK, ON_CLICK_EVENT_ID_13, nullptr); + nodeAPI->registerNodeEvent(button14, NODE_ON_CLICK, ON_CLICK_EVENT_ID_14, nullptr); + nodeAPI->registerNodeEvent(button15, NODE_ON_CLICK, ON_CLICK_EVENT_ID_15, nullptr); + nodeAPI->registerNodeEvent(button16, NODE_ON_CLICK, ON_CLICK_EVENT_ID_16, nullptr); + nodeAPI->registerNodeEvent(button17, NODE_ON_CLICK, ON_CLICK_EVENT_ID_17, nullptr); + nodeAPI->registerNodeEvent(button18, NODE_ON_CLICK, ON_CLICK_EVENT_ID_18, nullptr); + nodeAPI->registerNodeEvent(button19, NODE_ON_CLICK, ON_CLICK_EVENT_ID_19, nullptr); + nodeAPI->registerNodeEvent(button20, NODE_ON_CLICK, ON_CLICK_EVENT_ID_20, nullptr); + nodeAPI->registerNodeEvent(button21, NODE_ON_CLICK, ON_CLICK_EVENT_ID_21, nullptr); + nodeAPI->registerNodeEvent(button22, NODE_ON_CLICK, ON_CLICK_EVENT_ID_22, nullptr); + nodeAPI->registerNodeEvent(button23, NODE_ON_CLICK, ON_CLICK_EVENT_ID_23, nullptr); + nodeAPI->registerNodeEvent(button24, NODE_ON_CLICK, ON_CLICK_EVENT_ID_24, nullptr); + nodeAPI->registerNodeEvent(button25, NODE_ON_CLICK, ON_CLICK_EVENT_ID_25, nullptr); + nodeAPI->registerNodeEvent(button26, NODE_ON_CLICK, ON_CLICK_EVENT_ID_26, nullptr); + nodeAPI->registerNodeEvent(button27, NODE_ON_CLICK, ON_CLICK_EVENT_ID_27, nullptr); + nodeAPI->registerNodeEvent(button28, NODE_ON_CLICK, ON_CLICK_EVENT_ID_28, nullptr); + nodeAPI->registerNodeEvent(button29, NODE_ON_CLICK, ON_CLICK_EVENT_ID_29, nullptr); + nodeAPI->registerNodeEvent(button30, NODE_ON_CLICK, ON_CLICK_EVENT_ID_30, nullptr); + nodeAPI->registerNodeEvent(button31, NODE_ON_CLICK, ON_CLICK_EVENT_ID_31, nullptr); + nodeAPI->registerNodeEvent(button32, NODE_ON_CLICK, ON_CLICK_EVENT_ID_32, nullptr); + nodeAPI->registerNodeEvent(button33, NODE_ON_CLICK, ON_CLICK_EVENT_ID_33, nullptr); + nodeAPI->registerNodeEvent(button34, NODE_ON_CLICK, ON_CLICK_EVENT_ID_34, nullptr); + nodeAPI->registerNodeEvent(button35, NODE_ON_CLICK, ON_CLICK_EVENT_ID_35, nullptr); + nodeAPI->registerNodeEvent(button36, NODE_ON_CLICK, ON_CLICK_EVENT_ID_36, nullptr); + nodeAPI->registerNodeEvent(button37, NODE_ON_CLICK, ON_CLICK_EVENT_ID_37, nullptr); + nodeAPI->registerNodeEvent(button38, NODE_ON_CLICK, ON_CLICK_EVENT_ID_38, nullptr); + nodeAPI->registerNodeEvent(button39, NODE_ON_CLICK, ON_CLICK_EVENT_ID_39, nullptr); + nodeAPI->registerNodeEvent(button40, NODE_ON_CLICK, ON_CLICK_EVENT_ID_40, nullptr); + nodeAPI->registerNodeEvent(button41, NODE_ON_CLICK, ON_CLICK_EVENT_ID_41, nullptr); + nodeAPI->registerNodeEvent(button42, NODE_ON_CLICK, ON_CLICK_EVENT_ID_42, nullptr); + nodeAPI->registerNodeEvent(button43, NODE_ON_CLICK, ON_CLICK_EVENT_ID_43, nullptr); + nodeAPI->registerNodeEvent(button44, NODE_ON_CLICK, ON_CLICK_EVENT_ID_44, nullptr); + nodeAPI->registerNodeEvent(button45, NODE_ON_CLICK, ON_CLICK_EVENT_ID_45, nullptr); + nodeAPI->registerNodeEvent(button46, NODE_ON_CLICK, ON_CLICK_EVENT_ID_46, nullptr); + nodeAPI->registerNodeEvent(button47, NODE_ON_CLICK, ON_CLICK_EVENT_ID_47, nullptr); + nodeAPI->registerNodeEvent(button48, NODE_ON_CLICK, ON_CLICK_EVENT_ID_48, nullptr); + nodeAPI->registerNodeEvent(button49, NODE_ON_CLICK, ON_CLICK_EVENT_ID_49, nullptr); + nodeAPI->registerNodeEvent(button50, NODE_ON_CLICK, ON_CLICK_EVENT_ID_50, nullptr); + nodeAPI->registerNodeEvent(button51, NODE_ON_CLICK, ON_CLICK_EVENT_ID_51, nullptr); + nodeAPI->registerNodeEvent(button52, NODE_ON_CLICK, ON_CLICK_EVENT_ID_52, nullptr); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CustomDialogContentTest", + "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/customdialog/customdialog_content_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/customdialog/customdialog_content_test.h new file mode 100644 index 0000000000000000000000000000000000000000..01cf899d86a8ab381e197c7ca2a61441d726e994 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/customdialog/customdialog_content_test.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_CUSTOMDIALOG_CONTENT_TEST_H +#define ARKUI_CAPI_DEMO_CUSTOMDIALOG_CONTENT_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define PARAM_NEGATIVE_200 (-200) +#define PARAM_NEGATIVE_250 (-250) +#define PARAM_NEGATIVE_400 (-400) +#define SIZE_250 250 +#define SIZE_800 800 +#define ON_CLICK_EVENT_ID_1 6014 +#define ON_CLICK_EVENT_ID_2 6015 +#define ON_CLICK_EVENT_ID_3 6016 +#define ON_CLICK_EVENT_ID_4 6017 +#define ON_CLICK_EVENT_ID_5 6018 +#define ON_CLICK_EVENT_ID_6 6019 +#define ON_CLICK_EVENT_ID_7 6020 +#define ON_CLICK_EVENT_ID_8 6021 +#define ON_CLICK_EVENT_ID_9 6022 +#define ON_CLICK_EVENT_ID_10 6023 +#define ON_CLICK_EVENT_ID_11 6024 +#define ON_CLICK_EVENT_ID_12 6025 +#define ON_CLICK_EVENT_ID_13 6026 +#define ON_CLICK_EVENT_ID_14 6027 +#define ON_CLICK_EVENT_ID_15 6028 +#define ON_CLICK_EVENT_ID_16 6029 +#define ON_CLICK_EVENT_ID_17 6030 +#define ON_CLICK_EVENT_ID_18 6031 +#define ON_CLICK_EVENT_ID_19 6032 +#define ON_CLICK_EVENT_ID_20 6033 +#define ON_CLICK_EVENT_ID_21 6034 +#define ON_CLICK_EVENT_ID_22 6035 +#define ON_CLICK_EVENT_ID_23 6036 +#define ON_CLICK_EVENT_ID_24 6037 +#define ON_CLICK_EVENT_ID_25 6038 +#define ON_CLICK_EVENT_ID_26 6039 +#define ON_CLICK_EVENT_ID_27 6040 +#define ON_CLICK_EVENT_ID_28 6041 +#define ON_CLICK_EVENT_ID_29 6042 +#define ON_CLICK_EVENT_ID_30 6043 +#define ON_CLICK_EVENT_ID_31 6044 +#define ON_CLICK_EVENT_ID_32 6045 +#define ON_CLICK_EVENT_ID_33 6046 +#define ON_CLICK_EVENT_ID_34 6047 +#define ON_CLICK_EVENT_ID_35 6048 +#define ON_CLICK_EVENT_ID_36 6049 +#define ON_CLICK_EVENT_ID_37 6050 +#define ON_CLICK_EVENT_ID_38 6051 +#define ON_CLICK_EVENT_ID_39 6052 +#define ON_CLICK_EVENT_ID_40 6053 +#define ON_CLICK_EVENT_ID_41 6054 +#define ON_CLICK_EVENT_ID_42 6055 +#define ON_CLICK_EVENT_ID_43 6056 +#define ON_CLICK_EVENT_ID_44 6057 +#define ON_CLICK_EVENT_ID_45 6058 +#define ON_CLICK_EVENT_ID_46 6059 +#define ON_CLICK_EVENT_ID_47 6060 +#define ON_CLICK_EVENT_ID_48 6061 +#define ON_CLICK_EVENT_ID_49 6062 +#define ON_CLICK_EVENT_ID_50 6063 +#define ON_CLICK_EVENT_ID_51 6064 +#define ON_CLICK_EVENT_ID_52 6065 +#define ON_CLICK_EVENT_ID_53 6066 + +class CustomDialogContentTest { +public: + ~CustomDialogContentTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_CUSTOMDIALOG_CONTENT_TEST_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 100644 index 0000000000000000000000000000000000000000..7433219fd12b872aa3870351700b583ba1ecb351 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "manager/plugin_manager.h" +#include "textinput/textinput_bluronsubmit_test.h" +#include "textinput/textinput_cancelbutton_test.h" +#include "textinput/textinput_caretposition_test.h" +#include "textinput/textinput_content_type_test.h" +#include "textinput/textinput_controller_test.h" +#include "textinput/textinput_custom_keyboard_test.h" +#include "textinput/textinput_enable_auto_fill_test.h" +#include "textinput/textinput_fontfeature_test.h" +#include "textinput/textinput_getcaretoffset_test.h" +#include "textinput/textinput_inputfilter_test.h" +#include "textinput/textinput_maxlines_test.h" +#include "textinput/textinput_minfontsizeandmaxfontsize.h" +#include "textinput/textinput_numberoflines_test.h" +#include "textinput/textinput_password_rules_test.h" +#include "textinput/textinput_selectall_test.h" +#include "textinput/textinput_selection_menu_hidden_test.h" +#include "textinput/textinput_settextselection_test.h" +#include "textinput/textinput_showkeyboardonfocus_test.h" +#include "textinput/textinput_style_test.h" +#include "textinput/textinput_textplaceholder_test.h" +#include "textinput/textinput_underlinecolor_test.h" +#include "textinput/textinput_wordbreak_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[] = { + { "textInputCustomKeyboardPage1Test", nullptr, TextInputCustomKeyboardTest::CreateNativeNodePage1, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputCustomKeyboardPage2Test", nullptr, TextInputCustomKeyboardTest::CreateNativeNodePage2, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputCustomKeyboardPage3Test", nullptr, TextInputCustomKeyboardTest::CreateNativeNodePage3, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputCustomKeyboardPage4Test", nullptr, TextInputCustomKeyboardTest::CreateNativeNodePage4, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputCustomKeyboardPage5Test", nullptr, TextInputCustomKeyboardTest::CreateNativeNodePage5, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputCustomKeyboardPage6Test", nullptr, TextInputCustomKeyboardTest::CreateNativeNodePage6, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputSelectAllTest", nullptr, TextInputSelectAllTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "textInputEnableAutoFillTest", nullptr, TextInputEnableAutoFillTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputContentTypePage1Test", nullptr, TextInputContentTypeTest::CreateNativeNodePage1, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputContentTypePage2Test", nullptr, TextInputContentTypeTest::CreateNativeNodePage2, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputPasswordRulesPage1Test", nullptr, TextInputPasswordRulesTest::CreateNativeNodePage1, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputPasswordRulesPage2Test", nullptr, TextInputPasswordRulesTest::CreateNativeNodePage2, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputPasswordRulesPage3Test", nullptr, TextInputPasswordRulesTest::CreateNativeNodePage3, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputSelectionMenuHiddenTest", nullptr, TextInputSelectionMenuHiddenTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputFontFeaturePage1Test", nullptr, TextInputFontFeatureTest::CreateNativeNodePage1, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputFontFeaturePage2Test", nullptr, TextInputFontFeatureTest::CreateNativeNodePage2, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputFontFeaturePage3Test", nullptr, TextInputFontFeatureTest::CreateNativeNodePage3, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputTextPlaceholderTest", nullptr, TextInputTextPlaceholderTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputCancelButtonTest", nullptr, TextInputCancelButtonTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "textInputSetTextSelectionTest", nullptr, TextInputSetTextSelectionTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputUnderlineColorTest", nullptr, TextInputUnderlineColorTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputWordBreakTest", nullptr, TextInputWordBreakTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "textInputStyleTest", nullptr, TextInputStyleTest::CreateNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "textInputMinFontSizeAndMaxFontSizeTest", nullptr, TextInputMinFontSizeAndMaxFontSizeTest::CreateNativeNode, + nullptr, nullptr, nullptr, napi_default, nullptr }, + { "textInputMaxLinesTest", nullptr, TextInputMaxLinesTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "textInputNumberOfLinesTest", nullptr, TextInputNumberOfLinesTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputInputFilterTest", nullptr, TextInputInputFilterTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "textInputShowKeyboardOnFocusTest", nullptr, TextInputShowKeyboardOnFocusTest::CreateNativeNode, nullptr, + nullptr, nullptr, napi_default, nullptr }, + { "textInputShowKeyboardOnFocusAbnormalTest", nullptr, + TextInputShowKeyboardOnFocusTest::CreateAbnormalNativeNode, nullptr, nullptr, nullptr, napi_default, + nullptr }, + { "textInputBlurOnSubmitTest", nullptr, TextInputBlurOnSubmitTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "textInputGetCaretOffsetTest", nullptr, TextInputGetCaretOffsetTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputCaretPositionTest", nullptr, TextInputCaretPositionTest::CreateNativeNode, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "textInputControllerTest", nullptr, TextInputControllerTest::CreateNativeNode, nullptr, nullptr, nullptr, + napi_default, nullptr }, + }; + if (napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, ArkUICApiDemo::LOG_PRINT_DOMAIN, "Init", "napi_define_properties failed"); + return nullptr; + } + + ArkUICApiDemo::PluginManager::GetInstance()->Export(env, exports); + return exports; +} +EXTERN_C_END + +static napi_module nativerenderModule = { .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "nativerender", + .nm_priv = ((void*)0), + .reserved = { 0 } }; + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&nativerenderModule); +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_bluronsubmit_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_bluronsubmit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3e4e017ef648d1599e624072b0fd7a5529eb300 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_bluronsubmit_test.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_bluronsubmit_test.h" + +#include +#include + +#include "../manager/plugin_manager.h" + +#define ON_BLUR_ID 2 +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t value) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_200 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &width_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = DEFAULT_MARGIN } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue blur_value[] = { { .i32 = value } }; + ArkUI_AttributeItem blur_item = { blur_value, sizeof(blur_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_BLUR_ON_SUBMIT, &blur_item); + + ArkUI_NumberValue keyboard_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + + ArkUI_NumberValue keyboard1_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard1_item = { keyboard1_value, sizeof(keyboard1_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard1_item); + + return nodeHandle; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputBlurOnSubmitTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputBlurOnSubmitTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputBlurOnSubmitTest", "OnEventReceive eventId: %{public}d", + eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + if (eventId == ON_CHANGE_EVENT_ID) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + } else if (eventId == ON_BLUR_ID) { + 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(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + } +} + +napi_value TextInputBlurOnSubmitTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputBlurOnSubmitTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputBlurOnSubmitTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInputOne = createChildNode(nodeAPI, 1); + auto textInputTwo = createChildNode(nodeAPI, 0); + auto textInputThree = createChildNode(nodeAPI, -1); + + ArkUI_AttributeItem id_item = {}; + id_item.string = "OnSubmitTestTextInput"; + nodeAPI->setAttribute(textInputOne, NODE_ID, &id_item); + id_item.string = "OnSubmitTestTextInputCompare"; + nodeAPI->setAttribute(textInputTwo, NODE_ID, &id_item); + id_item.string = "OnSubmitTestTextInputAbnormal"; + nodeAPI->setAttribute(textInputThree, NODE_ID, &id_item); + + nodeAPI->addChild(column, textInputOne); + nodeAPI->addChild(column, textInputTwo); + nodeAPI->addChild(column, textInputThree); + + nodeAPI->registerNodeEvent(textInputOne, NODE_ON_FOCUS, ON_CHANGE_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInputOne, NODE_ON_BLUR, ON_BLUR_ID, nullptr); + + nodeAPI->registerNodeEvent(textInputTwo, NODE_ON_FOCUS, ON_CHANGE_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInputTwo, NODE_ON_BLUR, ON_BLUR_ID, nullptr); + + nodeAPI->registerNodeEvent(textInputThree, NODE_ON_FOCUS, ON_CHANGE_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInputThree, NODE_ON_BLUR, ON_BLUR_ID, nullptr); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputBlurOnSubmitTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_bluronsubmit_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_bluronsubmit_test.h new file mode 100644 index 0000000000000000000000000000000000000000..9c0dd90f75b144309bb80b556b50a81c878ede09 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_bluronsubmit_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_TEXTINPUT_BLURONSUBMIT_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_BLURONSUBMIT_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputBlurOnSubmitTest { +public: + ~TextInputBlurOnSubmitTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_BLURONSUBMIT_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_cancelbutton_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_cancelbutton_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6390675133543e408cb9a8febf4b63668a1988f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_cancelbutton_test.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "textinput_cancelbutton_test.h" + +#include + +#include "../manager/plugin_manager.h" + +static ArkUI_NodeHandle text; + +namespace ArkUICApiDemo { +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t type, float_t size, uint32_t color) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + // set type + ArkUI_NumberValue type_value[] = { { .i32 = type }, { .f32 = size }, { .u32 = color } }; + ArkUI_AttributeItem type_item = { type_value, sizeof(type_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_CANCEL_BUTTON, &type_item); + + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 300 } }; + 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 = SIZE_50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + return nodeHandle; +} + +napi_value TextInputCancelButtonTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCancelButtonTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCancelButtonTest", "GetContext env or info is null"); + return nullptr; + } + + // parent column + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // set alignment + ArkUI_NumberValue justify_content_value[] = { { .i32 = ARKUI_FLEX_ALIGNMENT_SPACE_AROUND } }; + ArkUI_AttributeItem justify_content_item = { justify_content_value, + sizeof(justify_content_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_COLUMN_JUSTIFY_CONTENT, &justify_content_item); + + // textinput + auto textInput1 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_CONSTANT, 10, COLOR_RED); + auto textInput2 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_CONSTANT, 15, COLOR_GREEN); + auto textInput3 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_INVISIBLE, 10, COLOR_RED); + auto textInput4 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_INVISIBLE, 15, COLOR_GREEN); + auto textInput5 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_INPUT, 10, COLOR_RED); + auto textInput6 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_INPUT, 15, COLOR_GREEN); + auto textInput7 = createChildNode(nodeAPI, -1, 10, COLOR_RED); + auto textInput8 = createChildNode(nodeAPI, -1, 15, COLOR_GREEN); + auto textInput9 = createChildNode(nodeAPI, 3, 10, COLOR_RED); + auto textInput10 = createChildNode(nodeAPI, 3, 15, COLOR_GREEN); + auto textInput11 = createChildNode(nodeAPI, ARKUI_CANCELBUTTON_STYLE_INVISIBLE, 10, COLOR_RED); + // text + ArkUI_AttributeItem text_item = {}; + text_item.string = ""; + ArkUI_AttributeItem text1_item = {}; + text1_item.string = + "dqr3feasdfhwieuhr2iuehfi3h2riuh3riu24hrfui24hfi2u4hfiu24fiu2bfi2ubf4i2ubfi4ubi2u4bi2ubi24ufb2i4ufbif"; + + nodeAPI->resetAttribute(textInput11, NODE_TEXT_INPUT_CANCEL_BUTTON); + + // set text + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput4, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textInput5, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput6, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textInput7, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput8, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textInput9, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput10, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textInput11, NODE_TEXT_INPUT_TEXT, &text_item); + + ArkUI_AttributeItem id_item = {}; + id_item.string = "textInput1"; + nodeAPI->setAttribute(textInput1, NODE_ID, &id_item); + + nodeAPI->addChild(column, text); + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + + // xComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCancelButtonTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_cancelbutton_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_cancelbutton_test.h new file mode 100644 index 0000000000000000000000000000000000000000..d10c64c56e59620e274ec2fa42a7b35f57e536e2 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_cancelbutton_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_CANCELBUTTON_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_CANCELBUTTON_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +using namespace std; + +class TextInputCancelButtonTest { +public: + ~TextInputCancelButtonTest(); + static ArkUI_NodeHandle CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi, int32_t value, const char* src); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_CANCELBUTTON_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_caretposition_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_caretposition_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14fd5e03a4ce90b0fe769b19a0dbbb47e60b7bcb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_caretposition_test.cpp @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_caretposition_test.h" + +#include + +#include "../manager/plugin_manager.h" + +#define ON_CLICK_1 6001 +#define ON_CLICK_2 6002 +#define ON_CLICK_3 6003 + +namespace ArkUICApiDemo { + +static ArkUI_NodeHandle text1; + +static ArkUI_NodeHandle textInput1; + +ArkUI_NodeHandle TextInputCaretPositionTest::CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi) +{ + float width = 300; + float height = 300; + auto textInput = nodeApi->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_HEIGHT, &heightItem); + + ArkUI_AttributeItem content_item = {}; + content_item.string = "TextInput"; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_TEXT, &content_item); + + ArkUI_NumberValue fontSizeValue[] = { { .f32 = 30 } }; + ArkUI_AttributeItem fontSizeItem = { fontSizeValue, sizeof(fontSizeValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_FONT_SIZE, &fontSizeItem); + + ArkUI_NumberValue keyboardEnable_value[] = { { .i32 = 0 } }; + ArkUI_AttributeItem keyboardEnable_item = { keyboardEnable_value, + sizeof(keyboardEnable_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboardEnable_item); + + ArkUI_NumberValue keyboard1_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard1_item = { keyboard1_value, sizeof(keyboard1_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard1_item); + + return textInput; +} + +static auto CreatButton(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandler = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + ArkUI_NumberValue width_value[] = { { .f32 = 300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_HEIGHT, &height_item); + + return nodeHandler; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + if (eventId == 0) { + return; + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + switch (eventId) { + case ON_CLICK_1: { + ArkUI_NumberValue setCaretPosition_value[] = { { .i32 = 3 } }; + ArkUI_AttributeItem setCaretPosition_item = { setCaretPosition_value, + sizeof(setCaretPosition_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET, &setCaretPosition_item); + auto result = nodeAPI->getAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET); + if (result == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", + "Failed to get caret offset attribute"); + return; + } + if (text1 != nullptr) { + std::string str = "index:" + std::to_string(result->value[0].i32); + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + } else { + std::string str = "error"; + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + } + return; + } + case ON_CLICK_2: { + ArkUI_NumberValue setCaretPosition_value[] = { { .i32 = -1 } }; + ArkUI_AttributeItem setCaretPosition_item = { setCaretPosition_value, + sizeof(setCaretPosition_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET, &setCaretPosition_item); + auto result = nodeAPI->getAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET); + if (result == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", + "Failed to get caret offset attribute"); + return; + } + if (text1 != nullptr) { + std::string str = "index:" + std::to_string(result->value[0].i32); + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + } else { + std::string str = "error"; + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + } + return; + } + case ON_CLICK_3: { + ArkUI_NumberValue setCaretPosition_value[] = { { .i32 = 100 } }; + ArkUI_AttributeItem setCaretPosition_item = { setCaretPosition_value, + sizeof(setCaretPosition_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET, &setCaretPosition_item); + auto result = nodeAPI->getAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET); + if (result == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", + "Failed to get caret offset attribute"); + return; + } + if (text1 != nullptr) { + std::string str = "index:" + std::to_string(result->value[0].i32); + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + } else { + std::string str = "error"; + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + } + return; + } + default: { + return; + } + } +} + +napi_value TextInputCaretPositionTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", "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, "TextInputCaretPositionTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + text1 = nodeAPI->createNode(ARKUI_NODE_TEXT); + + ArkUI_AttributeItem content_item = {}; + content_item.string = "TextInputCaretPositionTest"; + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &content_item); + + textInput1 = CreateSubTextInputNode(nodeAPI); + + auto button1 = CreatButton(nodeAPI); + auto button2 = CreatButton(nodeAPI); + auto button3 = CreatButton(nodeAPI); + + ArkUI_AttributeItem id_item1 = {}; + id_item1.string = "TextInputCaretPositionTest_buttonId1"; + nodeAPI->setAttribute(button1, NODE_ID, &id_item1); + + ArkUI_AttributeItem id_item2 = {}; + id_item2.string = "TextInputCaretPositionTest_buttonId2"; + nodeAPI->setAttribute(button2, NODE_ID, &id_item2); + + ArkUI_AttributeItem id_item3 = {}; + id_item3.string = "TextInputCaretPositionTest_buttonId3"; + nodeAPI->setAttribute(button3, NODE_ID, &id_item3); + + ArkUI_AttributeItem id_item4 = {}; + id_item4.string = "textInput1"; + nodeAPI->setAttribute(textInput1, NODE_ID, &id_item4); + + nodeAPI->registerNodeEvent(button1, NODE_ON_CLICK, ON_CLICK_1, nodeAPI); + nodeAPI->registerNodeEvent(button2, NODE_ON_CLICK, ON_CLICK_2, nodeAPI); + nodeAPI->registerNodeEvent(button3, NODE_ON_CLICK, ON_CLICK_3, nodeAPI); + + ArkUI_AttributeItem button_item1 = {}; + button_item1.string = "设置光标位置3"; + nodeAPI->setAttribute(button1, NODE_BUTTON_LABEL, &button_item1); + + ArkUI_AttributeItem button_item2 = {}; + button_item2.string = "设置光标位置-1"; + nodeAPI->setAttribute(button2, NODE_BUTTON_LABEL, &button_item2); + + ArkUI_AttributeItem button_item3 = {}; + button_item3.string = "设置光标位置100"; + nodeAPI->setAttribute(button3, NODE_BUTTON_LABEL, &button_item3); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, text1); + nodeAPI->addChild(column, button1); + nodeAPI->addChild(column, button2); + nodeAPI->addChild(column, button3); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCaretPositionTest", + "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/textinput/textinput_caretposition_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_caretposition_test.h new file mode 100644 index 0000000000000000000000000000000000000000..867a70c470ba01c6d0b843b70aedcacc350a879c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_caretposition_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_CARETPOSITION_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_CARETPOSITION_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputCaretPositionTest { +public: + ~TextInputCaretPositionTest(); + static ArkUI_NodeHandle CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_CARETPOSITION_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_content_type_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_content_type_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38f845102db1356283c0dee4a42ecd3db92f9577 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_content_type_test.cpp @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_content_type_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto setContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_TEXT, &content_item); + return nodeHandle; +} + +static auto setMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto setFontsize(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float fontsize) +{ + ArkUI_NumberValue font_size_value[] = { { .f32 = fontsize } }; + ArkUI_AttributeItem font_size_item = { font_size_value, sizeof(font_size_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &font_size_item); + return nodeHandle; +} + +static auto setEnableAutoFill(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t enable) +{ + ArkUI_NumberValue value[] = { { .i32 = enable } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_ENABLE_AUTO_FILL, &item); + return nodeHandle; +} + +static auto setContentType(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t contentType) +{ + ArkUI_NumberValue value[] = { { .i32 = contentType } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_CONTENT_TYPE, &item); + return nodeHandle; +} + +static auto setTextInput( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t contentType, const char* id) +{ + nodeHandle = setWidth(nodeAPI, nodeHandle, SIZE_400); + nodeHandle = setHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = setId(nodeAPI, nodeHandle, id); + nodeHandle = setMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = setFontsize(nodeAPI, nodeHandle, SIZE_30); + nodeHandle = setEnableAutoFill(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = setContentType(nodeAPI, nodeHandle, contentType); + return nodeHandle; +} + +napi_value TextInputContentTypeTest::CreateNativeNodePage1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputContentTypeTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputContentTypeTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + + textInput1 = setTextInput(nodeAPI, textInput1, ARKUI_TEXTINPUT_CONTENT_TYPE_USER_NAME, "textInput1"); + textInput2 = setTextInput(nodeAPI, textInput2, ARKUI_TEXTINPUT_CONTENT_TYPE_PASSWORD, "textInput2"); + textInput3 = setTextInput(nodeAPI, textInput3, ARKUI_TEXTINPUT_CONTENT_TYPE_NEW_PASSWORD, "textInput3"); + textInput4 = setTextInput(nodeAPI, textInput4, ARKUI_TEXTINPUT_CONTENT_TYPE_FULL_STREET_ADDRESS, "textInput4"); + textInput5 = setTextInput(nodeAPI, textInput5, ARKUI_TEXTINPUT_CONTENT_TYPE_HOUSE_NUMBER, "textInput5"); + textInput6 = setTextInput(nodeAPI, textInput6, ARKUI_TEXTINPUT_CONTENT_TYPE_DISTRICT_ADDRESS, "textInput6"); + textInput7 = setTextInput(nodeAPI, textInput7, ARKUI_TEXTINPUT_CONTENT_TYPE_CITY_ADDRESS, "textInput7"); + textInput8 = setTextInput(nodeAPI, textInput8, ARKUI_TEXTINPUT_CONTENT_TYPE_PROVINCE_ADDRESS, "textInput8"); + textInput9 = setTextInput(nodeAPI, textInput9, ARKUI_TEXTINPUT_CONTENT_TYPE_COUNTRY_ADDRESS, "textInput9"); + textInput10 = setTextInput(nodeAPI, textInput10, ARKUI_TEXTINPUT_CONTENT_TYPE_PERSON_FULL_NAME, "textInput10"); + textInput11 = setTextInput(nodeAPI, textInput11, ARKUI_TEXTINPUT_CONTENT_TYPE_PERSON_LAST_NAME, "textInput11"); + textInput12 = setTextInput(nodeAPI, textInput12, ARKUI_TEXTINPUT_CONTENT_TYPE_PERSON_FIRST_NAME, "textInput12"); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputContentTypeTest", + "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 TextInputContentTypeTest::CreateNativeNodePage2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputContentTypeTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputContentTypeTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + + // 设置属性 + textInput1 = setTextInput(nodeAPI, textInput1, ARKUI_TEXTINPUT_CONTENT_TYPE_PHONE_NUMBER, "textInput1"); + textInput2 = setTextInput(nodeAPI, textInput2, ARKUI_TEXTINPUT_CONTENT_TYPE_PHONE_COUNTRY_CODE, "textInput2"); + textInput3 = setTextInput(nodeAPI, textInput3, ARKUI_TEXTINPUT_CONTENT_TYPE_FULL_PHONE_NUMBER, "textInput3"); + textInput4 = setTextInput(nodeAPI, textInput4, ARKUI_TEXTINPUT_CONTENT_EMAIL_ADDRESS, "textInput4"); + textInput5 = setTextInput(nodeAPI, textInput5, ARKUI_TEXTINPUT_CONTENT_TYPE_BANK_CARD_NUMBER, "textInput5"); + textInput6 = setTextInput(nodeAPI, textInput6, ARKUI_TEXTINPUT_CONTENT_TYPE_ID_CARD_NUMBER, "textInput6"); + textInput7 = setTextInput(nodeAPI, textInput7, ARKUI_TEXTINPUT_CONTENT_TYPE_NICKNAME, "textInput7"); + textInput8 = + setTextInput(nodeAPI, textInput8, ARKUI_TEXTINPUT_CONTENT_TYPE_DETAIL_INFO_WITHOUT_STREET, "textInput8"); + textInput9 = setTextInput(nodeAPI, textInput9, ARKUI_TEXTINPUT_CONTENT_TYPE_FORMAT_ADDRESS, "textInput9"); + textInput10 = setTextInput(nodeAPI, textInput10, SIZE_21, "textInput10"); + textInput11 = setTextInput(nodeAPI, textInput11, PARAM_NEGATIVE_1, "textInput11"); + textInput12 = setTextInput(nodeAPI, textInput12, ARKUI_TEXTINPUT_CONTENT_TYPE_USER_NAME, "textInput12"); + nodeAPI->resetAttribute(textInput12, NODE_TEXT_INPUT_CONTENT_TYPE); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputContentTypeTest", + "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/textinput/textinput_content_type_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_content_type_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b996979d851a1203826e34c9c0fab66bd30f6e71 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_content_type_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_CONTENT_TYPE_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_CONTENT_TYPE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_21 21 + +class TextInputContentTypeTest { +public: + ~TextInputContentTypeTest(); + static napi_value CreateNativeNodePage1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage2(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_CONTENT_TYPE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_controller_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_controller_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..917125cf28569a214a529121412dd102f6a142c9 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_controller_test.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// NODE_TEXT_INPUT_CONTENT_RECT NODE_TEXT_INPUT_CONTENT_LINE_COUNT + +#include "textinput_controller_test.h" + +#include + +#include "../manager/plugin_manager.h" + +#define CONTROLLER_GET_INFORMATION 6017 +#define CONTROLLER_CHANGE_INFORMATION 1 +namespace ArkUICApiDemo { + +static ArkUI_NodeHandle text; +static ArkUI_NodeHandle textInput; +static ArkUI_NodeHandle text1; +static ArkUI_NodeHandle text2; +static ArkUI_NodeHandle text3; + +ArkUI_NodeHandle CreateText(ArkUI_NativeNodeAPI_1* nodeApi) +{ + float width = 300; + float height = 200; + auto text = nodeApi->createNode(ARKUI_NODE_TEXT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_HEIGHT, &heightItem); + + ArkUI_NumberValue margin_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue value[] = { { .f32 = 30 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(text, NODE_FONT_SIZE, &value_item); + return text; +} + +ArkUI_NodeHandle CreateTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi) +{ + float width = 200; + float height = 200; + auto textInput = nodeApi->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_HEIGHT, &heightItem); + + ArkUI_NumberValue style_value[] = { { .i32 = ARKUI_TEXTINPUT_STYLE_INLINE } }; + ArkUI_AttributeItem style_item = { style_value, sizeof(style_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_STYLE, &style_item); + + // set maxlines + ArkUI_NumberValue lines_value[] = { { .i32 = 2 } }; + ArkUI_AttributeItem lines_item = { lines_value, sizeof(lines_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_MAX_LINES, &lines_item); + + ArkUI_AttributeItem content_item = {}; + content_item.string = "TextInput TextInput "; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_TEXT, &content_item); + + ArkUI_NumberValue keyboard_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + + ArkUI_NumberValue keyboard1_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard1_item = { keyboard1_value, sizeof(keyboard1_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard1_item); + + ArkUI_NumberValue value[] = { { .f32 = 30 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_FONT_SIZE, &value_item); + + return textInput; +} + +static auto CreatButton(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandler = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + ArkUI_NumberValue width_value[] = { { .f32 = 300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_HEIGHT, &height_item); + + return nodeHandler; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputControllerTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputControllerTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + if (eventId == 0) { + return; + } + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputControllerTest", "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + switch (eventId) { + case CONTROLLER_GET_INFORMATION: { + auto result2 = nodeAPI->getAttribute(textInput, NODE_TEXT_INPUT_CONTENT_RECT); + if (result2 == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputControllerTest", + "Failed to get caret offset attribute"); + return; + } + std::string str = "horizontal:" + std::to_string(result2->value[0].f32) + " vertiacal" + + std::to_string(result2->value[1].f32) + " width" + std::to_string(result2->value[2].f32) + + " height" + std::to_string(result2->value[3].f32); + ArkUI_AttributeItem setCaretPosition_content_item = {}; + setCaretPosition_content_item.string = str.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &setCaretPosition_content_item); + + auto result3 = nodeAPI->getAttribute(textInput, NODE_TEXT_INPUT_CONTENT_LINE_COUNT); + if (result3 == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputControllerTest", + "Failed to get caret offset attribute"); + return; + } + if (result3 != nullptr) { + str = "line:" + std::to_string(result3->value[0].i32); + ArkUI_AttributeItem line_item = {}; + line_item.string = str.c_str(); + nodeAPI->setAttribute(text2, NODE_TEXT_CONTENT, &line_item); + } + return; + } + case CONTROLLER_CHANGE_INFORMATION: { + ArkUI_AttributeItem line_item = {}; + line_item.string = "TextInput TextInput TextInput TextInput"; + nodeAPI->setAttribute(textInput, NODE_TEXT_INPUT_TEXT, &line_item); + return; + } + default: { + return; + } + } +} + +napi_value TextInputControllerTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputControllerTest", "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, "TextInputControllerTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + auto Input = CreateTextInputNode(nodeAPI); + textInput = Input; + + ArkUI_AttributeItem textInput_id_item = {}; + textInput_id_item.string = "TextInputControllerTest_textInput_id"; + nodeAPI->setAttribute(textInput, NODE_ID, &textInput_id_item); + + auto button_1 = CreatButton(nodeAPI); + auto button_2 = CreatButton(nodeAPI); + + ArkUI_AttributeItem button_1_content_item = {}; + button_1_content_item.string = "获取输入框信息,获取输入框行数"; + nodeAPI->setAttribute(button_1, NODE_BUTTON_LABEL, &button_1_content_item); + + button_1_content_item.string = "多行后变化"; + nodeAPI->setAttribute(button_2, NODE_BUTTON_LABEL, &button_1_content_item); + + nodeAPI->registerNodeEvent(button_1, NODE_ON_CLICK, CONTROLLER_GET_INFORMATION, nodeAPI); + nodeAPI->registerNodeEvent(button_2, NODE_ON_CLICK, CONTROLLER_CHANGE_INFORMATION, nodeAPI); + + ArkUI_AttributeItem id_item_1 = {}; + id_item_1.string = "TextInputControllerTest_button_id"; + nodeAPI->setAttribute(button_1, NODE_ID, &id_item_1); + + id_item_1.string = "TextInputControllerTest_button_id2"; + nodeAPI->setAttribute(button_2, NODE_ID, &id_item_1); + + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + + text1 = CreateText(nodeAPI); + text2 = CreateText(nodeAPI); + + nodeAPI->addChild(column, button_1); + nodeAPI->addChild(column, button_2); + nodeAPI->addChild(column, text1); + nodeAPI->addChild(column, text2); + nodeAPI->addChild(column, textInput); + + nodeAPI->addChild(column, row); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputControllerTest", + "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/textinput/textinput_controller_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_controller_test.h new file mode 100644 index 0000000000000000000000000000000000000000..36545304643df5433556913f7b4f22b918e2bddd --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_controller_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_TEXTINPUT_COMTROLLER_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_COMTROLLER_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputControllerTest { +public: + ~TextInputControllerTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_COMTROLLER_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_custom_keyboard_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_custom_keyboard_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0de7f3277d5637b96941fc3cf7f76decdd4aed3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_custom_keyboard_test.cpp @@ -0,0 +1,662 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput/textinput_custom_keyboard_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +ArkUI_NodeHandle textInputGlobal; + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto setId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto setBackgroundColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &color_item); + return nodeHandle; +} + +static auto setCustomKeyboard( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, ArkUI_NodeHandle keyboard, int options) +{ + ArkUI_NumberValue keyboard_value[] = { { .i32 = options } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + keyboard_item.object = keyboard; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_CUSTOM_KEYBOARD, &keyboard_item); + return nodeHandle; +} + +static auto setOther(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width, float height, char* id) +{ + nodeHandle = setWidth(nodeAPI, nodeHandle, width); + nodeHandle = setHeight(nodeAPI, nodeHandle, height); + nodeHandle = setMargin(nodeAPI, nodeHandle, PARAM_3); + nodeHandle = setId(nodeAPI, nodeHandle, id); + return nodeHandle; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + if (eventId == ON_CLICK_EVENT_ID_ONE) { + 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(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + } + if (eventId == ON_CLICK_EVENT_ID_TWO) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + } + + // 点击推出编辑 + if (eventId == ON_CLICK_EVENT_ID_THREE) { + ArkUI_NumberValue editing_value[] = { { .u32 = PARAM_0 } }; + ArkUI_AttributeItem editing_item = { editing_value, sizeof(editing_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInputGlobal, NODE_TEXT_INPUT_EDITING, &editing_item); + } + + // 点击清除焦点 + if (eventId == ON_CLICK_EVENT_ID_FOUR) { + ArkUI_NumberValue editing_value[] = { { .u32 = PARAM_0 } }; + ArkUI_AttributeItem editing_item = { editing_value, sizeof(editing_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInputGlobal, NODE_FOCUS_STATUS, &editing_item); + } +} + +napi_value TextInputCustomKeyboardTest::CreateNativeNodePage1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "CreateNativeNodePage1"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, button); + nodeAPI->addChild(column, textInput1); + + auto customKeyboard = 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); + auto row4 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto button1 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button2 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button3 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button4 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button5 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button6 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button7 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button8 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button9 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button10 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button11 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + nodeAPI->addChild(customKeyboard, row1); + nodeAPI->addChild(customKeyboard, row2); + nodeAPI->addChild(customKeyboard, row3); + nodeAPI->addChild(customKeyboard, row4); + nodeAPI->addChild(row1, button1); + nodeAPI->addChild(row1, button2); + nodeAPI->addChild(row1, button3); + nodeAPI->addChild(row2, button4); + nodeAPI->addChild(row2, button5); + nodeAPI->addChild(row2, button6); + nodeAPI->addChild(row3, button7); + nodeAPI->addChild(row3, button8); + nodeAPI->addChild(row3, button9); + nodeAPI->addChild(row4, button10); + nodeAPI->addChild(row4, button11); + + // 设置键盘属性 + button1 = setOther(nodeAPI, button1, SIZE_100, SIZE_100, "button1"); + button2 = setOther(nodeAPI, button2, SIZE_100, SIZE_100, "button2"); + button3 = setOther(nodeAPI, button3, SIZE_100, SIZE_100, "button3"); + button4 = setOther(nodeAPI, button4, SIZE_100, SIZE_100, "button4"); + button5 = setOther(nodeAPI, button5, SIZE_100, SIZE_100, "button5"); + button6 = setOther(nodeAPI, button6, SIZE_100, SIZE_100, "button6"); + button7 = setOther(nodeAPI, button7, SIZE_100, SIZE_100, "button7"); + button8 = setOther(nodeAPI, button8, SIZE_100, SIZE_100, "button8"); + button9 = setOther(nodeAPI, button9, SIZE_100, SIZE_100, "button9"); + button10 = setOther(nodeAPI, button10, SIZE_100, SIZE_100, "button10"); + button11 = setOther(nodeAPI, button11, SIZE_100, SIZE_100, "button11"); + + // 设置textInput和button属性 + button = setOther(nodeAPI, button, SIZE_300, SIZE_600, "button"); + button = setBackgroundColor(nodeAPI, button, COLOR_BLUE); + textInput1 = setOther(nodeAPI, textInput1, SIZE_300, SIZE_50, "textInput1"); + textInput1 = setCustomKeyboard(nodeAPI, textInput1, customKeyboard, PARAM_0); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "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 TextInputCustomKeyboardTest::CreateNativeNodePage2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "CreateNativeNodePage2"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, button); + nodeAPI->addChild(column, textInput2); + + // 自定义键盘 + auto customKeyboard = 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); + auto row4 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto button1 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button2 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button3 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button4 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button5 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button6 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button7 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button8 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button9 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button10 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button11 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + nodeAPI->addChild(customKeyboard, row1); + nodeAPI->addChild(customKeyboard, row2); + nodeAPI->addChild(customKeyboard, row3); + nodeAPI->addChild(customKeyboard, row4); + nodeAPI->addChild(row1, button1); + nodeAPI->addChild(row1, button2); + nodeAPI->addChild(row1, button3); + nodeAPI->addChild(row2, button4); + nodeAPI->addChild(row2, button5); + nodeAPI->addChild(row2, button6); + nodeAPI->addChild(row3, button7); + nodeAPI->addChild(row3, button8); + nodeAPI->addChild(row3, button9); + nodeAPI->addChild(row4, button10); + nodeAPI->addChild(row4, button11); + + // 设置键盘属性 + button1 = setOther(nodeAPI, button1, SIZE_100, SIZE_100, "button1"); + button2 = setOther(nodeAPI, button2, SIZE_100, SIZE_100, "button2"); + button3 = setOther(nodeAPI, button3, SIZE_100, SIZE_100, "button3"); + button4 = setOther(nodeAPI, button4, SIZE_100, SIZE_100, "button4"); + button5 = setOther(nodeAPI, button5, SIZE_100, SIZE_100, "button5"); + button6 = setOther(nodeAPI, button6, SIZE_100, SIZE_100, "button6"); + button7 = setOther(nodeAPI, button7, SIZE_100, SIZE_100, "button7"); + button8 = setOther(nodeAPI, button8, SIZE_100, SIZE_100, "button8"); + button9 = setOther(nodeAPI, button9, SIZE_100, SIZE_100, "button9"); + button10 = setOther(nodeAPI, button10, SIZE_100, SIZE_100, "button10"); + button11 = setOther(nodeAPI, button11, SIZE_100, SIZE_100, "button11"); + + // 设置textInput和button属性 + button = setOther(nodeAPI, button, SIZE_300, SIZE_600, "button"); + button = setBackgroundColor(nodeAPI, button, COLOR_BLUE); + textInput2 = setOther(nodeAPI, textInput2, SIZE_300, SIZE_50, "textInput2"); + textInput2 = setCustomKeyboard(nodeAPI, textInput2, customKeyboard, PARAM_1); + + // 注册获取点击事件 + nodeAPI->registerNodeEvent(textInput2, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "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 TextInputCustomKeyboardTest::CreateNativeNodePage3(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "CreateNativeNodePage3"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + nodeAPI->addChild(column, button); + nodeAPI->addChild(column, textInput3); + + // 自定义键盘 + auto customKeyboard = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button1 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + nodeAPI->addChild(customKeyboard, button1); + + // 设置键盘属性 + button1 = setOther(nodeAPI, button1, SIZE_300, SIZE_400, "button1"); + + // 设置textInput和button属性 + button = setOther(nodeAPI, button, SIZE_300, SIZE_600, "button"); + button = setBackgroundColor(nodeAPI, button, COLOR_BLUE); + textInput3 = setOther(nodeAPI, textInput3, SIZE_300, SIZE_50, "textInput3"); + textInput3 = setCustomKeyboard(nodeAPI, textInput3, customKeyboard, PARAM_0); + + // 注册获取点击事件 + nodeAPI->registerNodeEvent(button, NODE_ON_CLICK, ON_CLICK_EVENT_ID_ONE, nullptr); + nodeAPI->registerNodeEvent(button1, NODE_ON_CLICK, ON_CLICK_EVENT_ID_TWO, nullptr); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "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 TextInputCustomKeyboardTest::CreateNativeNodePage4(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "CreateNativeNodePage4"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + textInputGlobal = textInput4; + nodeAPI->addChild(column, button); + nodeAPI->addChild(column, textInput4); + + // 自定义键盘 + auto customKeyboard = 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); + auto row4 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto button1 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button2 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button3 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button4 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button5 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button6 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button7 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button8 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button9 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button10 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button11 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + nodeAPI->addChild(customKeyboard, row1); + nodeAPI->addChild(customKeyboard, row2); + nodeAPI->addChild(customKeyboard, row3); + nodeAPI->addChild(customKeyboard, row4); + nodeAPI->addChild(row1, button1); + nodeAPI->addChild(row1, button2); + nodeAPI->addChild(row1, button3); + nodeAPI->addChild(row2, button4); + nodeAPI->addChild(row2, button5); + nodeAPI->addChild(row2, button6); + nodeAPI->addChild(row3, button7); + nodeAPI->addChild(row3, button8); + nodeAPI->addChild(row3, button9); + nodeAPI->addChild(row4, button10); + nodeAPI->addChild(row4, button11); + + // 设置键盘属性 + button1 = setOther(nodeAPI, button1, SIZE_100, SIZE_30, "button1"); + button2 = setOther(nodeAPI, button2, SIZE_100, SIZE_30, "button2"); + button3 = setOther(nodeAPI, button3, SIZE_100, SIZE_30, "button3"); + button4 = setOther(nodeAPI, button4, SIZE_100, SIZE_30, "button4"); + button5 = setOther(nodeAPI, button5, SIZE_100, SIZE_30, "button5"); + button6 = setOther(nodeAPI, button6, SIZE_100, SIZE_30, "button6"); + button7 = setOther(nodeAPI, button7, SIZE_100, SIZE_30, "button7"); + button8 = setOther(nodeAPI, button8, SIZE_100, SIZE_30, "button8"); + button9 = setOther(nodeAPI, button9, SIZE_100, SIZE_30, "button9"); + button10 = setOther(nodeAPI, button10, SIZE_100, SIZE_30, "button10"); + button11 = setOther(nodeAPI, button11, SIZE_100, SIZE_30, "button11"); + + // 设置textInput和button属性 + button = setOther(nodeAPI, button, SIZE_300, SIZE_300, "button"); + button = setBackgroundColor(nodeAPI, button, COLOR_BLUE); + textInput4 = setOther(nodeAPI, textInput4, SIZE_300, SIZE_50, "textInput4"); + textInput4 = setCustomKeyboard(nodeAPI, textInput4, customKeyboard, PARAM_0); + + // 设置点击按钮失去焦点 + nodeAPI->registerNodeEvent(button, NODE_ON_CLICK, ON_CLICK_EVENT_ID_FOUR, nullptr); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "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 TextInputCustomKeyboardTest::CreateNativeNodePage5(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "CreateNativeNodePage5"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + textInputGlobal = textInput5; + nodeAPI->addChild(column, button); + nodeAPI->addChild(column, textInput5); + + // 自定义键盘 + auto customKeyboard = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button1 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + nodeAPI->addChild(customKeyboard, button1); + + // 设置键盘属性 + button1 = setOther(nodeAPI, button1, SIZE_300, SIZE_400, "button1"); + + // 设置textInput和button属性 + button = setOther(nodeAPI, button, SIZE_300, SIZE_600, "button"); + button = setBackgroundColor(nodeAPI, button, COLOR_BLUE); + textInput5 = setOther(nodeAPI, textInput5, SIZE_300, SIZE_50, "textInput5"); + textInput5 = setCustomKeyboard(nodeAPI, textInput5, customKeyboard, PARAM_0); + + // 注册获取点击事件 + nodeAPI->registerNodeEvent(button1, NODE_ON_CLICK, ON_CLICK_EVENT_ID_THREE, nullptr); + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "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 TextInputCustomKeyboardTest::CreateNativeNodePage6(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "CreateNativeNodePage6"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, button); + nodeAPI->addChild(column, textInput6); + + // 自定义键盘 + auto customKeyboard = 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); + auto row4 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto button1 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button2 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button3 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button4 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button5 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button6 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button7 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button8 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button9 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button10 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + auto button11 = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + nodeAPI->addChild(customKeyboard, row1); + nodeAPI->addChild(customKeyboard, row2); + nodeAPI->addChild(customKeyboard, row3); + nodeAPI->addChild(customKeyboard, row4); + nodeAPI->addChild(row1, button1); + nodeAPI->addChild(row1, button2); + nodeAPI->addChild(row1, button3); + nodeAPI->addChild(row2, button4); + nodeAPI->addChild(row2, button5); + nodeAPI->addChild(row2, button6); + nodeAPI->addChild(row3, button7); + nodeAPI->addChild(row3, button8); + nodeAPI->addChild(row3, button9); + nodeAPI->addChild(row4, button10); + nodeAPI->addChild(row4, button11); + + // 设置键盘属性 + button1 = setOther(nodeAPI, button1, SIZE_100, SIZE_100, "button1"); + button2 = setOther(nodeAPI, button2, SIZE_100, SIZE_100, "button2"); + button3 = setOther(nodeAPI, button3, SIZE_100, SIZE_100, "button3"); + button4 = setOther(nodeAPI, button4, SIZE_100, SIZE_100, "button4"); + button5 = setOther(nodeAPI, button5, SIZE_100, SIZE_100, "button5"); + button6 = setOther(nodeAPI, button6, SIZE_100, SIZE_100, "button6"); + button7 = setOther(nodeAPI, button7, SIZE_100, SIZE_100, "button7"); + button8 = setOther(nodeAPI, button8, SIZE_100, SIZE_100, "button8"); + button9 = setOther(nodeAPI, button9, SIZE_100, SIZE_100, "button9"); + button10 = setOther(nodeAPI, button10, SIZE_100, SIZE_100, "button10"); + button11 = setOther(nodeAPI, button11, SIZE_100, SIZE_100, "button11"); + + // 设置textInput和button属性 + button = setOther(nodeAPI, button, SIZE_300, SIZE_600, "button"); + button = setBackgroundColor(nodeAPI, button, COLOR_BLUE); + textInput6 = setOther(nodeAPI, textInput6, SIZE_300, SIZE_50, "textInput6"); + textInput6 = setCustomKeyboard(nodeAPI, textInput6, customKeyboard, PARAM_1); + nodeAPI->resetAttribute(textInput6, NODE_TEXT_INPUT_CUSTOM_KEYBOARD); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputCustomKeyboardTest", + "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/textinput/textinput_custom_keyboard_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_custom_keyboard_test.h new file mode 100644 index 0000000000000000000000000000000000000000..f14a7b29af9825b0ef5436fccbaddb067a0a6ff4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_custom_keyboard_test.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_TEXTINPUT_CUSTOM_KEYBOARD_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_CUSTOM_KEYBOARD_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define SIZE_700 700 +#define ON_CLICK_EVENT_ID_ONE 6014 +#define ON_CLICK_EVENT_ID_TWO 6015 +#define ON_CLICK_EVENT_ID_THREE 6016 +#define ON_CLICK_EVENT_ID_FOUR 6017 + +class TextInputCustomKeyboardTest { +public: + ~TextInputCustomKeyboardTest(); + static napi_value CreateNativeNodePage1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage2(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage3(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage4(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage5(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage6(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_CUSTOM_KEYBOARD_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_enable_auto_fill_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_enable_auto_fill_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c17708f19de3b13202dd312317aee56dd1fd502 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_enable_auto_fill_test.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "textinput_enable_auto_fill_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto setContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_TEXT, &content_item); + return nodeHandle; +} + +static auto setMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto setFontsize(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float fontsize) +{ + ArkUI_NumberValue font_size_value[] = { { .f32 = fontsize } }; + ArkUI_AttributeItem font_size_item = { font_size_value, sizeof(font_size_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &font_size_item); + return nodeHandle; +} + +static auto setContentType(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t contentType) +{ + ArkUI_NumberValue value[] = { { .i32 = contentType } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_CONTENT_TYPE, &item); + return nodeHandle; +} + +static auto setEnableAutoFill(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t enable) +{ + ArkUI_NumberValue value[] = { { .i32 = enable } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_ENABLE_AUTO_FILL, &item); + return nodeHandle; +} + +static auto setTextInput(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t enable, const char* id) +{ + nodeHandle = setWidth(nodeAPI, nodeHandle, SIZE_400); + nodeHandle = setHeight(nodeAPI, nodeHandle, SIZE_100); + nodeHandle = setId(nodeAPI, nodeHandle, id); + nodeHandle = setMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = setContent(nodeAPI, nodeHandle, "pass"); + nodeHandle = setFontsize(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = setEnableAutoFill(nodeAPI, nodeHandle, enable); + nodeHandle = setContentType(nodeAPI, nodeHandle, ARKUI_TEXTINPUT_CONTENT_TYPE_PASSWORD); + return nodeHandle; +} + +napi_value TextInputEnableAutoFillTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputEnableAutoFillTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputEnableAutoFillTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + + textInput1 = setTextInput(nodeAPI, textInput1, PARAM_1, "textInput1"); + textInput2 = setTextInput(nodeAPI, textInput2, PARAM_0, "textInput2"); + textInput3 = setTextInput(nodeAPI, textInput3, PARAM_2, "textInput3"); + textInput4 = setTextInput(nodeAPI, textInput4, PARAM_NEGATIVE_1, "textInput4"); + textInput5 = setTextInput(nodeAPI, textInput5, PARAM_1, "textInput5"); + nodeAPI->resetAttribute(textInput5, NODE_TEXT_INPUT_ENABLE_AUTO_FILL); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputEnableAutoFillTest", + "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/textinput/textinput_enable_auto_fill_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_enable_auto_fill_test.h new file mode 100644 index 0000000000000000000000000000000000000000..ec0555e12b12dce42f71c01e09b432b4b38a18ac --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_enable_auto_fill_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_TEXTINPUT_ENABLE_AUTO_FILL_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_ENABLE_AUTO_FILL_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputEnableAutoFillTest { +public: + ~TextInputEnableAutoFillTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_ENABLE_AUTO_FILL_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_fontfeature_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_fontfeature_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2207eab3da0a06eae18b9e0966e07e48913913aa --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_fontfeature_test.cpp @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_fontfeature_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_TEXT, &content_item); + return nodeHandle; +} + +static auto setFontsize(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float fontsize) +{ + ArkUI_NumberValue font_size_value[] = { { .f32 = fontsize } }; + ArkUI_AttributeItem font_size_item = { font_size_value, sizeof(font_size_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &font_size_item); + return nodeHandle; +} + +static auto setFontFeature(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* fontfeature) +{ + ArkUI_AttributeItem font_feature_item = {}; + font_feature_item.string = fontfeature; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_FEATURE, &font_feature_item); + return nodeHandle; +} + +static auto setNodeHandle( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content, float fontsize, char* fontfeature) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = PARAM_1 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + nodeHandle = setContent(nodeAPI, nodeHandle, content); + nodeHandle = setFontsize(nodeAPI, nodeHandle, fontsize); + nodeHandle = setFontFeature(nodeAPI, nodeHandle, fontfeature); + return nodeHandle; +} + +napi_value TextInputFontFeatureTest::CreateNativeNodePage1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", "CreateNativeNodePage1"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput13 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput14 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput15 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput16 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput17 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput18 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + nodeAPI->addChild(column, textInput13); + nodeAPI->addChild(column, textInput14); + nodeAPI->addChild(column, textInput15); + nodeAPI->addChild(column, textInput16); + nodeAPI->addChild(column, textInput17); + nodeAPI->addChild(column, textInput18); + + // 设置属性 + textInput1 = setNodeHandle(nodeAPI, textInput1, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss01\" on"); + textInput2 = setNodeHandle(nodeAPI, textInput2, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss01\" 1"); + textInput3 = setNodeHandle(nodeAPI, textInput3, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss01\" "); + textInput4 = setNodeHandle(nodeAPI, textInput4, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss01\" off"); + textInput5 = setNodeHandle(nodeAPI, textInput5, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss01\" 0"); + textInput6 = setNodeHandle(nodeAPI, textInput6, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss02\" on"); + textInput7 = setNodeHandle(nodeAPI, textInput7, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss02\" 1"); + textInput8 = setNodeHandle(nodeAPI, textInput8, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss02\" "); + textInput9 = setNodeHandle(nodeAPI, textInput9, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss02\" off"); + textInput10 = setNodeHandle(nodeAPI, textInput10, "0123456789,;/\\-‱%℃℉", PARAM_16, "\"ss02\" 0"); + textInput11 = setNodeHandle(nodeAPI, textInput11, ":+-×÷=≠><≥≤±≈~﹁", PARAM_16, "\"ss03\" on"); + textInput12 = setNodeHandle(nodeAPI, textInput12, ":+-×÷=≠><≥≤±≈~﹁", PARAM_16, "\"ss03\" off"); + textInput13 = setNodeHandle(nodeAPI, textInput13, "llllllllll", PARAM_16, "\"ss04\" on"); + textInput14 = setNodeHandle(nodeAPI, textInput14, "llllllllll", PARAM_16, "\"ss04\" off"); + textInput15 = setNodeHandle(nodeAPI, textInput15, "€¢|¦№¤$₫₣₤₱£₦₨₩₪₱₮₡¥₥₭₰+-×", PARAM_16, "\"ss05\" on"); + textInput16 = setNodeHandle(nodeAPI, textInput16, "€¢|¦№¤$₫₣₤₱£₦₨₩₪₱₮₡¥₥₭₰+-×", PARAM_16, "\"ss05\" off"); + textInput17 = setNodeHandle(nodeAPI, textInput17, "÷=≠<>≤≥±≈~∟^∞∧∨∩∪∫Ω△∏∑√‰μδ|", PARAM_16, "\"ss05\" on"); + textInput18 = setNodeHandle(nodeAPI, textInput18, "÷=≠<>≤≥±≈~∟^∞∧∨∩∪∫Ω△∏∑√‰μδ|", PARAM_16, "\"ss05\" off"); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", + "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 TextInputFontFeatureTest::CreateNativeNodePage2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", "CreateNativeNodePage2"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput13 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput14 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput15 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput16 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput17 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput18 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + nodeAPI->addChild(column, textInput13); + nodeAPI->addChild(column, textInput14); + nodeAPI->addChild(column, textInput15); + nodeAPI->addChild(column, textInput16); + nodeAPI->addChild(column, textInput17); + nodeAPI->addChild(column, textInput18); + + // 设置属性 + textInput1 = setNodeHandle( + nodeAPI, textInput1, "{〈《「『【(〔、。!,:;?}〉》」』】〕〗)〕", PARAM_16, "\"ss08\" on"); + textInput2 = setNodeHandle( + nodeAPI, textInput2, "{〈《「『【(〔、。!,:;?}〉》」』】〕〗)〕", PARAM_16, "\"ss08\" off"); + textInput3 = setNodeHandle(nodeAPI, textInput3, "0123456789", PARAM_16, "\"ss09\" on"); + textInput4 = setNodeHandle(nodeAPI, textInput4, "0123456789", PARAM_16, "\"ss09\" off"); + textInput5 = setNodeHandle(nodeAPI, textInput5, "0123456789", PARAM_16, "\"ss010\" on"); + textInput6 = setNodeHandle(nodeAPI, textInput6, "0123456789", PARAM_16, "\"ss010\" off"); + textInput7 = setNodeHandle(nodeAPI, textInput7, "1/2 1/4 2/45", PARAM_16, "\"frac\" on"); + textInput8 = setNodeHandle(nodeAPI, textInput8, "1/2 1/4 2/45", PARAM_16, "\"frac\" off"); + textInput9 = setNodeHandle(nodeAPI, textInput9, "0123456789", PARAM_16, "\"sups\" on"); + textInput10 = setNodeHandle(nodeAPI, textInput10, "0123456789", PARAM_16, "\"sups\" off"); + textInput11 = setNodeHandle(nodeAPI, textInput11, "0123456789", PARAM_16, "\"subs\" on"); + textInput12 = setNodeHandle(nodeAPI, textInput12, "0123456789", PARAM_16, "\"subs\" off"); + textInput13 = setNodeHandle(nodeAPI, textInput13, "0123456789", PARAM_16, "\"numr\" on"); + textInput14 = setNodeHandle(nodeAPI, textInput14, "0123456789", PARAM_16, "\"numr\" off"); + textInput15 = setNodeHandle(nodeAPI, textInput15, "0123456789", PARAM_16, "\"dnom\" on"); + textInput16 = setNodeHandle(nodeAPI, textInput16, "0123456789", PARAM_16, "\"dnom\" off"); + textInput17 = setNodeHandle(nodeAPI, textInput17, "!¡?¿", PARAM_16, "\"case\" on"); + textInput18 = setNodeHandle(nodeAPI, textInput18, "!¡?¿", PARAM_16, "\"case\" off"); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", + "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 TextInputFontFeatureTest::CreateNativeNodePage3(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", "CreateNativeNodePage3"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput13 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput14 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput15 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput16 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + nodeAPI->addChild(column, textInput13); + nodeAPI->addChild(column, textInput14); + nodeAPI->addChild(column, textInput15); + nodeAPI->addChild(column, textInput16); + + // 设置属性 + textInput1 = setNodeHandle(nodeAPI, textInput1, "0123456789", PARAM_16, "\"tnum\" on"); + textInput2 = setNodeHandle(nodeAPI, textInput2, "0123456789", PARAM_16, "\"tnum\" off"); + textInput3 = setNodeHandle(nodeAPI, textInput3, "0123456789", PARAM_16, "\"pnum\" on"); + textInput4 = setNodeHandle(nodeAPI, textInput4, "0123456789", PARAM_16, "\"pnum\" off"); + textInput5 = setNodeHandle(nodeAPI, textInput5, "【】()", PARAM_16, "\"vert\" on"); + textInput6 = setNodeHandle(nodeAPI, textInput6, "【】()", PARAM_16, "\"vert\" off"); + textInput7 = setNodeHandle(nodeAPI, textInput7, "【】()", PARAM_16, "\"vrt2\" on"); + textInput8 = setNodeHandle(nodeAPI, textInput8, "【】()", PARAM_16, "\"vrt2\" off"); + textInput9 = setNodeHandle(nodeAPI, textInput9, "ff fl fi ffi ffl", PARAM_16, "\"liga\" on"); + textInput10 = setNodeHandle(nodeAPI, textInput10, "ff fl fi ffi ffl", PARAM_16, "\"liga\" off"); + textInput11 = setNodeHandle(nodeAPI, textInput11, "No.1 1a 1o", PARAM_16, "\"ordn\" on"); + textInput12 = setNodeHandle(nodeAPI, textInput12, "No.1 1a 1o", PARAM_16, "\"ordn\" off"); + textInput13 = setNodeHandle(nodeAPI, textInput13, "0123456789", PARAM_16, "\"sinf\" on"); + textInput14 = setNodeHandle(nodeAPI, textInput14, "0123456789", PARAM_16, "\"sinf\" off"); + textInput15 = setNodeHandle(nodeAPI, textInput15, "0123456789", PARAM_16, "\"sinf\" on"); + textInput16 = setNodeHandle(nodeAPI, textInput16, "0123456789", PARAM_16, "\"sinf\" on"); + nodeAPI->resetAttribute(textInput16, NODE_FONT_FEATURE); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputFontFeatureTest", + "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/textinput/textinput_fontfeature_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_fontfeature_test.h new file mode 100644 index 0000000000000000000000000000000000000000..d2ff85a57d0d9581113f85798f1b0887ff4e9079 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_fontfeature_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_TEXTINPUT_FONTFEATURE_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_FONTFEATURE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +#define PARAM_16 16 + +class TextInputFontFeatureTest { +public: + ~TextInputFontFeatureTest(); + static napi_value CreateNativeNodePage1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage2(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage3(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_FONTFEATURE_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_getcaretoffset_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_getcaretoffset_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1eb9501a685c9a6d88ff60bd5cb25fbee000f572 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_getcaretoffset_test.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "textinput_getcaretoffset_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static ArkUI_NodeHandle text1; +static ArkUI_NodeHandle textInput1; + +ArkUI_NodeHandle TextInputGetCaretOffsetTest::CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi) +{ + float width = 300; + float height = 200; + auto textInput = nodeApi->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_HEIGHT, &heightItem); + + ArkUI_AttributeItem content_item = {}; + content_item.string = "textInput"; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_TEXT, &content_item); + + ArkUI_NumberValue value[] = { { .f32 = 45 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_FONT_SIZE, &value_item); + + ArkUI_NumberValue keyboardEnable_value[] = { { .i32 = 1 } }; + ArkUI_AttributeItem keyboardEnable_item = { keyboardEnable_value, + sizeof(keyboardEnable_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboardEnable_item); + + return textInput; +} +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputGetCaretOffsetTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputGetCaretOffsetTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + if (eventId == 0) { + return; + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputGetCaretOffsetTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + if (eventId == ON_CHANGE_EVENT_ID) { + auto result1 = nodeAPI->getAttribute(textInput1, NODE_TEXT_INPUT_CARET_OFFSET); + if (result1 == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputControllerTest", + "Failed to get caret offset attribute"); + return; + } + std::string str1 = "get CARET_POSITION\nindex:" + std::to_string(result1->value[0].i32); + + ArkUI_AttributeItem getTextContentLineCount_item = {}; + getTextContentLineCount_item.string = str1.c_str(); + nodeAPI->setAttribute(text1, NODE_TEXT_CONTENT, &getTextContentLineCount_item); + + return; + } +} + +napi_value TextInputGetCaretOffsetTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputGetCaretOffsetTest", "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, "TextInputGetCaretOffsetTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + text1 = nodeAPI->createNode(ARKUI_NODE_TEXT); + + ArkUI_NumberValue value[] = { { .f32 = 40 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text1, NODE_FONT_SIZE, &value_item); + + textInput1 = CreateSubTextInputNode(nodeAPI); + + ArkUI_AttributeItem id_item1 = {}; + id_item1.string = "TextInputGetCaretOffsetTest_textInput_id1"; + nodeAPI->setAttribute(textInput1, NODE_ID, &id_item1); + + nodeAPI->registerNodeEvent(textInput1, NODE_TEXT_INPUT_ON_CHANGE, ON_CHANGE_EVENT_ID, nodeAPI); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, text1); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputGetCaretOffsetTest", + "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/textinput/textinput_getcaretoffset_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_getcaretoffset_test.h new file mode 100644 index 0000000000000000000000000000000000000000..d98403aa7aaee37c9c5d76527c96c681c0c20202 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_getcaretoffset_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_GETCARETOFFSET_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_GETCARETOFFSET_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputGetCaretOffsetTest { +public: + ~TextInputGetCaretOffsetTest(); + static ArkUI_NodeHandle CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_GETCARETOFFSET_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_inputfilter_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_inputfilter_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b0eab2fd98b713aee484b485e93ada327ac09df --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_inputfilter_test.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE 2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_inputfilter_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static ArkUI_NodeHandle textInput; +static ArkUI_NodeHandle column; +static ArkUI_NativeNodeAPI_1* nodeAPI; + +static auto CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeAPI, const char* str) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 350 } }; + 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 = 200 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + 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); + + ArkUI_NumberValue value[] = { { .f32 = 30 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &value_item); + + // set str + ArkUI_AttributeItem textinputItem = {}; + textinputItem.string = str; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_INPUT_FILTER, &textinputItem); + + nodeAPI->registerNodeEvent(nodeHandle, NODE_TEXT_INPUT_ON_INPUT_FILTER_ERROR, ON_CHANGE_EVENT_ID, nullptr); + + return nodeHandle; +} + +static void EventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonEventOnClickTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CommonEventOnClickTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "CommonEventOnClickTest", "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event); + + if (eventId == ON_CHANGE_EVENT_ID) { + ArkUI_NumberValue background_color_value[] = { { .u32 = COLOR_GREEN } }; + ArkUI_AttributeItem background_color_item = { background_color_value, + sizeof(background_color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_BACKGROUND_COLOR, &background_color_item); + return; + } +} + +napi_value TextInputInputFilterTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputInputFilterTest", "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, "TextInputInputFilterTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 创建容器组件 + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + const char* srcLocal1 = "[\u4e00-\u9fa5a-yA-Z1-9{}()(^&*;;“”\'\"+_——]|(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-" + "9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))"; + + auto textInput = CreateSubTextInputNode(nodeAPI, srcLocal1); + auto textInput2 = CreateSubTextInputNode(nodeAPI, nullptr); + auto textInput3 = CreateSubTextInputNode(nodeAPI, srcLocal1); + + nodeAPI->resetAttribute(textInput3, NODE_TEXT_INPUT_INPUT_FILTER); + + ArkUI_AttributeItem item = {}; + item.string = "@#$%^&*';\'()123456789zZABCDEFGHIJKLMN-1-9-80,-4.9,4.9"; + nodeAPI->setAttribute(textInput, NODE_TEXT_INPUT_TEXT, &item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_TEXT, &item); + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_TEXT, &item); + + nodeAPI->addChild(column, textInput); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + + nodeAPI->registerNodeEventReceiver(&EventReceive); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputInputFilterTest", + "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/textinput/textinput_inputfilter_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_inputfilter_test.h new file mode 100644 index 0000000000000000000000000000000000000000..256a5f68aea6bb5fee0799d7c9636394a3494219 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_inputfilter_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_TEXTINPUT_INPUTFILTER_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_INPUTFILTER_TEST_H + +#include +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputInputFilterTest { +public: + ~TextInputInputFilterTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_INPUTFILTER_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_maxlines_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_maxlines_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d386de7dd81b98fa787796ae08a4edc8849cfeb1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_maxlines_test.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_maxlines_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t value, const char* id) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + // 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 = 100 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + // set style + ArkUI_NumberValue style_value[] = { { .i32 = ARKUI_TEXTINPUT_STYLE_INLINE } }; + ArkUI_AttributeItem style_item = { style_value, sizeof(style_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_STYLE, &style_item); + + // set maxlines + ArkUI_NumberValue lines_value[] = { { .i32 = value } }; + ArkUI_AttributeItem lines_item = { lines_value, sizeof(lines_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_MAX_LINES, &lines_item); + + ArkUI_NumberValue Border_Value_1[] = { { .f32 = 1 } }; + ArkUI_AttributeItem Border_Item_1 = { Border_Value_1, sizeof(Border_Value_1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &Border_Item_1); + + ArkUI_NumberValue marginValue[] = { { .f32 = 5 } }; + ArkUI_AttributeItem marginItem = { marginValue, sizeof(marginValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &marginItem); + + // set id + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + + return nodeHandle; +} + +napi_value TextInputMaxLinesTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputMaxLinesTest", "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, "TextInputMaxLinesTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // column + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // create textinput + auto textinput1 = CreateSubTextInputNode(nodeAPI, 1, "normal"); + auto textinput2 = CreateSubTextInputNode(nodeAPI, -1, "negative"); + auto textinput3 = CreateSubTextInputNode(nodeAPI, 100, "large"); + auto textinput4 = CreateSubTextInputNode(nodeAPI, 1, "normalTwo"); + auto textinput5 = CreateSubTextInputNode(nodeAPI, -1, "negativeTwo"); + auto textinput6 = CreateSubTextInputNode(nodeAPI, 100, "largeTwo"); + auto textinput7 = CreateSubTextInputNode(nodeAPI, 100, "reset"); + + nodeAPI->resetAttribute(textinput7, NODE_TEXT_MAX_LINES); + + // text into column + nodeAPI->addChild(column, textinput1); + nodeAPI->addChild(column, textinput2); + nodeAPI->addChild(column, textinput3); + nodeAPI->addChild(column, textinput4); + nodeAPI->addChild(column, textinput5); + nodeAPI->addChild(column, textinput6); + nodeAPI->addChild(column, textinput7); + + // set text + ArkUI_AttributeItem text_item = {}; + text_item.string = "This is the text with the maxlines set This is the text with the maxlines set " + "This is the text with the maxlines set This is the text with the max set " + "This is the text with the maxlines set"; + nodeAPI->setAttribute(textinput1, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textinput2, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textinput3, NODE_TEXT_INPUT_TEXT, &text_item); + nodeAPI->setAttribute(textinput4, NODE_TEXT_INPUT_PLACEHOLDER, &text_item); + nodeAPI->setAttribute(textinput5, NODE_TEXT_INPUT_PLACEHOLDER, &text_item); + nodeAPI->setAttribute(textinput6, NODE_TEXT_INPUT_PLACEHOLDER, &text_item); + nodeAPI->setAttribute(textinput7, NODE_TEXT_INPUT_TEXT, &text_item); + + // XComponent + std::string id(xComponentID); + + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputMaxLinesTest", + "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/textinput/textinput_maxlines_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_maxlines_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b4cd0987a65da4d41d0bea1aeda2540f1fe61ade --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_maxlines_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_TEXT_INPUT_MAXLINES_TEST_H +#define ARKUI_CAPI_DEMO_TEXT_INPUT_MAXLINES_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputMaxLinesTest { +public: + ~TextInputMaxLinesTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXT_INPUT_MAXLINES_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_minfontsizeandmaxfontsize.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_minfontsizeandmaxfontsize.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79dda24c88534a61dc631d678a1e6ecd878b0c2c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_minfontsizeandmaxfontsize.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_minfontsizeandmaxfontsize.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +napi_value TextInputMinFontSizeAndMaxFontSizeTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputMinFontSizeAndMaxFontSizeTest", "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, "TextInputMinFontSizeAndMaxFontSizeTest", + "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // 创建column节点组件 + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // 设置column组件宽度和高度 + ArkUI_NumberValue column_width_value[] = { { .f32 = 300 } }; + ArkUI_AttributeItem column_width_item = { column_width_value, + sizeof(column_width_value) / sizeof(ArkUI_NumberValue) }; + ArkUI_NumberValue column_height_value[] = { { .f32 = 350 } }; + ArkUI_AttributeItem column_height_item = { column_height_value, + sizeof(column_height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(column, NODE_WIDTH, &column_width_item); + nodeAPI->setAttribute(column, NODE_HEIGHT, &column_height_item); + + // 创建text节点组件 + auto text1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto text2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto text3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto text4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto text5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto text6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + // 设置text组件宽度和高度 + ArkUI_NumberValue width_value[] = { { .f32 = 150 } }; + 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) }; + nodeAPI->setAttribute(text1, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(text2, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(text3, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(text4, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(text5, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(text6, NODE_HEIGHT, &height_item); + nodeAPI->setAttribute(text1, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(text2, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(text3, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(text4, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(text5, NODE_WIDTH, &width_item); + nodeAPI->setAttribute(text6, NODE_WIDTH, &width_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text1, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(text2, NODE_MARGIN, &margin_item); + // text组件放置父容器column中 + nodeAPI->setAttribute(text3, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(text4, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(text5, NODE_MARGIN, &margin_item); + nodeAPI->setAttribute(text6, NODE_MARGIN, &margin_item); + + // text组件放置父容器column中 + nodeAPI->addChild(column, text1); + nodeAPI->addChild(column, text2); + nodeAPI->addChild(column, text3); + nodeAPI->addChild(column, text4); + nodeAPI->addChild(column, text5); + nodeAPI->addChild(column, text6); + + // 设置text组件文本 + ArkUI_AttributeItem content_item = {}; + content_item.string = "Min"; + nodeAPI->setAttribute(text1, NODE_TEXT_INPUT_TEXT, &content_item); + nodeAPI->setAttribute(text2, NODE_TEXT_INPUT_TEXT, &content_item); + nodeAPI->setAttribute(text3, NODE_TEXT_INPUT_TEXT, &content_item); + + content_item.string = "Max"; + nodeAPI->setAttribute(text4, NODE_TEXT_INPUT_TEXT, &content_item); + nodeAPI->setAttribute(text5, NODE_TEXT_INPUT_TEXT, &content_item); + nodeAPI->setAttribute(text6, NODE_TEXT_INPUT_TEXT, &content_item); + + // 设置字体大小 + ArkUI_NumberValue font_size_valueOne[] = { { .f32 = 10 } }; + ArkUI_AttributeItem font_size_valueOne_item = { font_size_valueOne, + sizeof(font_size_valueOne) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text1, NODE_FONT_SIZE, &font_size_valueOne_item); + nodeAPI->setAttribute(text2, NODE_FONT_SIZE, &font_size_valueOne_item); + nodeAPI->setAttribute(text3, NODE_FONT_SIZE, &font_size_valueOne_item); + + ArkUI_NumberValue font_size_valueTwo[] = { { .f32 = 20 } }; + ArkUI_AttributeItem font_size_valueTwo_item = { font_size_valueTwo, + sizeof(font_size_valueTwo) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text4, NODE_FONT_SIZE, &font_size_valueTwo_item); + nodeAPI->setAttribute(text5, NODE_FONT_SIZE, &font_size_valueTwo_item); + nodeAPI->setAttribute(text6, NODE_FONT_SIZE, &font_size_valueTwo_item); + + // 设置text组件文本最小显示字号 + ArkUI_NumberValue minFontSize_valueOne[] = { { .f32 = 20 } }; + ArkUI_AttributeItem minFontSize_valueOne_item = { minFontSize_valueOne, + sizeof(minFontSize_valueOne) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text1, NODE_TEXT_MIN_FONT_SIZE, &minFontSize_valueOne_item); + nodeAPI->setAttribute(text2, NODE_TEXT_MIN_FONT_SIZE, &minFontSize_valueOne_item); + + ArkUI_NumberValue maxFontSize_valueTwo[] = { { .f32 = 10 } }; + ArkUI_AttributeItem maxFontSize_valueTwo_item = { maxFontSize_valueTwo, + sizeof(maxFontSize_valueTwo) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text4, NODE_TEXT_MAX_FONT_SIZE, &maxFontSize_valueTwo_item); + nodeAPI->setAttribute(text5, NODE_TEXT_MAX_FONT_SIZE, &maxFontSize_valueTwo_item); + + // 设置text组件文本最多行数 + ArkUI_NumberValue lines_valueOne[] = { { .i32 = 1 } }; + ArkUI_AttributeItem lines_value_valueOne_item = { lines_valueOne, + sizeof(lines_valueOne) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text1, NODE_TEXT_MAX_LINES, &lines_value_valueOne_item); + nodeAPI->setAttribute(text3, NODE_TEXT_MAX_LINES, &lines_value_valueOne_item); + + ArkUI_NumberValue lines_valueTwo[] = { { .i32 = 1 } }; + ArkUI_AttributeItem lines_value_valueTwo_item = { lines_valueTwo, + sizeof(lines_valueTwo) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text4, NODE_TEXT_MAX_LINES, &lines_value_valueTwo_item); + nodeAPI->setAttribute(text6, NODE_TEXT_MAX_LINES, &lines_value_valueTwo_item); + + // 设置text组件文本最大显示字号 + ArkUI_NumberValue maxFontSize_valueOne[] = { { .f32 = 40 } }; + ArkUI_AttributeItem maxFontSize_valueOne_item = { maxFontSize_valueOne, + sizeof(maxFontSize_valueOne) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text1, NODE_TEXT_MAX_FONT_SIZE, &maxFontSize_valueOne_item); + nodeAPI->setAttribute(text3, NODE_TEXT_MAX_FONT_SIZE, &maxFontSize_valueOne_item); + + ArkUI_NumberValue minFontSize_valueTwo[] = { { .f32 = 5 } }; + ArkUI_AttributeItem minFontSize_valueTwo_item = { minFontSize_valueTwo, + sizeof(minFontSize_valueTwo) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text4, NODE_TEXT_MIN_FONT_SIZE, &minFontSize_valueTwo_item); + nodeAPI->setAttribute(text6, NODE_TEXT_MIN_FONT_SIZE, &minFontSize_valueTwo_item); + + ArkUI_NumberValue exception_valueOne[] = { { .f32 = 0 } }; + ArkUI_AttributeItem exception_value_valueOne_item = { exception_valueOne, + sizeof(exception_valueOne) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text3, NODE_TEXT_MIN_FONT_SIZE, &exception_value_valueOne_item); + + ArkUI_NumberValue exception_valueTwo[] = { { .f32 = -1 } }; + ArkUI_AttributeItem exception_value_valueTwo_item = { exception_valueTwo, + sizeof(exception_valueTwo) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(text6, NODE_TEXT_MAX_FONT_SIZE, &exception_value_valueTwo_item); + + // 所有组件挂载到XComponent + std::string id(xComponentID); + + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputMinFontSizeAndMaxFontSizeTest", + "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/textinput/textinput_minfontsizeandmaxfontsize.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_minfontsizeandmaxfontsize.h new file mode 100644 index 0000000000000000000000000000000000000000..785f64d5d84fb542d54314974d7860dd9fa9105a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_minfontsizeandmaxfontsize.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_TEXTINPUT_MINFONTSIZEANDMAXFONTSIZE_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_MINFONTSIZEANDMAXFONTSIZE_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputMinFontSizeAndMaxFontSizeTest { +public: + ~TextInputMinFontSizeAndMaxFontSizeTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_MINFONTSIZEANDMAXFONTSIZE_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_numberoflines_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_numberoflines_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d671910bc0083934998b09e816b531c6b4f0b5f6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_numberoflines_test.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_numberoflines_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +ArkUI_NodeHandle CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi, int32_t value) +{ + float width = 200; + float height = 100; + auto textInput = nodeApi->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_HEIGHT, &heightItem); + + ArkUI_NumberValue marginValue[] = { { .f32 = 5 } }; + ArkUI_AttributeItem marginItem = { marginValue, sizeof(marginValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_MARGIN, &marginItem); + + ArkUI_NumberValue Line_Value_1[] = { { .i32 = value } }; + ArkUI_AttributeItem Line_Item_1 = { Line_Value_1, sizeof(Line_Value_1) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_AREA_NUMBER_OF_LINES, &Line_Item_1); + + ArkUI_AttributeItem textInput_id_item = {}; + textInput_id_item.string = "line1\nline2\nline3\nline4"; + nodeApi->setAttribute(textInput, NODE_TEXT_AREA_TEXT, &textInput_id_item); + + ArkUI_NumberValue Border_Value_1[] = { { .f32 = 1 } }; + ArkUI_AttributeItem Border_Item_1 = { Border_Value_1, sizeof(Border_Value_1) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_BORDER_WIDTH, &Border_Item_1); + + return textInput; +} + +ArkUI_NodeHandle CreateSubTextInputPlaceholderNode(ArkUI_NativeNodeAPI_1* nodeApi, int32_t value) +{ + float width = 200; + float height = 100; + auto textInput = nodeApi->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_HEIGHT, &heightItem); + + ArkUI_NumberValue marginValue[] = { { .f32 = 5 } }; + ArkUI_AttributeItem marginItem = { marginValue, sizeof(marginValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_MARGIN, &marginItem); + + ArkUI_AttributeItem textInput_id_item = {}; + textInput_id_item.string = "line1\nline2\nline3\nline4"; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_PLACEHOLDER, &textInput_id_item); + + ArkUI_NumberValue Line_Value_1[] = { { .i32 = value } }; + ArkUI_AttributeItem Line_Item_1 = { Line_Value_1, sizeof(Line_Value_1) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_NUMBER_OF_LINES, &Line_Item_1); + + ArkUI_NumberValue Border_Value_1[] = { { .f32 = 1 } }; + ArkUI_AttributeItem Border_Item_1 = { Border_Value_1, sizeof(Border_Value_1) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_BORDER_WIDTH, &Border_Item_1); + ; + + return textInput; +} + +napi_value TextInputNumberOfLinesTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputNumberOfLinesTest", "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, "TextInputNumberOfLinesTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + auto textInput_1 = CreateSubTextInputNode(nodeAPI, 0); + auto textInput_2 = CreateSubTextInputNode(nodeAPI, 3); + auto textInput_3 = CreateSubTextInputNode(nodeAPI, 3); + auto textInput_4 = CreateSubTextInputPlaceholderNode(nodeAPI, 0); + auto textInput_reset = CreateSubTextInputNode(nodeAPI, 5); + auto textInput_5 = CreateSubTextInputNode(nodeAPI, 100); + + nodeAPI->resetAttribute(textInput_reset, NODE_TEXT_INPUT_NUMBER_OF_LINES); + + ArkUI_NumberValue font_Value_4[] = { { .f32 = 12 } }; + ArkUI_AttributeItem font_Item_4 = { font_Value_4, sizeof(font_Value_4) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput_4, NODE_FONT_SIZE, &font_Item_4); + + ArkUI_NumberValue lineHeight_Value_3[] = { { .f32 = 30 } }; + ArkUI_AttributeItem lineHeight_Item_3 = { lineHeight_Value_3, + sizeof(lineHeight_Value_3) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput_3, NODE_TEXT_LINE_HEIGHT, &lineHeight_Item_3); + + nodeAPI->addChild(column, textInput_1); + nodeAPI->addChild(column, textInput_2); + nodeAPI->addChild(column, textInput_3); + nodeAPI->addChild(column, textInput_4); + nodeAPI->addChild(column, textInput_reset); + nodeAPI->addChild(column, textInput_5); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputNumberOfLinesTest", + "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/textinput/textinput_numberoflines_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_numberoflines_test.h new file mode 100644 index 0000000000000000000000000000000000000000..37855b2ef1db4d87b29396f90a56d4d6fce1087f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_numberoflines_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_NUMBEROFLINES_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_NUMBEROFLINES_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputNumberOfLinesTest { +public: + ~TextInputNumberOfLinesTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; + +} // namespace ArkUICApiDemo + +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_NUMBEROFLINES_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_password_rules_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_password_rules_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27b72fa3d0dd65a88a870bab9abd3bcf0f4b0094 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_password_rules_test.cpp @@ -0,0 +1,331 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_password_rules_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto setContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_TEXT, &content_item); + return nodeHandle; +} + +static auto setMargin(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float margin) +{ + ArkUI_NumberValue margin_value[] = { { .f32 = margin } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + return nodeHandle; +} + +static auto setFontsize(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float fontsize) +{ + ArkUI_NumberValue font_size_value[] = { { .f32 = fontsize } }; + ArkUI_AttributeItem font_size_item = { font_size_value, sizeof(font_size_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &font_size_item); + return nodeHandle; +} + +static auto setEnableAutoFill(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t enable) +{ + ArkUI_NumberValue value[] = { { .i32 = enable } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_ENABLE_AUTO_FILL, &item); + return nodeHandle; +} + +static auto setContentType(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, int32_t contentType) +{ + ArkUI_NumberValue value[] = { { .i32 = contentType } }; + ArkUI_AttributeItem item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_CONTENT_TYPE, &item); + return nodeHandle; +} + +static auto setPasswordRules(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* rules) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = rules; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_PASSWORD_RULES, &content_item); + return nodeHandle; +} + +static auto setTextInput( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, const char* id, const char* rules) +{ + nodeHandle = setWidth(nodeAPI, nodeHandle, SIZE_400); + nodeHandle = setHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = setId(nodeAPI, nodeHandle, id); + nodeHandle = setMargin(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = setFontsize(nodeAPI, nodeHandle, SIZE_30); + nodeHandle = setEnableAutoFill(nodeAPI, nodeHandle, PARAM_1); + nodeHandle = setContentType(nodeAPI, nodeHandle, ARKUI_TEXTINPUT_CONTENT_TYPE_NEW_PASSWORD); + nodeHandle = setPasswordRules(nodeAPI, nodeHandle, rules); + return nodeHandle; +} + +napi_value TextInputPasswordRulesTest::CreateNativeNodePage1(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + + textInput1 = setTextInput(nodeAPI, textInput1, "textInput1", "begin:[upper]"); + textInput2 = setTextInput(nodeAPI, textInput2, "textInput2", "begin:[lower]"); + textInput3 = setTextInput(nodeAPI, textInput3, "textInput3", "begin:[digit]"); + textInput4 = setTextInput(nodeAPI, textInput4, "textInput4", "begin:[]"); + textInput5 = setTextInput(nodeAPI, textInput5, "textInput5", "begin:[llllower]"); + textInput6 = setTextInput(nodeAPI, textInput6, "textInput6", "beeegin:[lower]"); + textInput7 = setTextInput(nodeAPI, textInput7, "textInput7", "special:[yes]"); + textInput8 = setTextInput(nodeAPI, textInput8, "textInput8", "ssssspecial:[yes]"); + textInput9 = setTextInput(nodeAPI, textInput9, "textInput9", "special:[yyyyyyes]"); + textInput10 = setTextInput(nodeAPI, textInput10, "textInput10", ""); + textInput11 = setTextInput(nodeAPI, textInput11, "textInput11", "len:[fixedlen:16]"); + textInput12 = setTextInput(nodeAPI, textInput12, "textInput12", "len:[]"); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", + "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 TextInputPasswordRulesTest::CreateNativeNodePage2(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput7 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput8 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput9 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput10 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput11 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput12 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + nodeAPI->addChild(column, textInput9); + nodeAPI->addChild(column, textInput10); + nodeAPI->addChild(column, textInput11); + nodeAPI->addChild(column, textInput12); + + // 设置属性 + textInput1 = setTextInput(nodeAPI, textInput1, "textInput1", "len:[fixedlen:5]"); + textInput2 = setTextInput(nodeAPI, textInput2, "textInput2", "len:[fixedlen:100]"); + textInput3 = setTextInput(nodeAPI, textInput3, "textInput3", "leeeen:[fixedlen:15]"); + textInput4 = setTextInput(nodeAPI, textInput4, "textInput4", "len:[minlen:16"); + textInput5 = setTextInput(nodeAPI, textInput5, "textInput5", "len:[minlen:5]"); + textInput6 = setTextInput(nodeAPI, textInput6, "textInput6", "len:[minlen:100]"); + textInput7 = setTextInput(nodeAPI, textInput7, "textInput7", "len:[maxlen:28]"); + textInput8 = setTextInput(nodeAPI, textInput8, "textInput8", "len:[maxlen:5]"); + textInput9 = setTextInput(nodeAPI, textInput9, "textInput9", "len:[maxlen:100]"); + textInput10 = setTextInput(nodeAPI, textInput10, "textInput10", "len:[minlen:13,maxlen:18]"); + textInput11 = setTextInput(nodeAPI, textInput11, "textInput11", "len:[maxlen:18,minlen:13]"); + textInput12 = setTextInput(nodeAPI, textInput12, "textInput12", "len:[minlen:18,maxlen:13]"); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", + "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 TextInputPasswordRulesTest::CreateNativeNodePage3(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + + // 设置属性 + textInput1 = + setTextInput(nodeAPI, textInput1, "textInput1", "begin:[upper],special:[yes],len:[maxlen:32,minlen:12]"); + textInput2 = + setTextInput(nodeAPI, textInput2, "textInput2", "special:[yes],begin:[upper],len:[maxlen:32,minlen:12]"); + textInput3 = setTextInput(nodeAPI, textInput3, "textInput3", "special:[yes],begin:[upper]"); + textInput4 = setTextInput(nodeAPI, textInput4, "textInput4", "special:[yes]@begin:[upper]"); + textInput5 = + setTextInput(nodeAPI, textInput5, "textInput5", "begin:[upper],special:[yes],len:[maxlen:32,minlen:12]"); + nodeAPI->resetAttribute(textInput5, NODE_TEXT_INPUT_PASSWORD_RULES); + + // 组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputPasswordRulesTest", + "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/textinput/textinput_password_rules_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_password_rules_test.h new file mode 100644 index 0000000000000000000000000000000000000000..7c45bb4cb259ea2d2a7df351360cd2d28264506e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_password_rules_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_PASSWORD_RULES_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_PASSWORD_RULES_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputPasswordRulesTest { +public: + ~TextInputPasswordRulesTest(); + static napi_value CreateNativeNodePage1(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage2(napi_env env, napi_callback_info info); + static napi_value CreateNativeNodePage3(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_PASSWORD_RULES_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selectall_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selectall_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..172aa4c19c2d8e95a485f8d3df1f0ad1eeb8b3dc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selectall_test.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "textinput/textinput_selectall_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_TEXT, &content_item); + return nodeHandle; +} + +static auto setId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto setCaretColor(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, uint32_t color) +{ + ArkUI_NumberValue color_value[] = { { .u32 = color } }; + ArkUI_AttributeItem color_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_CARET_COLOR, &color_item); + return nodeHandle; +} + +static auto setSelectAll( + ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content, char* id, int selectAll) +{ + nodeHandle = setWidth(nodeAPI, nodeHandle, SIZE_300); + nodeHandle = setHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = setContent(nodeAPI, nodeHandle, content); + nodeHandle = setCaretColor(nodeAPI, nodeHandle, COLOR_TRANSPARENT); + nodeHandle = setId(nodeAPI, nodeHandle, id); + ArkUI_NumberValue select_all_value[] = { { .i32 = selectAll } }; + ArkUI_AttributeItem select_all_item = { select_all_value, sizeof(select_all_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_SELECT_ALL, &select_all_item); + return nodeHandle; +} + +napi_value TextInputSelectAllTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSelectAllTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSelectAllTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput5 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput6 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + + // 设置selectAll + textInput1 = setSelectAll(nodeAPI, textInput1, "the textInput content", "textInput1", PARAM_1); + textInput2 = setSelectAll(nodeAPI, textInput2, "the textInput content", "textInput2", PARAM_0); + textInput3 = setSelectAll(nodeAPI, textInput3, "the textInput content", "textInput3", PARAM_NEGATIVE_1); + textInput4 = setSelectAll(nodeAPI, textInput4, + "the textInput content the textInput content the textInput content the textInput content", "textInput4", + PARAM_1); + textInput5 = setSelectAll(nodeAPI, textInput5, "", "textInput5", PARAM_1); + textInput6 = setSelectAll(nodeAPI, textInput6, "the textInput content", "textInput6", PARAM_1); + nodeAPI->resetAttribute(textInput6, NODE_TEXT_INPUT_SELECT_ALL); + + // 设置聚焦不拉起输入法 + ArkUI_NumberValue keyboard_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput4, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput5, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput6, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + + // 注册获取焦点事件 + nodeAPI->registerNodeEvent(textInput1, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput2, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput3, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput4, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput5, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput6, NODE_ON_FOCUS, ON_FOCUS_EVENT_ID, nullptr); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSelectAllTest", + "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/textinput/textinput_selectall_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selectall_test.h new file mode 100644 index 0000000000000000000000000000000000000000..8332f56c16e7524f86d8c7f77169b3962c28ffa6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selectall_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_TEXTINPUT_SELECTALL_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_SELECTALL_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputSelectAllTest { +public: + ~TextInputSelectAllTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_SELECTALL_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selection_menu_hidden_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selection_menu_hidden_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14608d86e8bfc81cedd91786b265fcda84405aff --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selection_menu_hidden_test.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput/textinput_selection_menu_hidden_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto setWidth(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float width) +{ + ArkUI_NumberValue width_value[] = { { .f32 = width } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + return nodeHandle; +} + +static auto setHeight(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, float height) +{ + ArkUI_NumberValue height_value[] = { { .f32 = height } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + return nodeHandle; +} + +static auto setContent(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* content) +{ + ArkUI_AttributeItem content_item = {}; + content_item.string = content; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_TEXT, &content_item); + return nodeHandle; +} + +static auto setId(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* id) +{ + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + return nodeHandle; +} + +static auto setSelectionMenuHidden(ArkUI_NativeNodeAPI_1* nodeAPI, ArkUI_NodeHandle& nodeHandle, char* id, int select) +{ + nodeHandle = setWidth(nodeAPI, nodeHandle, SIZE_300); + nodeHandle = setHeight(nodeAPI, nodeHandle, SIZE_50); + nodeHandle = setContent(nodeAPI, nodeHandle, "thetextInputcontentthe"); + nodeHandle = setId(nodeAPI, nodeHandle, id); + ArkUI_NumberValue select_value[] = { { .i32 = select } }; + ArkUI_AttributeItem select_item = { select_value, sizeof(select_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_SELECTION_MENU_HIDDEN, &select_item); + return nodeHandle; +} + +napi_value TextInputSelectionMenuHiddenTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSelectionMenuHiddenTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSelectionMenuHiddenTest", "GetContext env or info is null"); + return nullptr; + } + + // 创建节点组件 + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto textInput1 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput2 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput3 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + auto textInput4 = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + + // 设置selectionMenuHidden + textInput1 = setSelectionMenuHidden(nodeAPI, textInput1, "textInput1", PARAM_1); + textInput2 = setSelectionMenuHidden(nodeAPI, textInput2, "textInput2", PARAM_0); + textInput3 = setSelectionMenuHidden(nodeAPI, textInput3, "textInput3", PARAM_NEGATIVE_1); + textInput4 = setSelectionMenuHidden(nodeAPI, textInput4, "textInput4", PARAM_1); + nodeAPI->resetAttribute(textInput4, NODE_TEXT_INPUT_SELECTION_MENU_HIDDEN); + + // 设置聚焦不拉起输入法 + ArkUI_NumberValue keyboard_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput4, NODE_TEXT_INPUT_ENABLE_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + nodeAPI->setAttribute(textInput4, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + + // 注册获取点击事件 + nodeAPI->registerNodeEvent(textInput1, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput2, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput3, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + nodeAPI->registerNodeEvent(textInput4, NODE_ON_CLICK, ON_CLICK_EVENT_ID, nullptr); + + // column组件挂载到XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSelectionMenuHiddenTest", + "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/textinput/textinput_selection_menu_hidden_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selection_menu_hidden_test.h new file mode 100644 index 0000000000000000000000000000000000000000..721e72e84afdee86bd7a839b1869563737c04431 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_selection_menu_hidden_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_TEXTINPUT_SELECTION_MENU_HIDDEN_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_SELECTION_MENU_HIDDEN_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputSelectionMenuHiddenTest { +public: + ~TextInputSelectionMenuHiddenTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_SELECTION_MENU_HIDDEN_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_settextselection_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_settextselection_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9c88104aaaff6a2d0857a1925dbc8123d320848 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_settextselection_test.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_settextselection_test.h" + +#include + +#include "../manager/plugin_manager.h" + +#define ON_CLICK_1 6001 +#define ON_CLICK_2 6002 +#define ON_CLICK_3 6003 +#define ON_CLICK_4 6004 + +namespace ArkUICApiDemo { + +static ArkUI_NodeHandle text1; + +static ArkUI_NodeHandle textInput1; + +ArkUI_NodeHandle TextInputSetTextSelectionTest::CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi) +{ + float width = 300; + float height = 280; + auto textInput = nodeApi->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue widthValue[] = { { .f32 = width } }; + ArkUI_AttributeItem widthItem = { widthValue, sizeof(widthValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_WIDTH, &widthItem); + + ArkUI_NumberValue heightValue[] = { { .f32 = height } }; + ArkUI_AttributeItem heightItem = { heightValue, sizeof(heightValue) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_HEIGHT, &heightItem); + + ArkUI_AttributeItem content_item = {}; + content_item.string = "TextInput"; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_TEXT, &content_item); + + ArkUI_NumberValue caretColor_value[] = { { .u32 = COLOR_TRANSPARENT } }; + ArkUI_AttributeItem caretColor_item = { caretColor_value, sizeof(caretColor_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_CARET_COLOR, &caretColor_item); + + ArkUI_NumberValue keyboardEnable_value[] = { { .i32 = 0 } }; + ArkUI_AttributeItem keyboardEnable_item = { keyboardEnable_value, + sizeof(keyboardEnable_value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboardEnable_item); + + ArkUI_NumberValue value[] = { { .f32 = 55 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeApi->setAttribute(textInput, NODE_FONT_SIZE, &value_item); + + return textInput; +} + +static auto CreatButton(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandler = nodeAPI->createNode(ARKUI_NODE_BUTTON); + + ArkUI_NumberValue width_value[] = { { .f32 = 300 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = 50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandler, NODE_HEIGHT, &height_item); + + return nodeHandler; +} + +static void OnEventReceive(ArkUI_NodeEvent* event) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputSetTextSelectionTest", "OnEventReceive"); + if (event == nullptr) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSetTextSelectionTest", "OnEventReceive: event is null"); + return; + } + + int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event); + if (eventId == 0) { + return; + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputSetTextSelectionTest", + "OnEventReceive eventId: %{public}d", eventId); + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + switch (eventId) { + case ON_CLICK_1: { + ArkUI_NumberValue setTextSelection_value1[] = { { .i32 = 0 }, { .i32 = 4 } }; + ArkUI_AttributeItem setTextSelection_item1 = { setTextSelection_value1, + sizeof(setTextSelection_value1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT_SELECTION, &setTextSelection_item1); + + return; + } + case ON_CLICK_2: { + ArkUI_NumberValue setTextSelection_value1[] = { { .i32 = -1 }, { .i32 = -1 } }; + ArkUI_AttributeItem setTextSelection_item1 = { setTextSelection_value1, + sizeof(setTextSelection_value1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT_SELECTION, &setTextSelection_item1); + + return; + } + case ON_CLICK_3: { + ArkUI_NumberValue setTextSelection_value1[] = { { .i32 = 0 }, { .i32 = 100 } }; + ArkUI_AttributeItem setTextSelection_item1 = { setTextSelection_value1, + sizeof(setTextSelection_value1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT_SELECTION, &setTextSelection_item1); + + return; + } + case ON_CLICK_4: { + ArkUI_NumberValue setTextSelection_value1[] = { { .i32 = 7 }, { .i32 = 2 } }; + ArkUI_AttributeItem setTextSelection_item1 = { setTextSelection_value1, + sizeof(setTextSelection_value1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT_SELECTION, &setTextSelection_item1); + + return; + } + default: { + return; + } + } +} + +napi_value TextInputSetTextSelectionTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSetTextSelectionTest", "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, "TextInputSetTextSelectionTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + text1 = nodeAPI->createNode(ARKUI_NODE_TEXT); + + textInput1 = CreateSubTextInputNode(nodeAPI); + + ArkUI_AttributeItem id_item = {}; + id_item.string = "TextInputSetTextSelectionTest_textInput_id1"; + nodeAPI->setAttribute(textInput1, NODE_ID, &id_item); + + auto button1 = CreatButton(nodeAPI); + auto button2 = CreatButton(nodeAPI); + auto button3 = CreatButton(nodeAPI); + auto button4 = CreatButton(nodeAPI); + + ArkUI_AttributeItem id_item1 = {}; + id_item1.string = "TextInputSetTextSelectionTest_id1"; + nodeAPI->setAttribute(button1, NODE_ID, &id_item1); + + ArkUI_AttributeItem id_item2 = {}; + id_item2.string = "TextInputSetTextSelectionTest_id2"; + nodeAPI->setAttribute(button2, NODE_ID, &id_item2); + + ArkUI_AttributeItem id_item3 = {}; + id_item3.string = "TextInputSetTextSelectionTest_id3"; + nodeAPI->setAttribute(button3, NODE_ID, &id_item3); + + ArkUI_AttributeItem id_item4 = {}; + id_item4.string = "TextInputSetTextSelectionTest_id4"; + nodeAPI->setAttribute(button4, NODE_ID, &id_item4); + + ArkUI_AttributeItem button_item1 = {}; + button_item1.string = "选中0-4"; + nodeAPI->setAttribute(button1, NODE_BUTTON_LABEL, &button_item1); + + button_item1.string = "选中-1 - -1"; + nodeAPI->setAttribute(button2, NODE_BUTTON_LABEL, &button_item1); + + button_item1.string = "选中0-100"; + nodeAPI->setAttribute(button3, NODE_BUTTON_LABEL, &button_item1); + + button_item1.string = "选中7-2"; + nodeAPI->setAttribute(button4, NODE_BUTTON_LABEL, &button_item1); + + nodeAPI->registerNodeEvent(button1, NODE_ON_CLICK, ON_CLICK_1, nodeAPI); + nodeAPI->registerNodeEvent(button2, NODE_ON_CLICK, ON_CLICK_2, nodeAPI); + nodeAPI->registerNodeEvent(button3, NODE_ON_CLICK, ON_CLICK_3, nodeAPI); + nodeAPI->registerNodeEvent(button4, NODE_ON_CLICK, ON_CLICK_4, nodeAPI); + + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, button1); + nodeAPI->addChild(column, button2); + nodeAPI->addChild(column, button3); + nodeAPI->addChild(column, button4); + + nodeAPI->registerNodeEventReceiver(&OnEventReceive); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputSetTextSelectionTest", + "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/textinput/textinput_settextselection_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_settextselection_test.h new file mode 100644 index 0000000000000000000000000000000000000000..d4d06483c250feb9ed2744f869173f17851df849 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_settextselection_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUI_CAPI_DEMO_TEXTINPUT_SETTEXTSELECTION_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_SETTEXTSELECTION_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputSetTextSelectionTest { +public: + ~TextInputSetTextSelectionTest(); + static ArkUI_NodeHandle CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeApi); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; + +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_SETTEXTSELECTION_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_showkeyboardonfocus_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_showkeyboardonfocus_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..71aa3f32a99492b562de6783ce34a15db58711fa --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_showkeyboardonfocus_test.cpp @@ -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. + */ + +#include "textinput_showkeyboardonfocus_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto createChildNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t value) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + + ArkUI_NumberValue showKey_value[] = { { .i32 = value } }; + ArkUI_AttributeItem showKey_item = { showKey_value, sizeof(showKey_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &showKey_item); + + ArkUI_NumberValue width_value[] = { { .f32 = SIZE_200 } }; + ArkUI_AttributeItem width_item = { width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_WIDTH, &width_item); + + ArkUI_NumberValue height_value[] = { { .f32 = SIZE_300 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + ArkUI_NumberValue margin_value[] = { { .f32 = DEFAULT_MARGIN } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + return nodeHandle; +} + +napi_value TextInputShowKeyboardOnFocusTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputShowKeyboardOnFocusTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputShowKeyboardOnFocusTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row = nodeAPI->createNode(ARKUI_NODE_ROW); + auto textInput = createChildNode(nodeAPI, 1); + auto textInputCompare = createChildNode(nodeAPI, 0); + + ArkUI_AttributeItem id_item = {}; + id_item.string = "OnFocusTestTextInput"; + nodeAPI->setAttribute(textInput, NODE_ID, &id_item); + id_item.string = "OnFocusTestTextInputCompare"; + nodeAPI->setAttribute(textInputCompare, NODE_ID, &id_item); + + nodeAPI->addChild(row, textInput); + nodeAPI->addChild(row, textInputCompare); + nodeAPI->addChild(column, row); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputShowKeyboardOnFocusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +napi_value TextInputShowKeyboardOnFocusTest::CreateAbnormalNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "TextInputShowKeyboardOnFocusTest", "CreateNativeNode"); + + size_t argc = PARAM_1; + napi_value args[PARAM_1] = { nullptr }; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + size_t length = PARAM_64; + size_t strLength = PARAM_0; + char xComponentID[PARAM_64] = { PARAM_0 }; + napi_get_value_string_utf8(env, args[PARAM_0], xComponentID, length, &strLength); + + if ((env == nullptr) || (info == nullptr)) { + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputShowKeyboardOnFocusTest", "GetContext env or info is null"); + return nullptr; + } + + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + auto row1 = nodeAPI->createNode(ARKUI_NODE_ROW); + auto textInput3 = createChildNode(nodeAPI, -1); + auto textInput4 = createChildNode(nodeAPI, 0); + + ArkUI_AttributeItem id_item = {}; + + id_item.string = "TextInputDisableTest"; + nodeAPI->setAttribute(textInput3, NODE_ID, &id_item); + id_item.string = "OnFocusTestTextInputReset"; + nodeAPI->setAttribute(textInput4, NODE_ID, &id_item); + nodeAPI->resetAttribute(textInput4, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS); + + nodeAPI->addChild(row1, textInput3); + nodeAPI->addChild(row1, textInput4); + nodeAPI->addChild(column, row1); + + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputShowKeyboardOnFocusTest", + "OH_NativeXComponent_AttachNativeRootNode failed"); + } + + napi_value exports; + if (napi_create_object(env, &exports) != napi_ok) { + napi_throw_type_error(env, nullptr, "napi_create_object failed"); + return nullptr; + } + + return exports; +} + +} // namespace ArkUICApiDemo \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_showkeyboardonfocus_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_showkeyboardonfocus_test.h new file mode 100644 index 0000000000000000000000000000000000000000..370ddda6ff363ecd1419e95e2c72bbf54ed8d25f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_showkeyboardonfocus_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_TEXTINPUT_SHOWKEYBOARDONFOCUS_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_SHOWKEYBOARDONFOCUS_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputShowKeyboardOnFocusTest { +public: + ~TextInputShowKeyboardOnFocusTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); + static napi_value CreateAbnormalNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_SHOWKEYBOARDONFOCUS_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_style_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_style_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..644bfdb51c40caa61242b6c615cfd894d56d3333 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_style_test.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_style_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t value, const char* id) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 350 } }; + 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 = 100 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + // set style + ArkUI_NumberValue style_value[] = { { .i32 = value } }; + ArkUI_AttributeItem type_item = { style_value, sizeof(style_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_STYLE, &type_item); + + // set text + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + + return nodeHandle; +} + +napi_value TextInputStyleTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputStyleTest", "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, "TextInputStyleTest", "GetContext env or info is null"); + return nullptr; + } + // create nodeAPI + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // textinput + auto textInput1 = CreateSubTextInputNode(nodeAPI, ARKUI_TEXTINPUT_STYLE_DEFAULT, "default"); + auto textInput2 = CreateSubTextInputNode(nodeAPI, ARKUI_TEXTINPUT_STYLE_INLINE, "inline"); + auto textInput3 = CreateSubTextInputNode(nodeAPI, -1, "negative"); + auto textInput4 = CreateSubTextInputNode(nodeAPI, 2, "large"); + auto textInput5 = CreateSubTextInputNode(nodeAPI, ARKUI_TEXTINPUT_STYLE_INLINE, "reset"); + + nodeAPI->resetAttribute(textInput5, NODE_TEXT_INPUT_STYLE); + + // insert into the column + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + + // XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputStyleTest", + "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/textinput/textinput_style_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_style_test.h new file mode 100644 index 0000000000000000000000000000000000000000..30bb32ac0bde951d0513fc3974c7d45733cb0a5c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_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_TEXTINPUT_STYLE_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_STYLE_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputStyleTest { +public: + ~TextInputStyleTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_Style_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_textplaceholder_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_textplaceholder_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17e6f513499f99c1a3f924ad67fd16ccdb1f2b11 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_textplaceholder_test.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "textinput_textplaceholder_test.h" + +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeAPI) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 350 } }; + 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); + + ArkUI_NumberValue margin_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue value[] = { { .f32 = 40 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &value_item); + + return nodeHandle; +} + +napi_value TextInputTextPlaceholderTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputTextPlaceholderTest", "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, "TextInputTextPlaceholderTest", "GetContext env or info is null"); + return nullptr; + } + // create nodeAPI + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // textinput + auto textInput1 = CreateSubTextInputNode(nodeAPI); + auto textInput2 = CreateSubTextInputNode(nodeAPI); + + // set text + ArkUI_AttributeItem text_item = {}; + text_item.string = "texttest"; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT, &text_item); + + // set placeholder + ArkUI_AttributeItem placeholder_item = {}; + placeholder_item.string = "placeholder test"; + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_PLACEHOLDER, &placeholder_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_PLACEHOLDER, &placeholder_item); + + ArkUI_NumberValue value[] = { { .f32 = 40 } }; + ArkUI_AttributeItem value_item = { value, sizeof(value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput1, NODE_TEXT_AREA_PLACEHOLDER_FONT, &value_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_AREA_PLACEHOLDER_FONT, &value_item); + + // insert into the column + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + + // XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputTextPlaceholderTest", + "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/textinput/textinput_textplaceholder_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_textplaceholder_test.h new file mode 100644 index 0000000000000000000000000000000000000000..3a748968bad6d098f3fd56b8c86dc1c571b6485b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_textplaceholder_test.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_TEXTINPUT_TEXTPLACEHOLDER_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_TEXTPLACEHOLDER_TEST_H +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputTextPlaceholderTest { +public: + ~TextInputTextPlaceholderTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_TEXTPLACEHOLDER_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_underlinecolor_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_underlinecolor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b612bb48f4eb80d2f54bfc99858e66d60645d0e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_underlinecolor_test.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_underlinecolor_test.h" + +#include +#include +#include + +#include "../manager/plugin_manager.h" + +namespace ArkUICApiDemo { + +static auto CreateUnderlineColorNode( + ArkUI_NativeNodeAPI_1* nodeAPI, uint32_t color, uint32_t color1, uint32_t color2, uint32_t color3) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = 350 } }; + 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); + + // showUnderline + ArkUI_NumberValue showUnderlineValue[] = { { .i32 = 1 } }; + ArkUI_AttributeItem showUnderlineItem = { showUnderlineValue, + sizeof(showUnderlineValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_SHOW_UNDERLINE, &showUnderlineItem); + + ArkUI_NumberValue keyboard_value[] = { { .i32 = PARAM_0 } }; + ArkUI_AttributeItem keyboard_item = { keyboard_value, sizeof(keyboard_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_SHOW_KEYBOARD_ON_FOCUS, &keyboard_item); + + // maxLength + ArkUI_NumberValue lengthValue[] = { { .i32 = 4 } }; + ArkUI_AttributeItem lengthValueItem = { lengthValue, sizeof(lengthValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_MAX_LENGTH, &lengthValueItem); + + ArkUI_NumberValue showValue[] = { { .i32 = 1 } }; + ArkUI_AttributeItem showValueItem = { showValue, sizeof(showValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_AREA_SHOW_COUNTER, &showValueItem); + + // set typing\normal\error\disable color + ArkUI_NumberValue color_value[] = { { .u32 = color }, { .u32 = color1 }, { .u32 = color2 }, { .u32 = color3 } }; + ArkUI_AttributeItem color_value_item = { color_value, sizeof(color_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_UNDERLINE_COLOR, &color_value_item); + + return nodeHandle; +} + +napi_value TextInputUnderlineColorTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputUnderlineColorTest", "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, "TextInputUnderlineColorTest", "GetContext env or info is null"); + return nullptr; + } + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // textinput1 normal + auto textInput1 = CreateUnderlineColorNode(nodeAPI, COLOR_GREEN, COLOR_BLUE, COLOR_RED, COLOR_BLACK); + + // textinput2 typing + auto textInput2 = CreateUnderlineColorNode(nodeAPI, COLOR_GREEN, COLOR_BLUE, COLOR_RED, COLOR_BLACK); + + // textinput3 error + auto textInput3 = CreateUnderlineColorNode(nodeAPI, COLOR_GREEN, COLOR_BLUE, COLOR_RED, COLOR_BLACK); + + // textinput4 disable + auto textInput4 = CreateUnderlineColorNode(nodeAPI, COLOR_GREEN, COLOR_BLUE, COLOR_RED, COLOR_BLACK); + + // textinput2 typing + ArkUI_AttributeItem id_item = {}; + id_item.string = "textInput2"; + nodeAPI->setAttribute(textInput2, NODE_ID, &id_item); + + id_item.string = "textInput3"; + nodeAPI->setAttribute(textInput3, NODE_ID, &id_item); + + // textinput3 error + ArkUI_AttributeItem text_item = {}; + text_item.string = "12345"; + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_TEXT, &text_item); + + // textinput4 disable + ArkUI_NumberValue editValue[] = { { .i32 = false } }; + ArkUI_AttributeItem editItem = { editValue, sizeof(editValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(textInput4, NODE_ENABLED, &editItem); + + // insert into the column + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + + // XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputUnderlineColorTest", + "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/textinput/textinput_underlinecolor_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_underlinecolor_test.h new file mode 100644 index 0000000000000000000000000000000000000000..161ba1243e1df9c6dc9eee98e6e5998d78b9109d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_underlinecolor_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_TEXTINPUT_UNDERLINECOLOR_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_UNDERLINECOLOR_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputUnderlineColorTest { +public: + ~TextInputUnderlineColorTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_UNDERLINECOLOR_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_wordbreak_test.cpp b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_wordbreak_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..380d8237c886f5fcfa24757c5c2660f47ef06910 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_wordbreak_test.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "textinput_wordbreak_test.h" + +#include + +#include "../manager/plugin_manager.h" + +#define TEXTINPUT_WIDTH_150 150 + +namespace ArkUICApiDemo { + +static auto CreateSubTextInputNode(ArkUI_NativeNodeAPI_1* nodeAPI, int32_t type, char* id) +{ + auto nodeHandle = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT); + // set width + ArkUI_NumberValue width_value[] = { { .f32 = TEXTINPUT_WIDTH_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 = SIZE_50 } }; + ArkUI_AttributeItem height_item = { height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_HEIGHT, &height_item); + + // set inlineStyle + ArkUI_NumberValue style_value[] = { { .i32 = ARKUI_TEXTINPUT_STYLE_INLINE } }; + ArkUI_AttributeItem type_item = { style_value, sizeof(style_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_STYLE, &type_item); + + // set wordBreakType + ArkUI_NumberValue textinputValue[] = { { .i32 = type } }; + ArkUI_AttributeItem textinputItem = { textinputValue, sizeof(textinputValue) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_TEXT_INPUT_WORD_BREAK, &textinputItem); + + ArkUI_NumberValue margin_value[] = { { .f32 = 10 } }; + ArkUI_AttributeItem margin_item = { margin_value, sizeof(margin_value) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_MARGIN, &margin_item); + + ArkUI_NumberValue Border_Value_1[] = { { .f32 = 1 } }; + ArkUI_AttributeItem Border_Item_1 = { Border_Value_1, sizeof(Border_Value_1) / sizeof(ArkUI_NumberValue) }; + nodeAPI->setAttribute(nodeHandle, NODE_BORDER_WIDTH, &Border_Item_1); + + ArkUI_AttributeItem id_item = {}; + id_item.string = id; + nodeAPI->setAttribute(nodeHandle, NODE_ID, &id_item); + + return nodeHandle; +} + +napi_value TextInputWordBreakTest::CreateNativeNode(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputWordBreakTest", "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, "TextInputWordBreakTest", "GetContext env or info is null"); + return nullptr; + } + // create nodeAPI + ArkUI_NativeNodeAPI_1* nodeAPI = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); + + // create column + auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN); + + // create four textinput with diffrent types + auto textInput0 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_NORMAL, "textInput0"); + auto textInput1 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_NORMAL, "textInput1"); + auto textInput2 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_BREAK_ALL, "textInput2"); + auto textInput3 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_BREAK_ALL, "textInput3"); + auto textInput4 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_BREAK_WORD, "textInput4"); + auto textInput5 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_BREAK_WORD, "textInput5"); + auto textInput6 = CreateSubTextInputNode(nodeAPI, -1, "textInput6"); + auto textInput7 = CreateSubTextInputNode(nodeAPI, 3, "textInput7"); + auto textInput8 = CreateSubTextInputNode(nodeAPI, ARKUI_WORD_BREAK_NORMAL, "textInput8"); + + nodeAPI->resetAttribute(textInput8, NODE_TEXT_INPUT_WORD_BREAK); + + // insert into the column + nodeAPI->addChild(column, textInput0); + nodeAPI->addChild(column, textInput1); + nodeAPI->addChild(column, textInput2); + nodeAPI->addChild(column, textInput3); + nodeAPI->addChild(column, textInput4); + nodeAPI->addChild(column, textInput5); + nodeAPI->addChild(column, textInput6); + nodeAPI->addChild(column, textInput7); + nodeAPI->addChild(column, textInput8); + + // set text + ArkUI_AttributeItem text1_item = {}; + text1_item.string = "This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateat"; + ArkUI_AttributeItem text2_item = {}; + text2_item.string = "多行文本输入框组件,当输入的文本内容超过组件宽度时会自动换行显示。\n高度未设置时,组件无默认高" + "度,自适应内容高度。宽度未设置时,默认撑满最大宽度"; + + nodeAPI->setAttribute(textInput0, NODE_TEXT_INPUT_TEXT, &text2_item); + nodeAPI->setAttribute(textInput1, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput2, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput3, NODE_TEXT_INPUT_TEXT, &text2_item); + nodeAPI->setAttribute(textInput4, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput5, NODE_TEXT_INPUT_TEXT, &text2_item); + nodeAPI->setAttribute(textInput6, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput7, NODE_TEXT_INPUT_TEXT, &text1_item); + nodeAPI->setAttribute(textInput8, NODE_TEXT_INPUT_TEXT, &text1_item); + + // XComponent + std::string id(xComponentID); + if (OH_NativeXComponent_AttachNativeRootNode(PluginManager::GetInstance()->GetNativeXComponent(id), column) == + INVALID_PARAM) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "TextInputWordBreakTest", + "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/textinput/textinput_wordbreak_test.h b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_wordbreak_test.h new file mode 100644 index 0000000000000000000000000000000000000000..13942e9dcbc2634a65fa464e58b4252de8446369 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/textinput/textinput_wordbreak_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_TEXTINPUT_WORDBREAK_TEST_H +#define ARKUI_CAPI_DEMO_TEXTINPUT_WORDBREAK_TEST_H + +#include +#include +#include + +#include "../common/common.h" + +namespace ArkUICApiDemo { + +class TextInputWordBreakTest { +public: + ~TextInputWordBreakTest(); + static napi_value CreateNativeNode(napi_env env, napi_callback_info info); +}; +} // namespace ArkUICApiDemo +#endif // ARKUI_CAPI_DEMO_TEXTINPUT_WORDBREAK_TEST_H diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..05271b9c812c86a70121adaeba88167da23706e6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/index.d.ts @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputFontFeaturePage1Test: (a: string) => void; + +export const textInputFontFeaturePage2Test: (a: string) => void; + +export const textInputFontFeaturePage3Test: (a: string) => void; + +export const textInputEnableAutoFillTest: (a: string) => void; + +export const textInputContentTypePage1Test: (a: string) => void; + +export const textInputContentTypePage2Test: (a: string) => void; + +export const textInputPasswordRulesPage1Test: (a: string) => void; + +export const textInputPasswordRulesPage2Test: (a: string) => void; + +export const textInputPasswordRulesPage3Test: (a: string) => void; + +export const textInputCustomKeyboardPage1Test: (a: string) => void; + +export const textInputCustomKeyboardPage2Test: (a: string) => void; + +export const textInputCustomKeyboardPage3Test: (a: string) => void; + +export const textInputCustomKeyboardPage4Test: (a: string) => void; + +export const textInputCustomKeyboardPage5Test: (a: string) => void; + +export const textInputCustomKeyboardPage6Test: (a: string) => void; + +export const textInputSelectAllTest: (a: string) => void; + +export const textInputSelectionMenuHiddenTest: (a: string) => void; + +export const textInputTextPlaceholderTest: (a: string) => void; + +export const textInputCancelButtonTest: (a: string) => void; + +export const textInputSetTextSelectionTest: (a: string) => void; + +export const textInputUnderlineColorTest: (a: string) => void; + +export const textInputWordBreakTest: (a: string) => void; + +export const textInputStyleTest: (a: string) => void; + +export const textInputMinFontSizeAndMaxFontSizeTest: (a: string) => void; + +export const textInputMaxLinesTest: (a: string) => void; + +export const textInputNumberOfLinesTest: (a: string) => void; + +export const textInputInputFilterTest: (a: string) => void; + +export const textInputShowKeyboardOnFocusTest: (a: string) => void; + +export const textInputShowKeyboardOnFocusAbnormalTest: (a: string) => void; + +export const textInputBlurOnSubmitTest: (a: string) => void; + +export const textInputGetCaretOffsetTest: (a: string) => void; + +export const textInputCaretPositionTest: (a: string) => void; + +export const textInputControllerTest: (a: string) => void; \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70466261f5936d9f1f412c12bea873a6fb3a522c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/cpp/types/libnativerender/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libnativerender.so", + "types": "./index.d.ts", + "version": "0.1.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..a32a8361c7fcad66acf12208583e198fc4e68dab --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..3804336023f8f9fc174e32ffff976899dd003950 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/function/ui_compare/capidemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..be794f48ccffc46278e76ce3493088a647b0d470 --- /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 100644 index 0000000000000000000000000000000000000000..685673faf7fa04f4881896a0caa079c1d71c3a60 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/ets/pages/Index.ets @@ -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. + */ +import render from "libnativerender.so" +@Entry +@Component +struct Index { + build() { + Column() { + Column() { + + XComponent({ + id: 'xComponentId', + type: XComponentType.NODE, + libraryname: 'nativerender' + }).onDestroy(() => { + console.log('onDestroy'); + }) + }.margin({ + top: 27, + left: 12, + right: 12 + }) + .height('100%') + .width('100%') + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/module.json5 b/function/ui_compare/capidemo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aa0ed1bad179e91b0e7d4f9d7e84f7f83c25a33a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/module.json5 @@ -0,0 +1,45 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json b/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_blue.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png new file mode 100644 index 0000000000000000000000000000000000000000..385aee55284cd8a5ebde3910bf82c494f057fecf Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_green.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png new file mode 100644 index 0000000000000000000000000000000000000000..742044d80325e183663d8dffd8a2e5a37c6bed90 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_red.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..1fa2f73575caef6b5fcf736b6eb2e8ff34802713 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/background_yellow.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/foreground.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png new file mode 100644 index 0000000000000000000000000000000000000000..adb226051b3771a741509382c683606d029e5b25 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/icon_small.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json b/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg b/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg new file mode 100644 index 0000000000000000000000000000000000000000..36a19cd6b90bb98511116f5015c74fe2f860249d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/src.jpg differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png b/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json b/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..597ecf95e61d7e30367c22fe2f8638008361b044 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..35d7138e9c498ded1b55d2daf4f9d58630841647 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/Application/AbilityStage.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log('[Demo] MyAbilityStage onCreate'); + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..bb42e0040a8974b56a591f1e662fe7b7e64842d5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/MainAbility.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ability from '@ohos.app.ability.UIAbility'; +import Settings from '../test/common/Settings'; + +const TAG: string = '[createWindow]' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log(`${TAG} MainAbility onCreate`); + globalThis.abilityWant = want; + globalThis.abilityLaunchParam = launchParam; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log(`${TAG} MainAbility onDestroy`); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log(`${TAG} MainAbility onWindowStageCreate windowStage=` + windowStage); + globalThis.windowStage = windowStage; + globalThis.context = this.context; + + setTimeout(() => { + console.info(`${TAG} setTimeout`) + Settings.createWindow('MainAbility/pages/DemoIndex', { + width: 720, height: 1280, dpi: 230 + }) + }, 1000) + } + + onWindowStageDestroy() { + //Main window is destroyed, release UI related resources + console.log(`${TAG} MainAbility onWindowStageDestroy`); + } + + onForeground() { + // Ability has brought to foreground + console.log(`${TAG} MainAbility onForeground`); + } + + onBackground() { + // Ability has back to background + console.log(`${TAG} MainAbility onBackground`); + } +}; \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets new file mode 100644 index 0000000000000000000000000000000000000000..a049a87977058169ed5625795b248d3aa773bb1e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/componet/CommonView.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct CommonView { + pageTag: string = ''; + + build() { + Column() { + Column({ space: 10 }) { + XComponent({ + id: this.pageTag, + type: 'node', + libraryname: 'nativerender' + }).onDestroy(() => { + console.log('onDestroy'); + }).backgroundColor('#FFEEEEEE') + .width('100%') + .height('100%') + }.margin(20) + .height('100%') + .width('100%') + } + .id(this.pageTag) + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e9adc265a2b3e7260371437cdedd90608f51df5 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/DemoIndex.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../../test/List.test'; + +@Entry +@Component +struct DemoIndex { + aboutToAppear() { + setTimeout(() => { + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, 2000) + } + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('ARKUI CAPI DEMO') + .fontSize(36) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputBlurOnSubmitTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputBlurOnSubmitTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c041e4e52b08e865e664f5763885d6131e6928ec --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputBlurOnSubmitTest.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 TextInputBlurOnSubmitTest { + PAGE_TAG: string = 'TextInputBlurOnSubmitTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputBlurOnSubmitTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCancelButtonTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCancelButtonTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..78a7bbbbec833990cf33fac16d9ed074fddf5251 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCancelButtonTest.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 TextInputCancelButtonTest { + PAGE_TAG: string = 'TextInputCancelButtonTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCancelButtonTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCaretPositionTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCaretPositionTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb0cfd097459b6281e2c2fca36d1ab723247c28c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCaretPositionTest.ets @@ -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. + */ +import render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct TextInputCaretPositionTest { + PAGE_TAG: string = 'TextInputCaretPositionTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCaretPositionTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputContentTypePage1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputContentTypePage1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5025f9a1f5ae4e096657f85a2d97bef0e6cca02 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputContentTypePage1Test.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 TextInputContentTypePage1Test { + PAGE_TAG: string = 'TextInputContentTypePage1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputContentTypePage1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputContentTypePage2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputContentTypePage2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f00f52d814fa1fe02be7dad80faaf0fbe8cf35a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputContentTypePage2Test.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 TextInputContentTypePage2Test { + PAGE_TAG: string = 'TextInputContentTypePage2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputContentTypePage2Test(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputControllerTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputControllerTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..ea7179a4ee9d7f768b42fee0155baadc0ddcbfc3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputControllerTest.ets @@ -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. + */ +import render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct TextInputControllerTest { + PAGE_TAG: string = 'TextInputControllerTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputControllerTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8356aacefddcd7ba26daf1a397dff579018fdb2c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage1Test.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 TextInputCustomKeyboardPage1Test { + PAGE_TAG: string = 'TextInputCustomKeyboardPage1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCustomKeyboardPage1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..79cdc436faee1d70e7c6a97067cb306a02c5c72f --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage2Test.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 TextInputCustomKeyboardPage2Test { + PAGE_TAG: string = 'TextInputCustomKeyboardPage2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCustomKeyboardPage2Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage3Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage3Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ec0b9b46643e15a11c3e483df9e55bbb48aa4bcf --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage3Test.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 TextInputCustomKeyboardPage3Test { + PAGE_TAG: string = 'TextInputCustomKeyboardPage3Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCustomKeyboardPage3Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage4Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage4Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e185918bc17b9a10be2d93b68216afed3605fbac --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage4Test.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 TextInputCustomKeyboardPage4Test { + PAGE_TAG: string = 'TextInputCustomKeyboardPage4Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCustomKeyboardPage4Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage5Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage5Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..49b9474d323ab0bc98c1e81237f8aac8b3523ef4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage5Test.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 TextInputCustomKeyboardPage5Test { + PAGE_TAG: string = 'TextInputCustomKeyboardPage5Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCustomKeyboardPage5Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage6Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage6Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..30908f146aac54e11f93cbbb4a46b692b23fbf74 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputCustomKeyboardPage6Test.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 TextInputCustomKeyboardPage6Test { + PAGE_TAG: string = 'TextInputCustomKeyboardPage6Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputCustomKeyboardPage6Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputEnableAutoFillTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputEnableAutoFillTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3f285a22953c33832fbeb81a66aa5eb345496d7 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputEnableAutoFillTest.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 TextInputEnableAutoFillTest { + PAGE_TAG: string = 'TextInputEnableAutoFillTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputEnableAutoFillTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc6fc32348034b274589f8e47f3a24b3a0de487 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage1Test.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 TextInputFontFeaturePage1Test { + PAGE_TAG: string = 'TextInputFontFeaturePage1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputFontFeaturePage1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ac276d90865b7b868c6b237d5e69251aa9fa406a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage2Test.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 TextInputFontFeaturePage2Test { + PAGE_TAG: string = 'TextInputFontFeaturePage2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputFontFeaturePage2Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage3Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage3Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5147df2640abe9139562ca98adc79d5742bc8656 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputFontFeaturePage3Test.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 TextInputFontFeaturePage3Test { + PAGE_TAG: string = 'TextInputFontFeaturePage3Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputFontFeaturePage3Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputGetCaretOffsetTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputGetCaretOffsetTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..44a73b87d5acec5e77bb1d52505d1b5910a51f76 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputGetCaretOffsetTest.ets @@ -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. + */ +import render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct TextInputGetCaretOffsetTest { + PAGE_TAG: string = 'TextInputGetCaretOffsetTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputGetCaretOffsetTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputInputFilterTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputInputFilterTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..d27fadbebecd5a434b0d756568cb9e0f77928077 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputInputFilterTest.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 TextInputInputFilterTest { + PAGE_TAG: string = 'TextInputInputFilterTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputInputFilterTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputMaxLinesTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputMaxLinesTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..415daf9db70bc33c4b5ea4a662bed4e681bed852 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputMaxLinesTest.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 TextInputMaxLinesTest { + PAGE_TAG: string = 'TextInputMaxLinesTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputMaxLinesTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputMinFontSizeAndMaxFontSizeTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputMinFontSizeAndMaxFontSizeTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..a6ae3c4385630c00fa7f9d3e9f3c30e621965bf1 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputMinFontSizeAndMaxFontSizeTest.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 TextInputMinFontSizeAndMaxFontSizeTest { + PAGE_TAG: string = 'TextInputMinFontSizeAndMaxFontSizeTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputMinFontSizeAndMaxFontSizeTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputNumberOfLinesTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputNumberOfLinesTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e9522b848e9763a81d3c148155226ac581ef52e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputNumberOfLinesTest.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 TextInputNumberOfLinesTest { + PAGE_TAG: string = 'TextInputNumberOfLinesTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputNumberOfLinesTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage1Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage1Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd014578852e3819c041691d3cedd06a806e9f54 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage1Test.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 TextInputPasswordRulesPage1Test { + PAGE_TAG: string = 'TextInputPasswordRulesPage1Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputPasswordRulesPage1Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage2Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage2Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b90944499b1a69f567f9110f780a605bd8364b83 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage2Test.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 TextInputPasswordRulesPage2Test { + PAGE_TAG: string = 'TextInputPasswordRulesPage2Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputPasswordRulesPage2Test(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage3Test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage3Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c6b301388ddb0377eca7603055f81b8fe7c65a50 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputPasswordRulesPage3Test.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 TextInputPasswordRulesPage3Test { + PAGE_TAG: string = 'TextInputPasswordRulesPage3Test'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputPasswordRulesPage3Test(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSelectAllTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSelectAllTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..20abfa95b365a5c77a46bb73546f84493a896622 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSelectAllTest.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 TextInputSelectAllTest { + PAGE_TAG: string = 'TextInputSelectAllTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputSelectAllTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSelectionMenuHiddenTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSelectionMenuHiddenTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d96c073008037c9346a0928757befeabe084133 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSelectionMenuHiddenTest.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 TextInputSelectionMenuHiddenTest { + PAGE_TAG: string = 'TextInputSelectionMenuHiddenTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputSelectionMenuHiddenTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSetTextSelectionTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSetTextSelectionTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..34fe92586c686efc4687bc91ae0df590b3a14c6a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputSetTextSelectionTest.ets @@ -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. + */ +import render from 'libnativerender.so' +import { CommonView } from '../../componet/CommonView'; + +@Entry +@Component +struct TextInputSetTextSelectionTest { + PAGE_TAG: string = 'TextInputSetTextSelectionTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputSetTextSelectionTest(this.PAGE_TAG); + }) + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputShowKeyboardOnFocusAbnormalTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputShowKeyboardOnFocusAbnormalTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..06b4bf7c8aea8e383d3adacb7da0f0bad6628843 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputShowKeyboardOnFocusAbnormalTest.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 TextInputShowKeyboardOnFocusAbnormalTest { + PAGE_TAG: string = 'TextInputShowKeyboardOnFocusAbnormalTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputShowKeyboardOnFocusAbnormalTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputShowKeyboardOnFocusTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputShowKeyboardOnFocusTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d433742d185c867d2d1d93b1cd2dad265f8bc8e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputShowKeyboardOnFocusTest.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 TextInputShowKeyboardOnFocusTest { + PAGE_TAG: string = 'TextInputShowKeyboardOnFocusTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputShowKeyboardOnFocusTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputStyleTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputStyleTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..dda2de23ffdb7a0862e4c2faddc2b5359df9a415 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputStyleTest.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 TextInputStyleTest { + PAGE_TAG: string = 'TextInputStyleTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputStyleTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputTextPlaceholderTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputTextPlaceholderTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..4cd2d9d9df3279eb3e76660b7e71354a97ca1174 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputTextPlaceholderTest.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 TextInputTextPlaceholderTest { + PAGE_TAG: string = 'TextInputTextPlaceholderTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputTextPlaceholderTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputUnderlineColorTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputUnderlineColorTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c53097032f139a6ece941929a3090f8995a3158c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputUnderlineColorTest.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 TextInputUnderlineColorTest { + PAGE_TAG: string = 'TextInputUnderlineColorTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputUnderlineColorTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputWordBreakTest.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputWordBreakTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2ee7363eea443c42882bea499811a5322b6eaeb --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/MainAbility/pages/textinput/TextInputWordBreakTest.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 TextInputWordBreakTest { + PAGE_TAG: string = 'TextInputWordBreakTest'; + + build() { + Column() { + CommonView({ + pageTag: this.PAGE_TAG, + }).onAppear(() => { + render.textInputWordBreakTest(this.PAGE_TAG); + }) + } + } +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6c9fd29e4072773009d070875cb872909c203e5d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/List.test.ets @@ -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 textInputCustomKeyboardTest from './textinput/TextInputCustomKeyboardTest.test' +import textInputEnableAutoFillTest from './textinput/TextInputEnableAutoFillTest.test' +import textInputContentTypeTest from './textinput/TextInputContentTypeTest.test' +import textInputPasswordRulesTest from './textinput/TextInputPasswordRulesTest.test' +import textInputSelectAllTest from './textinput/TextInputSelectAllTest.test' +import textInputSelectionMenuHiddenTest from './textinput/TextInputSelectionMenuHiddenTest.test' +import textInputFontFeatureTest from './textinput/TextInputFontFeatureTest.test' +import textInputTextPlaceholderTest from './textinput/TextInputTextPlaceholderTest.test' +import textInputCancelButtonTest from './textinput/TextInputCancelButtonTest.test' +import textInputSetTextSelectionTest from './textinput/TextInputSetTextSelectionTest.test' +import textInputUnderlineColorTest from './textinput/TextInputUnderlineColorTest.test' +import textInputWordBreakTest from './textinput/TextInputWordBreakTest.test' +import textInputStyleTest from './textinput/TextInputStyleTest.test' +import textInputMinFontSizeAndMaxFontSizeTest from './textinput/TextInputMinFontSizeAndMaxFontSizeTest.test' +import textInputMaxLinesTest from './textinput/TextInputMaxLinesTest.test' +import textInputNumberOfLinesTest from './textinput/TextInputNumberOfLinesTest.test' +import textInputInputFilterTest from './textinput/TextInputInputFilterTest.test' +import textInputShowKeyboardOnFocusTest from './textinput/TextInputShowKeyboardOnFocusTest.test' +import textInputBlurOnSubmitTest from './textinput/TextInputBlurOnSubmitTest.test' +import textInputGetCaretOffsetTest from './textinput/TextInputGetCaretOffsetTest.test' +import textInputCaretPositionTest from './textinput/TextInputCaretPositionTest.test' +import textInputControllerTest from './textinput/TextInputControllerTest.test' + +export default function testsuite() { + textInputCustomKeyboardTest() + textInputSelectAllTest() + textInputEnableAutoFillTest() + textInputContentTypeTest() + textInputPasswordRulesTest() + textInputSelectionMenuHiddenTest() + textInputFontFeatureTest() + textInputTextPlaceholderTest() + textInputCancelButtonTest() + textInputSetTextSelectionTest() + textInputUnderlineColorTest() + textInputWordBreakTest() + textInputStyleTest() + textInputMinFontSizeAndMaxFontSizeTest() + textInputMaxLinesTest() + textInputNumberOfLinesTest() + textInputInputFilterTest() + textInputShowKeyboardOnFocusTest() + textInputBlurOnSubmitTest() + textInputGetCaretOffsetTest() + textInputCaretPositionTest() + textInputControllerTest() +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d2e942f4a238e9c6cce0f4b752699a8c622663e3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Interfaces.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class ComponentInfo { + $type: string; + $rect: Object[]; +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts new file mode 100644 index 0000000000000000000000000000000000000000..f92fa6f417dd13fe3ea3699af14531d1c3e82c82 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Settings.ts @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// import screen from '@ohos.screen'; +import window from '@ohos.window'; + +const TAG: string = '[SettingsCApiDemo]' + +class Settings { + sleep(time) { + return new Promise((resolve) => { + setTimeout(resolve, time) + }); + } + + windowClass: window.Window = null + + //为悬浮窗设置位置 + changeWindowPosition(windowClass, X, Y) { + windowClass.moveWindowTo(X, Y, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to move the window. Cause: ${JSON.stringify(err)}`); + return; + } + }) + } + + //为悬浮窗设置大小 + changeWindowSize(windowClass, width, height) { + windowClass.resize(width, height, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to change the window size. Cause: ${JSON.stringify(err)}`); + return; + } + }) + } + + loadContent(windowClass, pageURI) { + //为悬浮窗加载对应的目标页面 + windowClass.setUIContent(pageURI, (err) => { + if (err.code) { + console.error(`${TAG}, Fail to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in loading the content.`); + + //显示悬浮窗 + windowClass.showWindow((err) => { + if (err.code) { + console.error(`${TAG}, Fail to show the window. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in showing the window.`); + }) + + }) + } + + // changeDpi(dpi) { + // let screenClass = null; + // screen.getAllScreens((err, data) => { + // if (err.code) { + // console.error(`${TAG}, Fail to get all screens. Cause: ${JSON.stringify(err)}`); + // return; + // } + // console.info(`${TAG}, Succeeded in geting all screens.`); + // + // screenClass = data[0]; + // //设置设备dpi + // screenClass.setDensityDpi(dpi, (err, data) => { + // if (err.code) { + // console.error(`${TAG}, Fail to set the piexl density. Cause: ${JSON.stringify(err)}`); + // return; + // } + // console.info(`${TAG}, Succeeded in seting the piexl density.`) + // }) + // }) + // } + + destroyWindow() { + //销毁窗口 + let windowClass = null; + try { + windowClass = window.findWindow('floatWindow'); + console.info(`${TAG}, find window success.`) + } catch (exception) { + console.error(`${TAG}, Fail to find the window. Cause: ${JSON.stringify(exception)}`); + } + windowClass.destroyWindow((err) => { + if (err.code) { + console.error(`${TAG}, Fail to destroy the window. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in destroying the window.`) + }) + } + + createWindow(pageURI: String, {X=0,Y=0,width=1344,height=2560,dpi=400}={}) { + console.info(`${TAG}, params, pageURI=${pageURI}}, X=${X}, Y=${Y}, width=${width}, height=${height}, dpi=${dpi}`) + + // this.changeDpi(dpi); + this.sleep(1000); + let windowClass = null; + let config = { + name: 'floatWindow', windowType: window.WindowType.TYPE_FLOAT, ctx: globalThis.context + } + window.createWindow(config, (err, data) => { + if (err.code) { + console.error(`${TAG}, Fail to create the floatWindow. Cause: ${JSON.stringify(err)}`); + return; + } + console.info(`${TAG}, Succeeded in creating the floatWindow.`) + windowClass = data; + this.windowClass = data; + + this.changeWindowPosition(windowClass, X, Y) + this.changeWindowSize(windowClass, width, height) + this.loadContent(windowClass, pageURI) + }) + } +} + +export default new Settings() \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts new file mode 100644 index 0000000000000000000000000000000000000000..c2d92270475c072bd61a22931f6b281a030ac5dc --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Snap.ts @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import window from '@ohos.window'; +import image from '@ohos.multimedia.image'; +import fs from '@ohos.file.fs'; +import { Driver, Rect } from '@ohos.UiTest'; + +const TAG: string = '[WindowSnap]' +const INFO = { + 'img': { + prefix: 'IMG_', + suffix: '.webp' + }, + 'txt': { + prefix: 'TXT_', + suffix: '.txt' + } +} + +class WindowSnap { + async sleep(time) { + return new Promise((resolve) => { + setTimeout(resolve, time) + }); + } + + createFile(context: any, type, page) { + console.info(`${TAG}, createFile start`) + let pathDir = context.filesDir; + console.info(`${TAG}, createFile pathDir = ${pathDir}`) + let name = page + let info = INFO[type] + let displayName = `${info.prefix}${name}${info.suffix}` + let filePath = pathDir + '/' + displayName + console.info(`${TAG}, createFile filePath = ${filePath}`) + let exists = fs.accessSync(filePath) + console.info(`${TAG}, oldFile exists = ${exists}`) + if (exists) { + fs.unlinkSync(filePath) + console.info(`${TAG}, remove file succeed`) + } + return fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) + } + + async save(data: image.PixelMap, context: any, page) { + console.info(`${TAG}, start save image`) + let packOpts: image.PackingOption = { + format: 'image/webp', quality: 100 + } + let imagePackerApi = image.createImagePacker() + let arrayBuffer = await imagePackerApi.packing(data, packOpts) + let file = null + while (file == null) { + file = this.createFile(context, 'img', page) + } + let exists = fs.accessSync(file.path) + console.info(`${TAG}, createFile exists = ${exists}`) + let fd = file.fd + console.info(`${TAG}, createFile fd = ${fd}`) + imagePackerApi.release() + try { + fs.writeSync(fd, arrayBuffer) + } catch (err) { + console.error(`${TAG}, write failed, code is ${err.code}, message is ${err.message}}`) + } + fs.closeSync(file) + console.info(`${TAG}, write picture done`) + } + + /** + * 获取窗口截图&文件保存 + * 入参必须为ability的context + * + * save:设备保存路径:/data/app/el2/100/base/{bundle_name}/haps/entry_test/files/IMG_test.webp + */ + async snapShot(context, page, done?) { + console.info(`${TAG}, start snapshot`) + await this.sleep(2000); + let windowClass = null + try { + windowClass = window.findWindow('floatWindow') + console.info(`${TAG}, find window success`) + } catch (exception) { + console.error(`${TAG}, Failed to find the window. Cause: ${JSON.stringify(exception)}`) + } + + windowClass.snapshot(async (err, data) => { + console.info(`${TAG}, windowClass.snapshot`) + if (err.code) { + console.error(`${TAG}, Failed to snapshot window. Cause: ${JSON.stringify(err)}`) + return + } + await this.save(data, context, page) + data.release() + if (done) { + done(); + } + }) + } + + async snapShotNext(context, page, done?) { + console.info(`${TAG}, start snapshot`) + let windowClass = null + try { + windowClass = window.findWindow('floatWindow'); + } catch (exception) { + console.error(`${TAG}, Failed to find the window. Cause: ${JSON.stringify(exception)}`) + } + await this.sleep(600); + windowClass.snapshot(async (err, data) => { + console.info(`${TAG}, windowClass.snapshot`) + + if (err.code) { + console.error(`${TAG}, Failed to snapshot window. Cause: ${JSON.stringify(err)}`) + return + } + await this.save(data, context, page) + data.release() + if (done) { + done(); + } + }) + } + + async snapShotByDriver(context, page, done?) { + console.info(`Start snapshot by driver`) + await this.sleep(2000); + let file = null + while (file == null) { + file = this.createFile(context, 'img', page) + } + let exists = fs.accessSync(file.path) + console.info(`${TAG}, createFile exists = ${exists}`) + + try { + let windowClass = window.findWindow('floatWindow') + console.info(`${TAG}, find window success`) + let windowRect = windowClass.getWindowProperties().windowRect; + console.info(`${TAG}, windowRct is ${JSON.stringify(windowRect)}`) + let driver = Driver.create(); + await driver.screenCapture(file.path, { + left: windowRect.left, + top: windowRect.top, + right: windowRect.width, + bottom: windowRect.height + }); + } catch (exception) { + console.error(`${TAG}, Failed to snap shot. Cause: ${JSON.stringify(exception)}`) + } + + if (done) { + done(); + } + } +} + +export default new WindowSnap() \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..0de7823510a15bd718a457a592c6f4f29d4c2d3d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/common/Utils.ets @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import events_emitter from '@ohos.events.emitter'; +import { Driver, ON, PointerMatrix, Rect } from '@ohos.UiTest'; +import { ComponentInfo } from './Interfaces'; +import systemDateTime from '@ohos.systemDateTime'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry' +import fs from '@ohos.file.fs'; +import router from '@ohos.router'; + +export default class Utils { + static sleep(time: number) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve("ok") + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getSystemTime() { + return systemDateTime.getTime(true) / 1000 + } + + static getSandboxFileDir() { + let sandboxFileDir = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext().filesDir + "/" + console.log(`[getSandboxFileDir] return ${sandboxFileDir}`); + return sandboxFileDir; + } + + static deleteFile(filePath: string) { + console.info("[deleteFile] filePath:" + filePath); + try { + fs.unlinkSync(filePath) + } catch (error) { + console.info("[deleteFile] error:" + error); + } + } + + static isFileExist(filePath: string): boolean { + console.info("[isFileExist] filePath:" + filePath); + try { + let fileExist = fs.accessSync(filePath) + console.info("[isFileExist] return:" + fileExist); + return fileExist + } catch (error) { + console.info("[isFileExist] error:" + error); + return false + } + } + + static getComponentInfoByKey(key: string): ComponentInfo { + let strJson = getInspectorByKey(key); + let obj: ComponentInfo = JSON.parse(strJson); + console.info('[getInspectorByKey] current component info: ' + JSON.stringify(obj)); + return obj; + } + + + static async flingComponent(key: string, isHorizontal: boolean, isForward: boolean) { + let driver = Driver.create(); + let rect = Utils.getComponentRect(key); + let centerX = Utils.getRectHorizontalCenterX(rect) + let centerY = Utils.getRectVerticalCenterY(rect) + let X1 = centerX - 100; + let X2 = centerX + 100; + let Y1 = centerY - 100; + let Y2 = centerY + 100; + let stepLen = 20; + let speed = 10000; + if (isHorizontal) { + if (isForward) { + await driver.fling({ + x: X2, y: centerY + }, { + x: X1, y: centerY + }, stepLen, speed); + } else { + await driver.fling({ + x: X1, y: centerY + }, { + x: X2, y: centerY + }, stepLen, speed); + } + } else { + if (isForward) { + await driver.fling({ + x: centerX, y: Y2 + }, { + x: centerX, y: Y1 + }, stepLen, speed); + } else { + await driver.fling({ + x: centerX, y: Y1 + }, { + x: centerX, y: Y2 + }, stepLen, speed); + } + } + } + + static async clickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.click(); + } + + static async doubleClickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.click(); + await component.click(); + } + + static async clickLocation(X: number, Y: number) { + let driver = Driver.create(); + await driver.click(X, Y); + } + + static async triggerKey(id: number) { + let driver = Driver.create(); + await driver.triggerKey(id); + } + + static async longClickComponent(id: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(id)); + await component.longClick(); + } + + static async clickComponentByText(text: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.text(text)); + await component.click(); + } + + static async fingerZoom(key: string, isOut: boolean) { + let rect = Utils.getComponentRect(key); + let centerX = Utils.getRectHorizontalCenterX(rect) + let centerY = Utils.getRectVerticalCenterY(rect) + let fingerUpCenterY = centerY - 100; + let fingerDownCenterY = centerY + 100; + let driver: Driver = Driver.create(); + let pointers: PointerMatrix = PointerMatrix.create(2, 3); + pointers.setPoint(0, 0, { + x: centerX, y: fingerUpCenterY - (isOut ? 40 : 120) + }); + pointers.setPoint(0, 1, { + x: centerX, y: fingerUpCenterY - 80 + }); + pointers.setPoint(0, 2, { + x: centerX, y: fingerUpCenterY - (isOut ? 120 : 40) + }); + pointers.setPoint(1, 0, { + x: centerX, y: fingerDownCenterY + (isOut ? 40 : 120) + }); + pointers.setPoint(1, 1, { + x: centerX, y: fingerDownCenterY + 80 + }); + pointers.setPoint(1, 2, { + x: centerX, y: fingerDownCenterY + (isOut ? 120 : 40) + }); + await driver.injectMultiPointerAction(pointers); + } + + static registerEvent(pageTag: string, eventId: number, callBack: Function) { + events_emitter.on({ + eventId: eventId, + priority: events_emitter.EventPriority.LOW + }, (eventData: events_emitter.EventData) => { + console.info("Value Change CallBack"); + if (eventData != null && eventData.data != null) { + if (pageTag == eventData.data.PAGE_TAG) { + console.info("CallBack value:" + JSON.stringify(eventData)); + callBack(eventData.data.VALUE); + } + } + }) + } + + static emitEvent(pageTag: string, emitValue: number | string | object, eventId: number) { + try { + let backData: events_emitter.EventData = { + data: { + "PAGE_TAG": pageTag, + "VALUE": emitValue + } + } + let backEvent: events_emitter.InnerEvent = { + eventId: eventId, + priority: events_emitter.EventPriority.LOW + } + console.info("start to emit page state"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("emit page state err: " + JSON.stringify(err)); + } + } + + static async pushPage(pageTag: string, done?: Function) { + let options: router.RouterOptions = { + url: `MainAbility/pages/${pageTag}`, + } + try { + router.clear(); + let pages = router.getState(); + console.info(`get ${pageTag} state success ` + JSON.stringify(pages)); + if (pageTag.indexOf(pages.name) < 0) { + console.info(`get ${pageTag} state success ` + JSON.stringify(pages.name)); + let result = await router.pushUrl(options); + await Utils.sleep(2000); + console.info(`push ${pageTag} page success ` + JSON.stringify(result)); + } + } catch (err) { + console.error(`push ${pageTag} page error: ` + err); + } + if (done) { + done(); + } + } + + static getComponentRect(key: string): Rect { + let strJson = getInspectorByKey(key); + let obj: ComponentInfo = JSON.parse(strJson); + console.info('[getInspectorByKey] key is: ' + key); + return Utils.getComponentRectByObj(obj); + } + + static getComponentRectByObj(obj: ComponentInfo): Rect { + console.info('[getInspectorByKey] current component is: ' + obj.$type); + let rectInfo: Object[] = JSON.parse('[' + obj.$rect + ']'); + let rect_value: Rect = { + left: JSON.parse('[' + rectInfo[0] + ']')[0], + top: JSON.parse('[' + rectInfo[0] + ']')[1], + right: JSON.parse('[' + rectInfo[1] + ']')[0], + bottom: JSON.parse('[' + rectInfo[1] + ']')[1] + }; + console.info(JSON.stringify(rect_value)); + return rect_value; + } + + static getRectHorizontalCenterX(rect: Rect): number { + return Number.parseInt(Number((rect.right - rect.left) / 2 + rect.left).toFixed(0)); + } + + static getRectVerticalCenterY(rect: Rect): number { + return Number.parseInt(Number((rect.bottom - rect.top) / 2 + rect.top).toFixed(0)); + } + + static async mouseMoveTo(X: number, Y: number) { + let driver = Driver.create(); + await driver.mouseMoveTo({ + x: X, y: Y + }); + } + + static async mouseMoveToCurrentComponent(componentId: string) { + let driver = Driver.create(); + let component = await driver.findComponent(ON.id(componentId)); + let point = await component.getBounds(); + await driver.mouseMoveTo({ + x: point.left + 10, y: point.bottom - 10 + }); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputBlurOnSubmitTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputBlurOnSubmitTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..83cf20bbf94bca0fc16ae6d95df8083df57dc534 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputBlurOnSubmitTest.test.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, beforeAll } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputBlurOnSubmitTest() { + + describe('TextInputBlurOnSubmitTest', () => { + + let PAGE_TAG = 'TextInputBlurOnSubmitTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + + it('testTextInputBlurOnSubmitTest001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('OnSubmitTestTextInput') + await Utils.sleep(2000) + await Utils.triggerKey(2054) + await Utils.sleep(200) + done(); + }) + + + it('testTextInputBlurOnSubmitTest002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('OnSubmitTestTextInputCompare') + await Utils.sleep(2000) + await Utils.triggerKey(2054) + await Utils.sleep(200) + done(); + }) + + it('testTextInputBlurOnSubmitTest003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('OnSubmitTestTextInputAbnormal') + await Utils.sleep(2000) + await Utils.triggerKey(2054) + await Utils.sleep(200) + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCancelButtonTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCancelButtonTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..379b2dfc27fb10dd3e9431b55acabc4c4f0a6fa4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCancelButtonTest.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputCancelButtonTest() { + + describe('TextInputCancelButtonTest', () => { + + let PAGE_TAG = 'TextInputCancelButtonTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputCancelButton001', 0, async (done: Function) => { + done() + }) + + it('testTextInputCancelButton002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('textInput1') + await Utils.sleep(1000) + await Utils.clickComponent("textInput1"); + await Utils.triggerKey(2049) + await Utils.triggerKey(2054) + await Utils.sleep(1000) + done(); + }) + + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCaretPositionTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCaretPositionTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..94401d07aab201db5ee60dffc502fe4f03c7cd23 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCaretPositionTest.test.ets @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputCaretPositionTest() { + + describe('TextInputCaretPositionTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputCaretPosition001', 0, async (done: Function) => { + let PAGE_TAG = 'TextInputCaretPositionTest'; + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("textInput1"); + await Utils.clickComponent("textInput1"); + await Utils.clickComponent("TextInputCaretPositionTest_buttonId1"); + done(); + }) + + it('testTextInputCaretPosition002', 0, async (done: Function) => { + let PAGE_TAG = 'TextInputCaretPositionTest'; + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("textInput1"); + await Utils.clickComponent("textInput1"); + await Utils.clickComponent("TextInputCaretPositionTest_buttonId2"); + done(); + }) + + it('testTextInputCaretPosition003', 0, async (done: Function) => { + let PAGE_TAG = 'TextInputCaretPositionTest'; + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("textInput1"); + await Utils.clickComponent("TextInputCaretPositionTest_buttonId3"); + done(); + }) + + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputContentTypeTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputContentTypeTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a169c67947aa64ca209aab2a951ebd5a68a1aa76 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputContentTypeTest.test.ets @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputContentTypeTest() { + + describe('TextInputContentTypeTest', () => { + let PAGE_TAG_1 = 'TextInputContentTypePage1Test'; + let PAGE_TAG_2 = 'TextInputContentTypePage2Test'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputContentType001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType006', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput6"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType007', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput7"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType008', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput8"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType009', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput9"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType010', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput10"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType011', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput11"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType012', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput12"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType013', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType014', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType015', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType016', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType017', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType018', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput6"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType019', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput7"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType020', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput8"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType021', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput9"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType022', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput10"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType023', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput11"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputContentType024', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput12"); + await Utils.sleep(2000); + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputControllerTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputControllerTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6cc8b13e79cc1a157a976ac48ae0f8a9fff8b5c4 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputControllerTest.test.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { FocusController } from '@ohos.arkui.UIContext'; + +export default function textInputControllerTest() { + + describe('TextInputControllerTest', () => { + + let PAGE_TAG = 'TextInputControllerTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputController001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + await Utils.clickComponent("TextInputControllerTest_button_id"); + await Utils.sleep(1000) + done() + }) + + it('testTextInputController002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("TextInputControllerTest_textInput_id"); + await Utils.sleep(1000) + await Utils.clickComponent("TextInputControllerTest_button_id"); + await Utils.sleep(1000) + done() + }) + + it('testTextInputController003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("TextInputControllerTest_textInput_id"); + await Utils.sleep(1000) + await Utils.clickComponent("TextInputControllerTest_button_id2"); + await Utils.sleep(1000) + await Utils.clickComponent("TextInputControllerTest_button_id"); + await Utils.sleep(1000) + done() + }) + + it('testTextInputController004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("TextInputControllerTest_textInput_id"); + await Utils.sleep(1000) + await Utils.clickComponent("TextInputControllerTest_button_id2"); + await Utils.sleep(1000) + await Utils.triggerKey(2049) + await Utils.sleep(1000) + await Utils.clickComponent("TextInputControllerTest_button_id"); + await Utils.sleep(1000) + done() + }) + + + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCustomKeyboardTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCustomKeyboardTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2be5651a3223c3358f8a82b421d5750a17a1542 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputCustomKeyboardTest.test.ets @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputCustomKeyboardTest() { + + describe('TextInputCustomKeyboardTest', () => { + let PAGE_TAG_1 = 'TextInputCustomKeyboardPage1Test'; + let PAGE_TAG_2 = 'TextInputCustomKeyboardPage2Test'; + let PAGE_TAG_3 = 'TextInputCustomKeyboardPage3Test'; + let PAGE_TAG_4 = 'TextInputCustomKeyboardPage4Test'; + let PAGE_TAG_5 = 'TextInputCustomKeyboardPage5Test'; + let PAGE_TAG_6 = 'TextInputCustomKeyboardPage6Test'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + // 点击textInput,不支持避让效果 + it('testTextInputCustomKeyboard001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + // 点击textInput,支持避让效果 + it('testTextInputCustomKeyboard002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + // 测试是否会拦截手势事件 + it('testTextInputCustomKeyboard003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + await Utils.clickComponent("button1"); + await Utils.sleep(2000); + done() + }) + + // 测试输入控件失去焦点时,是否关闭自定义键盘 + it('testTextInputCustomKeyboard004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_4}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + await Utils.clickComponent("button"); + await Utils.sleep(2000); + done() + }) + + // 测试通过TextInputController.stopEditing方法控制键盘关闭,是否关闭自定义键盘 + it('testTextInputCustomKeyboard005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_5}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + await Utils.clickComponent("button1"); + await Utils.sleep(2000); + done() + }) + + // 测试resetAttribute + it('testTextInputCustomKeyboard006', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_6}`); + await Utils.clickComponent("textInput6"); + await Utils.sleep(2000); + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputEnableAutoFillTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputEnableAutoFillTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..aef42b0f8b36168bf55a295ef813ced710acc160 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputEnableAutoFillTest.test.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputEnableAutoFillTest() { + + describe('TextInputEnableAutoFillTest', () => { + let PAGE_TAG = 'TextInputEnableAutoFillTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputEnableAutoFill001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputEnableAutoFill002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputEnableAutoFill003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputEnableAutoFill004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputEnableAutoFill005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputFontFeatureTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputFontFeatureTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..76ef5de01f6fc5926073c297343c82dbb56f1664 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputFontFeatureTest.test.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputFontFeatureTest() { + + describe('TextInputFontFeatureTest', () => { + let PAGE_TAG_1 = 'TextInputFontFeaturePage1Test'; + let PAGE_TAG_2 = 'TextInputFontFeaturePage2Test'; + let PAGE_TAG_3 = 'TextInputFontFeaturePage3Test'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputFontFeature001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`, done); + done() + }) + + it('testTextInputFontFeature002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`, done); + done() + }) + + it('testTextInputFontFeature003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`, done); + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputGetCaretOffsetTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputGetCaretOffsetTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5f2a584aeec8f39e32e80d37a231bc107c195a6 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputGetCaretOffsetTest.test.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 { describe, it, afterEach, beforeAll } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputGetCaretOffsetTest() { + + describe('TextInputGetCaretOffsetTest', () => { + + let PAGE_TAG = 'TextInputGetCaretOffsetTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputGetCaretOffset001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("TextInputGetCaretOffsetTest_textInput_id1"); + await Utils.sleep(1000) + await Utils.triggerKey(2049); + done(); + }) + + it('testTextInputGetCaretOffset002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus("TextInputGetCaretOffsetTest_textInput_id1"); + await Utils.triggerKey(2024); + await Utils.sleep(2000) + done(); + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputInputFilterTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputInputFilterTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d6f7a14384fe2f3024eb4b06aa96bb85c887615 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputInputFilterTest.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 { describe, it, afterEach } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputInputFilterTest() { + + describe('TextInputInputFilterTest', () => { + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputInputFilter001', 0, async (done: Function) => { + let PAGE_TAG = 'TextInputInputFilterTest'; + await Utils.pushPage(`textinput/${PAGE_TAG}`); + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputMaxLinesTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputMaxLinesTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..afb16149c45a8c4bda34030f555de4861150e3ca --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputMaxLinesTest.test.ets @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, beforeAll } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputMaxLinesTest() { + + describe('TextInputMaxLinesTest', () => { + let PAGE_TAG = 'TextInputMaxLinesTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputMaxLinesTest001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('normal') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputMaxLinesTest002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('negative') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputMaxLinesTest003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('large') + await Utils.sleep(1000) + done(); + }) + it('testTextInputMaxLinesTest004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('normalTwo') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputMaxLinesTest005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('negativeTwo') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputMaxLinesTest006', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('largeTwo') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputMaxLinesTest007', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('reset') + await Utils.sleep(1000) + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputMinFontSizeAndMaxFontSizeTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputMinFontSizeAndMaxFontSizeTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4310673eae75f1416370bc8e7622abdce910fd6a --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputMinFontSizeAndMaxFontSizeTest.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 textInputMinFontSizeAndMaxFontSizeTest() { + + describe('TextInputMinFontSizeAndMaxFontSizeTest', () => { + + let PAGE_TAG = 'TextInputMinFontSizeAndMaxFontSizeTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputMinFontSizeAndMaxFontSize001', 0, async (done: Function) => { + done() + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputNumberOfLinesTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputNumberOfLinesTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..46cf69145230813503d0fa3a831614ccb3cfd26b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputNumberOfLinesTest.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 textInputNumberOfLinesTest() { + + describe('TextInputNumberOfLinesTest', () => { + + let PAGE_TAG = 'TextInputNumberOfLinesTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputNumberOfLines001', 0, async (done: Function) => { + done() + }) + + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputPasswordRulesTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputPasswordRulesTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e7af2fcc5f95f766821ee0507af3072eda6456e --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputPasswordRulesTest.test.ets @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputPasswordRulesTest() { + + describe('TextInputPasswordRulesTest', () => { + let PAGE_TAG_1 = 'TextInputPasswordRulesPage1Test'; + let PAGE_TAG_2 = 'TextInputPasswordRulesPage2Test'; + let PAGE_TAG_3 = 'TextInputPasswordRulesPage3Test'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputPasswordRules001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules006', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput6"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules007', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput7"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules008', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput8"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules009', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput9"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules010', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput10"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules011', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput11"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules012', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_1}`); + await Utils.clickComponent("textInput12"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules013', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules014', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules015', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules016', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules017', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules018', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput6"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules019', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput7"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules020', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput8"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules021', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput9"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules022', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput10"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules023', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput11"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules024', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_2}`); + await Utils.clickComponent("textInput12"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules025', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`); + await Utils.clickComponent("textInput1"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules026', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`); + await Utils.clickComponent("textInput2"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules027', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`); + await Utils.clickComponent("textInput3"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules028', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`); + await Utils.clickComponent("textInput4"); + await Utils.sleep(2000); + done() + }) + + it('testTextInputPasswordRules029', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_3}`); + await Utils.clickComponent("textInput5"); + await Utils.sleep(2000); + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSelectAllTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSelectAllTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f3a6e7e499621668e3f110ba3ad2481301cf86d --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSelectAllTest.test.ets @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputSelectAllTest() { + + describe('TextInputSelectAllTest', () => { + let PAGE_TAG = 'TextInputSelectAllTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done); + }); + + // TextInput组件selectAll参数设置为1时的显示效果测试 + it('testTextInputSelectAll001', 0, async (done: Function) => { + await focusControl.requestFocus('textInput1') + await Utils.sleep(2000) + done(); + }); + + // TextInput组件selectAll参数设置为0时的显示效果测试 + it('testTextInputSelectAll002', 0, async (done: Function) => { + await focusControl.requestFocus('textInput2') + await Utils.sleep(2000) + done(); + }); + + // TextInput组件selectAll参数设置为-1时的显示效果测试 + it('testTextInputSelectAll003', 0, async (done: Function) => { + await focusControl.requestFocus('textInput3') + await Utils.sleep(2000) + done(); + }); + + // TextInput组件selectAll参数设置为1,内容为超长文本时的显示效果测试 + it('testTextInputSelectAll004', 0, async (done: Function) => { + await focusControl.requestFocus('textInput4') + await Utils.sleep(2000) + done(); + }); + + // TextInput组件selectAll参数设置为1,内容为空时的显示效果测试 + it('testTextInputSelectAll005', 0, async (done: Function) => { + await focusControl.requestFocus('textInput5') + await Utils.sleep(2000) + done(); + }); + + // TextInput组件resetAttribute selectAll + it('testTextInputSelectAll006', 0, async (done: Function) => { + await focusControl.requestFocus('textInput6') + await Utils.sleep(2000) + done(); + }); + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSelectionMenuHiddenTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSelectionMenuHiddenTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..48178bd37b56a4bd43b9d625bf4b483525fd56d3 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSelectionMenuHiddenTest.test.ets @@ -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. + */ + +import { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; +import { Driver, ON, Component, MouseButton } from '@ohos.UiTest'; + +// 点击光标 +async function click(id: string, done: Function) { + let driver: Driver = Driver.create(); + let component: Component = await driver.findComponent(ON.id(id)); + await component.click(); + await Utils.sleep(1000); + await component.click(); +} + +// 双击 +async function doubleClick(id: string, done: Function) { + let driver: Driver = Driver.create(); + let component: Component = await driver.findComponent(ON.id(id)); + await component.click(); + await component.click(); +} + +// 长按 +async function longClick(id: string, done: Function) { + let driver: Driver = Driver.create(); + let component: Component = await driver.findComponent(ON.id(id)); + await component.longClick(); +} + +// 右键点击 +async function rightClick(id: string, done: Function) { + let driver: Driver = Driver.create(); + let component: Component = await driver.findComponent(ON.id(id)); + let point = await component.getBoundsCenter(); + await driver.mouseClick(point, MouseButton.MOUSE_BUTTON_RIGHT); +} + +// 三击 +async function threeClick(id: string, done: Function) { + let driver: Driver = Driver.create(); + let component: Component = await driver.findComponent(ON.id(id)); + await component.click(); + await component.click(); + await component.click(); +} + +export default function textInputSelectionMenuHiddenTest() { + + describe('TextInputSelectionMenuHiddenTest', () => { + let PAGE_TAG = 'TextInputSelectionMenuHiddenTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + // 点击效果 + it('testTextInputSelectionMenuHidden001', 0, async (done: Function) => { + await click("textInput1", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden002', 0, async (done: Function) => { + await click("textInput2", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden003', 0, async (done: Function) => { + await click("textInput3", done); + await Utils.sleep(1000) + done() + }) + + // 双击效果 + it('testTextInputSelectionMenuHidden004', 0, async (done: Function) => { + await doubleClick("textInput1", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden005', 0, async (done: Function) => { + await doubleClick("textInput2", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden006', 0, async (done: Function) => { + await doubleClick("textInput3", done); + await Utils.sleep(1000) + done() + }) + + // 长按效果 + it('testTextInputSelectionMenuHidden007', 0, async (done: Function) => { + await longClick("textInput1", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden008', 0, async (done: Function) => { + await longClick("textInput2", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden009', 0, async (done: Function) => { + await longClick("textInput3", done); + await Utils.sleep(1000) + done() + }) + + // 右键点击效果 + it('testTextInputSelectionMenuHidden010', 0, async (done: Function) => { + await rightClick("textInput1", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden011', 0, async (done: Function) => { + await rightClick("textInput2", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden012', 0, async (done: Function) => { + await rightClick("textInput3", done); + await Utils.sleep(1000) + done() + }) + + // 三击效果 + it('testTextInputSelectionMenuHidden013', 0, async (done: Function) => { + await threeClick("textInput1", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden014', 0, async (done: Function) => { + await threeClick("textInput2", done); + await Utils.sleep(1000) + done() + }) + + it('testTextInputSelectionMenuHidden015', 0, async (done: Function) => { + await threeClick("textInput3", done); + await Utils.sleep(1000) + done() + }) + + // resetAttribute 后的效果 + it('testTextInputSelectionMenuHidden016', 0, async (done: Function) => { + await click("textInput4", done); + await Utils.sleep(1000) + done() + }) + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSetTextSelectionTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSetTextSelectionTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..92a931c6927fbf96610c10e7369e19c4bc76ea05 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputSetTextSelectionTest.test.ets @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputSetTextSelectionTest() { + + describe('TextInputSetTextSelectionTest', () => { + + let PAGE_TAG = 'TextInputSetTextSelectionTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done) + }) + + it('testTextInputSetTextSelection001', 0, async (done: Function) => { + focusControl.requestFocus("TextInputSetTextSelectionTest_textInput_id1"); + await Utils.sleep(1000); + await Utils.clickComponent("TextInputSetTextSelectionTest_id1"); + done(); + }) + + it('testTextInputSetTextSelection002', 1, async (done: Function) => { + focusControl.requestFocus("TextInputSetTextSelectionTest_textInput_id1"); + await Utils.sleep(1000); + await Utils.clickComponent("TextInputSetTextSelectionTest_id2"); + done(); + }) + + it('testTextInputSetTextSelection003', 0, async (done: Function) => { + focusControl.requestFocus("TextInputSetTextSelectionTest_textInput_id1"); + await Utils.sleep(1000); + await Utils.clickComponent("TextInputSetTextSelectionTest_id3"); + done(); + }) + + it('testTextInputSetTextSelection004', 0, async (done: Function) => { + focusControl.requestFocus("TextInputSetTextSelectionTest_textInput_id1"); + await Utils.sleep(1000); + await Utils.clickComponent("TextInputSetTextSelectionTest_id4"); + done(); + }) + + }) +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputShowKeyboardOnFocusTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputShowKeyboardOnFocusTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad1fcf6542e31984894a963fd37795ab251b089c --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputShowKeyboardOnFocusTest.test.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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'; + +export default function textInputShowKeyboardOnFocusTest() { + + describe('TextInputShowKeyboardOnFocusTest', () => { + + let PAGE_TAG = 'TextInputShowKeyboardOnFocusTest'; + let PAGE_TAG_ABNORMAL = 'TextInputShowKeyboardOnFocusAbnormalTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShotByDriver(globalThis.context, 'test', done) + }) + + it('testTextInputShowKeyboardOnFocusTest001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('OnFocusTestTextInputCompare') + await Utils.sleep(1000) + await Utils.clickComponent('OnFocusTestTextInputCompare') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputShowKeyboardOnFocusTest002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('OnFocusTestTextInput') + await Utils.sleep(1000) + await Utils.clickComponent('OnFocusTestTextInput') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputShowKeyboardOnFocusTest003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_ABNORMAL}`); + focusControl.requestFocus("TextInputDisableTest") + await Utils.sleep(1000) + await Utils.clickComponent("TextInputDisableTest") + await Utils.sleep(1000) + done(); + }) + + it('testTextInputShowKeyboardOnFocusTest004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG_ABNORMAL}`); + focusControl.requestFocus("OnFocusTestTextInputReset") + await Utils.sleep(1000) + await Utils.clickComponent("OnFocusTestTextInputReset") + await Utils.sleep(1000) + done(); + }) + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputStyleTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputStyleTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fcc4b8ed1de73ee5e0954930a6bf88f5dc8693b --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputStyleTest.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputStyleTest() { + + describe('TextInputStyleTest', () => { + + let PAGE_TAG = 'TextInputStyleTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done); + }); + + it('testTextInputStyle001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('default') + await Utils.sleep(2000) + await Utils.clickComponent('default') + await Utils.sleep(2000) + }); + + it('testTextInputStyle002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('inline') + await Utils.sleep(2000) + await Utils.clickComponent('inline') + await Utils.sleep(2000) + }); + + it('testTextInputStyle003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('negative') + await Utils.sleep(2000) + await Utils.clickComponent('negative') + await Utils.sleep(2000) + }); + + it('testTextInputStyle004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('large') + await Utils.sleep(2000) + await Utils.clickComponent('large') + await Utils.sleep(2000) + }); + + it('testTextInputStyle005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('reset') + await Utils.sleep(2000) + await Utils.clickComponent('reset') + await Utils.sleep(2000) + }); + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputTextPlaceholderTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputTextPlaceholderTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6de2223afb9fbec4a09b263d2954837dca11334 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputTextPlaceholderTest.test.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { afterEach, beforeAll, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputTextPlaceholderTest() { + + describe('TextInputTextPlaceholderTest', () => { + + let PAGE_TAG = 'TextInputTextPlaceholderTest'; + + beforeAll(async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done); + }); + + it('testTextInputTextPlaceholderTest001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + }); + + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputUnderlineColorTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputUnderlineColorTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9160a34102e52a7bd8541a1105af52cceae19a65 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputUnderlineColorTest.test.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 textInputUnderlineColorTest() { + + describe('TextInputUnderlineColorTest', () => { + + let PAGE_TAG = 'TextInputUnderlineColorTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done); + }); + + it('testTextInputUnderlineColorTest001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('textInput3') + await Utils.sleep(1000) + await Utils.clickComponent('textInput3') + await Utils.sleep(1000) + await Utils.triggerKey(2000) + await Utils.sleep(1000) + done(); + }) + + it('testTextInputUnderlineColorTest002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`); + focusControl.requestFocus('textInput2') + await Utils.sleep(1000) + await Utils.clickComponent('textInput2') + await Utils.sleep(1000) + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputWordBreakTest.test.ets b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputWordBreakTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..77e60b12e243953237015cdf6949671d21c4b590 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/test/textinput/TextInputWordBreakTest.test.ets @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { afterEach, describe, it } from '@ohos/hypium'; +import Utils from '../common/Utils'; +import WindowSnap from '../common/Snap'; + +export default function textInputWordBreakTest() { + + describe('TextInputWordBreakTest', () => { + + let PAGE_TAG = 'TextInputWordBreakTest'; + + afterEach(async (done: Function) => { + WindowSnap.snapShot(globalThis.context, 'test', done); + }); + + it('testTextInputWordBreak001', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput0') + await Utils.sleep(1000) + await Utils.clickComponent('textInput0') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak002', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput1') + await Utils.sleep(1000) + await Utils.clickComponent('textInput1') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak003', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput2') + await Utils.sleep(1000) + await Utils.clickComponent('textInput2') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak004', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput3') + await Utils.sleep(1000) + await Utils.clickComponent('textInput3') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak005', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput4') + await Utils.sleep(1000) + await Utils.clickComponent('textInput4') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak006', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput5') + await Utils.sleep(1000) + await Utils.clickComponent('textInput5') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak007', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput6') + await Utils.sleep(1000) + await Utils.clickComponent('textInput6') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak008', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput7') + await Utils.sleep(1000) + await Utils.clickComponent('textInput7') + await Utils.sleep(1000) + done(); + }) + + it('testTextInputWordBreak009', 0, async (done: Function) => { + await Utils.pushPage(`textinput/${PAGE_TAG}`, done); + focusControl.requestFocus('textInput8') + await Utils.sleep(1000) + await Utils.clickComponent('textInput8') + await Utils.sleep(1000) + done(); + }) + + }) +} diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..22e8d7e308a48383a2acdc13254a18588637bdfa --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +let abilityDelegator = undefined; +let abilityDelegatorArguments = undefined; + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]); + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}`; + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + let cmd = 'aa start -d 0 -a MainAbility' + + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); + let debug = abilityDelegatorArguments.parameters['-D']; + if (debug == 'true') { + cmd += ' -D'; + } + console.info('cmd : ' + cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }); + console.info('OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 b/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b0ee0e81d470b8fc3b276f0b706ddf014ed6099 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/module.json5 @@ -0,0 +1,47 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntry": "./ets/Application/AbilityStage.ts", + "description": "$string:module_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "MainAbility", + "srcEntry": "./ets/MainAbility/MainAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "orientation": "portrait", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..8658bacc0d5d479ee25116b206bc152e53d92953 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/float.json @@ -0,0 +1,24 @@ +{ + "float": [ + { + "name": "300vp", + "value": "300vp" + }, + { + "name": "200vp", + "value": "200vp" + }, + { + "name": "100vp", + "value": "100vp" + }, + { + "name": "50vp", + "value": "50vp" + } + ,{ + "name": "10vp", + "value": "10vp" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..bbe9979eda9db82793df2873701e4beae14c44cc Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/background.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..0ec2e1692ed4a280147f41fa7491fa6595958153 Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/icon_transparent.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..4b68e9b07b4c30539ff093e43c193cfd61dc59fd Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/rectIcon.png differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg new file mode 100644 index 0000000000000000000000000000000000000000..36a19cd6b90bb98511116f5015c74fe2f860249d Binary files /dev/null and b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/media/src.jpg differ diff --git a/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..4f59601e59aa4184858bf73d85843eed667bd883 --- /dev/null +++ b/function/ui_compare/capidemo/entry/src/ohosTest/resources/base/profile/main_pages.json @@ -0,0 +1,39 @@ +{ + "src": [ + "MainAbility/pages/DemoIndex", + "MainAbility/pages/textinput/TextInputCustomKeyboardPage1Test", + "MainAbility/pages/textinput/TextInputCustomKeyboardPage2Test", + "MainAbility/pages/textinput/TextInputCustomKeyboardPage3Test", + "MainAbility/pages/textinput/TextInputCustomKeyboardPage4Test", + "MainAbility/pages/textinput/TextInputCustomKeyboardPage5Test", + "MainAbility/pages/textinput/TextInputCustomKeyboardPage6Test", + "MainAbility/pages/textinput/TextInputSelectAllTest", + "MainAbility/pages/textinput/TextInputEnableAutoFillTest", + "MainAbility/pages/textinput/TextInputContentTypePage1Test", + "MainAbility/pages/textinput/TextInputContentTypePage2Test", + "MainAbility/pages/textinput/TextInputPasswordRulesPage1Test", + "MainAbility/pages/textinput/TextInputPasswordRulesPage2Test", + "MainAbility/pages/textinput/TextInputPasswordRulesPage3Test", + "MainAbility/pages/textinput/TextInputSelectionMenuHiddenTest", + "MainAbility/pages/textinput/TextInputFontFeaturePage1Test", + "MainAbility/pages/textinput/TextInputFontFeaturePage2Test", + "MainAbility/pages/textinput/TextInputFontFeaturePage3Test", + "MainAbility/pages/textinput/TextInputTextPlaceholderTest", + "MainAbility/pages/textinput/TextInputCancelButtonTest", + "MainAbility/pages/textinput/TextInputSetTextSelectionTest", + "MainAbility/pages/textinput/TextInputUnderlineColorTest", + "MainAbility/pages/textinput/TextInputWordBreakTest", + "MainAbility/pages/textinput/TextInputStyleTest", + "MainAbility/pages/textinput/TextInputMinFontSizeAndMaxFontSizeTest", + "MainAbility/pages/textinput/TextInputMaxLinesTest", + "MainAbility/pages/textinput/TextInputNumberOfLinesTest", + "MainAbility/pages/textinput/TextInputInputFilterTest", + "MainAbility/pages/textinput/TextInputShowKeyboardOnFocusTest", + "MainAbility/pages/textinput/TextInputShowKeyboardOnFocusAbnormalTest", + "MainAbility/pages/textinput/TextInputBlurOnSubmitTest", + "MainAbility/pages/textinput/TextInputGetCaretOffsetTest", + "MainAbility/pages/textinput/TextInputCaretPositionTest", + "MainAbility/pages/textinput/TextInputControllerTest" + ] +} + diff --git a/function/ui_compare/capidemo/hvigor/hvigor-config.json5 b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f70ecd4112d94f9aa555adf898d53f18bf58f3e9 --- /dev/null +++ b/function/ui_compare/capidemo/hvigor/hvigor-config.json5 @@ -0,0 +1,5 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/hvigorfile.ts b/function/ui_compare/capidemo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/function/ui_compare/capidemo/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/function/ui_compare/capidemo/log.txt b/function/ui_compare/capidemo/log.txt new file mode 100644 index 0000000000000000000000000000000000000000..c30becbf3cf835fb939a2032089d1445f7774299 Binary files /dev/null and b/function/ui_compare/capidemo/log.txt differ diff --git a/function/ui_compare/capidemo/oh-package-lock.json5 b/function/ui_compare/capidemo/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8c097e89cbd732ed125dac0b04ac91ccfa637656 --- /dev/null +++ b/function/ui_compare/capidemo/oh-package-lock.json5 @@ -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. + */ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.19": { + "name": "@ohos/hypium", + "version": "1.0.19", + "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.19.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/function/ui_compare/capidemo/oh-package.json5 b/function/ui_compare/capidemo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3884ebeba43b0beec2ec781d334eb3347549d05 --- /dev/null +++ b/function/ui_compare/capidemo/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "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