From 954f7f47fad906d1e9213ced4b91cdebbaaf1251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B0=B8=E5=87=AF?= Date: Wed, 24 Sep 2025 18:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85capi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘永凯 --- .../entry/src/main/cpp/ArkUIAnimationNode.h | 241 ++++++++ .../entry/src/main/cpp/ArkUIBaseNode.h | 83 +++ .../entry/src/main/cpp/ArkUIColumnNode.h | 229 ++++++++ .../entry/src/main/cpp/ArkUINode.h | 270 +++++++++ .../entry/src/main/cpp/ArkUINumber.h | 62 +++ .../entry/src/main/cpp/ArkUITextNode.h | 55 ++ .../src/main/cpp/ArkUIVisualEffectsNode.h | 468 ++++++++++++++++ .../entry/src/main/cpp/NativeModule.h | 44 ++ .../entry/src/main/cpp/manager.cpp | 250 +++++++++ .../entry/src/main/cpp/manager.h | 42 ++ .../entry/src/main/cpp/napi_init.cpp | 32 +- .../src/main/cpp/types/libentry/Index.d.ts | 18 +- .../entry/src/main/ets/pages/Index.ets | 2 + .../ets/pages/animation/animationIndex1.ets | 44 ++ .../ets/pages/animation/animationIndex2.ets | 44 ++ .../ets/pages/animation/animationIndex3.ets | 44 ++ .../ets/pages/animation/animationIndex4.ets | 44 ++ .../ets/pages/animation/animationIndex5.ets | 44 ++ .../src/main/ets/pages/page_animation.ets | 103 ++++ .../main/ets/pages/page_visual_effects.ets | 110 ++++ .../visualEffects/visualEffectsIndex1.ets | 44 ++ .../visualEffects/visualEffectsIndex10.ets | 44 ++ .../visualEffects/visualEffectsIndex2.ets | 44 ++ .../visualEffects/visualEffectsIndex3.ets | 44 ++ .../visualEffects/visualEffectsIndex4.ets | 44 ++ .../visualEffects/visualEffectsIndex5.ets | 44 ++ .../visualEffects/visualEffectsIndex6.ets | 44 ++ .../visualEffects/visualEffectsIndex7.ets | 44 ++ .../visualEffects/visualEffectsIndex8.ets | 44 ++ .../visualEffects/visualEffectsIndex9.ets | 44 ++ .../resources/base/profile/main_pages.json | 21 +- ArkUIKit/NativeTypeSample/README.md | 19 +- .../entry/src/main/cpp/ArkUIAnimationNode.h | 518 ++++++++++++++++++ .../entry/src/main/cpp/ArkUIBaseNode.h | 83 +++ .../entry/src/main/cpp/ArkUIButtonNode.h | 42 ++ .../entry/src/main/cpp/ArkUIColumnNode.h | 229 ++++++++ .../entry/src/main/cpp/ArkUINode.h | 276 ++++++++++ .../entry/src/main/cpp/ArkUINumber.h | 61 +++ .../entry/src/main/cpp/ArkUITextNode.h | 93 ++++ .../src/main/cpp/ArkUIVisualEffectsNode.h | 113 ++++ .../entry/src/main/cpp/NativeModule.h | 44 ++ .../entry/src/main/cpp/SwiperMaker.cpp | 2 +- .../entry/src/main/cpp/TextMaker.h | 2 +- .../entry/src/main/cpp/manager.cpp | 136 +++++ .../entry/src/main/cpp/manager.h | 37 +- .../entry/src/main/cpp/napi_init.cpp | 26 +- .../src/main/cpp/types/libentry/Index.d.ts | 11 +- .../entry/src/main/ets/pages/Index.ets | 2 + .../ets/pages/animation/animationIndex1.ets | 44 ++ .../ets/pages/animation/animationIndex2.ets | 44 ++ .../ets/pages/animation/animationIndex3.ets | 44 ++ .../ets/pages/animation/animationIndex4.ets | 44 ++ .../ets/pages/animation/animationIndex5.ets | 44 ++ .../src/main/ets/pages/page_animation.ets | 105 ++++ .../main/ets/pages/page_visual_effects.ets | 101 ++++ .../visualEffects/visualEffectsIndex1.ets | 44 ++ .../visualEffects/visualEffectsIndex2.ets | 44 ++ .../visualEffects/visualEffectsIndex3.ets | 44 ++ 58 files changed, 4922 insertions(+), 20 deletions(-) create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIAnimationNode.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIBaseNode.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIColumnNode.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINode.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINumber.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUITextNode.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/NativeModule.h create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex1.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex2.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex3.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex4.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex5.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_animation.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_visual_effects.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex10.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex4.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex5.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex6.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex7.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex8.ets create mode 100644 ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex9.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIAnimationNode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIBaseNode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIButtonNode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIColumnNode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINumber.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUITextNode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/cpp/NativeModule.h create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex1.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex2.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex3.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex4.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex5.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_animation.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_visual_effects.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets create mode 100644 ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIAnimationNode.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIAnimationNode.h new file mode 100644 index 000000000..73e481e2d --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIAnimationNode.h @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIDOBASENODE_H +#define MYAPPLICATION_ARKUIDOBASENODE_H +#include "ArkUIColumnNode.h" +#include "ArkUITextNode.h" +#include "ArkUINumber.h" +#include + +namespace NativeModule { +std::shared_ptr g_keyframe_text = nullptr; +std::shared_ptr g_keyframe_column1 = nullptr; +std::shared_ptr g_keyframe_column2 = nullptr; +std::shared_ptr CreateAnimationFrameNode1() +{ + auto column = std::make_shared(); + auto textNodeTransformCenter = std::make_shared(); + textNodeTransformCenter->SetTextContent("transformCenter"); + textNodeTransformCenter->SetWidth(MIDDLE_LENGTH); + textNodeTransformCenter->SetHeight(SMALL_LENGTH); + auto columnTransformCenter = std::make_shared(); + columnTransformCenter->SetWidth(MIDDLE_LENGTH); + columnTransformCenter->SetHeight(MIDDLE_LENGTH); + columnTransformCenter->SetBackgroundColor(COLOR_PINK); + columnTransformCenter->SetRotateTransition(); + columnTransformCenter->SetTransformCenter(NUMBER_20); + column->AddChild(textNodeTransformCenter); + column->AddChild(columnTransformCenter); + + auto textNodeTransition = std::make_shared(); + textNodeTransition->SetTextContent("NODE_TRANSITION"); + textNodeTransition->SetWidth(MIDDLE_LENGTH); + textNodeTransition->SetHeight(SMALL_LENGTH); + ArkUI_RotationOptions rotation; + rotation.x = NUMBER_0; + rotation.y = NUMBER_0; + rotation.z = NUMBER_1; + rotation.angle = NUMBER_180; + rotation.perspective = NUMBER_0; + ArkUI_TransitionEffect* options = OH_ArkUI_CreateRotationTransitionEffect(&rotation); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + OH_ArkUI_AnimateOption_SetDuration(option, DURATION_TIME); + OH_ArkUI_TransitionEffect_SetAnimation(options, option); + auto columnTransition = std::make_shared(); + columnTransition->SetWidth(MIDDLE_LENGTH); + columnTransition->SetHeight(MIDDLE_LENGTH); + columnTransition->SetBackgroundColor(COLOR_RED); + columnTransition->SetTransition(options); + column->AddChild(textNodeTransition); + column->AddChild(columnTransition); + + return column; +} + +std::shared_ptr CreateAnimationFrameNode2() +{ + auto column = std::make_shared(); + auto textNodeOpacityTransition = std::make_shared(); + textNodeOpacityTransition->SetTextContent("OpacityTransition"); + textNodeOpacityTransition->SetWidth(MIDDLE_LENGTH); + textNodeOpacityTransition->SetHeight(SMALL_LENGTH); + auto columnOpacityTransition = std::make_shared(); + columnOpacityTransition->SetWidth(MIDDLE_LENGTH); + columnOpacityTransition->SetHeight(MIDDLE_LENGTH); + columnOpacityTransition->SetBackgroundColor(COLOR_RED); + columnOpacityTransition->SetOpacityTransition(); + column->AddChild(textNodeOpacityTransition); + column->AddChild(columnOpacityTransition); + + auto textNodeRotateTransition = std::make_shared(); + textNodeRotateTransition->SetTextContent("RotateTransition"); + textNodeRotateTransition->SetWidth(MIDDLE_LENGTH); + textNodeRotateTransition->SetHeight(SMALL_LENGTH); + auto columnRotateTransition = std::make_shared(); + columnRotateTransition->SetWidth(MIDDLE_LENGTH); + columnRotateTransition->SetHeight(MIDDLE_LENGTH); + columnRotateTransition->SetBackgroundColor(COLOR_PINK); + columnRotateTransition->SetRotateTransition(); + column->AddChild(textNodeRotateTransition); + column->AddChild(columnRotateTransition); + + auto textNodeScaleTransition = std::make_shared(); + textNodeScaleTransition->SetTextContent("ScaleTransition"); + textNodeScaleTransition->SetWidth(MIDDLE_LENGTH); + textNodeScaleTransition->SetHeight(SMALL_LENGTH); + auto columnScaleTransition = std::make_shared(); + columnScaleTransition->SetWidth(MIDDLE_LENGTH); + columnScaleTransition->SetHeight(MIDDLE_LENGTH); + columnScaleTransition->SetBackgroundColor(COLOR_PINK); + columnScaleTransition->SetScaleTransition(); + column->AddChild(textNodeScaleTransition); + column->AddChild(columnScaleTransition); + + return column; +} + +std::shared_ptr CreateAnimationFrameNode3() +{ + auto column = std::make_shared(); + auto textNodeTranslateTransition = std::make_shared(); + textNodeTranslateTransition->SetTextContent("TranslateTransition"); + textNodeTranslateTransition->SetWidth(MIDDLE_LENGTH); + textNodeTranslateTransition->SetHeight(SMALL_LENGTH); + auto columnTranslateTransition = std::make_shared(); + columnTranslateTransition->SetWidth(MIDDLE_LENGTH); + columnTranslateTransition->SetHeight(MIDDLE_LENGTH); + columnTranslateTransition->SetBackgroundColor(COLOR_RED); + columnTranslateTransition->SetTranslateTransition(); + column->AddChild(textNodeTranslateTransition); + column->AddChild(columnTranslateTransition); + + auto textNodeMoveTransition = std::make_shared(); + textNodeMoveTransition->SetTextContent("MoveTransition"); + textNodeMoveTransition->SetWidth(MIDDLE_LENGTH); + textNodeMoveTransition->SetHeight(SMALL_LENGTH); + auto columnMoveTransition = std::make_shared(); + columnMoveTransition->SetWidth(MIDDLE_LENGTH); + columnMoveTransition->SetHeight(MIDDLE_LENGTH); + columnMoveTransition->SetBackgroundColor(COLOR_PINK); + columnMoveTransition->SetMoveTransition(); + column->AddChild(textNodeMoveTransition); + column->AddChild(columnMoveTransition); + + return column; +} + +std::shared_ptr CreateAnimationFrameNode4() +{ + auto column = std::make_shared(); + auto textNode = std::make_shared(); + textNode->SetTextContent("NODE_RENDER_FIT"); + textNode->SetWidth(MIDDLE_LENGTH); + textNode->SetHeight(SMALL_LENGTH); + + auto text = std::make_shared(); + text->SetWidth(MIDDLE_LENGTH); + text->SetHeight(SMALL_LENGTH); + text->SetBackgroundColor(COLOR_PINK); + text->SetTextContent("NODE_RENDER_FIT"); + text->SetRenderFit(ARKUI_RENDER_FIT_BOTTOM); + + g_keyframe_text = text; + text->RegisterNodeEvent(text->GetHandle(), NODE_ON_CLICK, NUMBER_1, nullptr); + auto onTouch1 = [](ArkUI_NodeEvent *event) { + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUMBER_1) { + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_keyframe_text->GetHandle()); + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + completeCallback->callback = [](void *userData) { + }; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + g_keyframe_text->SetWidth(LARGE_LENGTH); + g_keyframe_text->SetHeight(MIDDLE_LENGTH); + g_keyframe_text->SetBackgroundColor(COLOR_RED); + }; + animateApi->animateTo(context, option, update, completeCallback); + } + }; + text->RegisterNodeEventReceiver(onTouch1); + column->AddChild(textNode); + column->AddChild(text); + + return column; +} + +std::shared_ptr CreateAnimationFrameNode5() +{ + auto column = std::make_shared(); + auto textNodeTitle1 = std::make_shared(); + textNodeTitle1->SetTextContent("GeometryTransition"); + textNodeTitle1->SetWidth(MIDDLE_LENGTH); + textNodeTitle1->SetHeight(SMALL_LENGTH); + const char* str = "animation"; + auto column1 = std::make_shared(); + column1->SetWidth(MIDDLE_LENGTH); + column1->SetHeight(MIDDLE_LENGTH); + column1->SetBackgroundColor(COLOR_PINK); + column1->SetOpacityTransition(); + column1->SetGeometryTransition(NUMBER_0, str); + + auto column2 = std::make_shared(); + column2->SetWidth(LARGE_LENGTH); + column2->SetHeight(LARGE_LENGTH); + column2->SetBackgroundColor(COLOR_RED); + column2->SetVisibility(ARKUI_VISIBILITY_NONE); + column2->SetGeometryTransition(NUMBER_1, str); + column2->SetOpacityTransition(); + + g_keyframe_column1 = column1; + g_keyframe_column2 = column2; + column1->RegisterNodeEvent(column1->GetHandle(), NODE_ON_CLICK, NUMBER_1, nullptr); + auto onTouch1 = [](ArkUI_NodeEvent *event) { + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUMBER_1) { + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_keyframe_column1->GetHandle()); + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetDuration(option, NUMBER_1000); + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + completeCallback->callback = [](void *userData) { + }; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + g_keyframe_column2->SetVisibility(ARKUI_VISIBILITY_VISIBLE); + g_keyframe_column1->SetVisibility(ARKUI_VISIBILITY_NONE); + }; + animateApi->animateTo(context, option, update, completeCallback); + } + }; + column1->RegisterNodeEventReceiver(onTouch1); + column->AddChild(textNodeTitle1); + column->AddChild(column1); + column->AddChild(column2); + + return column; +} +} // namespace NativeModule + +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIBaseNode.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIBaseNode.h new file mode 100644 index 000000000..9931c7d72 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIBaseNode.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIBASENODE_H +#define MYAPPLICATION_ARKUIBASENODE_H + +#include +#include +#include + +#include "manager.h" +#include "NativeModule.h" + +namespace NativeModule { + +class ArkUIBaseNode { +public: + explicit ArkUIBaseNode(ArkUI_NodeHandle handle) + : handle_(handle), nativeModule_(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()) {} + + virtual ~ArkUIBaseNode() + { + if (!children_.empty()) { + for (const auto& child : children_) { + nativeModule_->removeChild(handle_, child->GetHandle()); + } + children_.clear(); + } + nativeModule_->disposeNode(handle_); + } + void AddChild(const std::shared_ptr &child) + { + children_.emplace_back(child); + OnAddChild(child); + } + void RemoveChild(const std::shared_ptr &child) + { + children_.remove(child); + OnRemoveChild(child); + } + void InsertChild(const std::shared_ptr &child, int32_t index) + { + if (index >= children_.size()) { + AddChild(child); + } else { + auto iter = children_.begin(); + std::advance(iter, index); + children_.insert(iter, child); + OnInsertChild(child, index); + } + } + ArkUI_NodeHandle GetHandle() const { return handle_; } + ArkUI_NativeNodeAPI_1* GetNativeModule() const + { + return nativeModule_; + } + +protected: + virtual void OnAddChild(const std::shared_ptr &child) {} + virtual void OnRemoveChild(const std::shared_ptr &child) {} + virtual void OnInsertChild(const std::shared_ptr &child, int32_t index) {} + + ArkUI_NodeHandle handle_; + ArkUI_NativeNodeAPI_1 *nativeModule_ = nullptr; + +private: + std::list> children_; +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUIBASENODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIColumnNode.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIColumnNode.h new file mode 100644 index 000000000..b51935def --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIColumnNode.h @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUICOLUMNNODE_H +#define MYAPPLICATION_ARKUICOLUMNNODE_H + +#include "ArkUINode.h" +#include + +namespace NativeModule { +class ArkUIColumnNode : public ArkUINode { +public: + ArkUIColumnNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_COLUMN)) {} + + void SetTranslate(float x, float y, float z) + { + ArkUI_NumberValue nums[NUMBER_3] = {x, y, z}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + nativeModule_->setAttribute(handle_, NODE_TRANSLATE, &item); + } + void SetScale(float x, float y) + { + ArkUI_NumberValue nums[NUMBER_2] = {x, y}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_2}; + nativeModule_->setAttribute(handle_, NODE_SCALE, &item); + } + void SetRotate(float x, float y, float z, float angle, float center) + { + ArkUI_NumberValue nums[NUMBER_5] = {x, y, z, angle, center}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_5}; + nativeModule_->setAttribute(handle_, NODE_ROTATE, &item); + } + void SetBrightness(float light) + { + ArkUI_NumberValue nums[NUMBER_1] = {light}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BRIGHTNESS, &item); + } + void SetSaturate(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_SATURATION, &item); + } + int32_t SetLinearGradient(float angle, int32_t direction, int32_t repeat) + { + ArkUI_NumberValue nums[NUMBER_3]; + nums[NUMBER_0].f32 = angle; + nums[NUMBER_1].i32 = direction; + nums[NUMBER_2].i32 = repeat; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3, .object = &colorStop}; + auto err = nativeModule_->setAttribute(handle_, NODE_LINEAR_GRADIENT, &item); + return err; + } + void SetOpacity(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_OPACITY, &item); + } + void SetBorderRadius(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BORDER_RADIUS, &item); + } + int32_t SetClip(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].i32 = number; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_CLIP, &item); + return err; + } + int32_t SetCircleShape(int32_t number, float width, float height) + { + ArkUI_NumberValue nums[NUMBER_3]; + nums[NUMBER_0].i32 = number; + nums[NUMBER_1].f32 = width; + nums[NUMBER_2].f32 = height; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_CLIP_SHAPE, &item); + return err; + } + int32_t SetTransform() + { + ArkUI_NumberValue value2[NUMBER_16]; + for (int i = NUMBER_0; i < NUMBER_16; i++) { + value2[i].f32 = NUMBER_0; + } + value2[NUMBER_0].f32 = NUMBER_1; + value2[NUMBER_1].f32 = NUMBER_1; + ArkUI_AttributeItem item = { .value = value2, .size = NUMBER_3 }; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSFORM, &item); + return err; + } + int32_t SetShadow(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_0]; + nums[NUMBER_0].i32 = number; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_SHADOW, &item); + return err; + } + int32_t SetBackgroundBlurStyle(int32_t number) + { + ArkUI_NumberValue blurStyle[NUMBER_6]; + blurStyle[NUMBER_0].i32 = number; + blurStyle[NUMBER_2].i32 = ARKUI_ADAPTIVE_COLOR_AVERAGE; + ArkUI_AttributeItem item = { .value = blurStyle, .size = NUMBER_2}; + auto err = nativeModule_->setAttribute(handle_, NODE_BACKGROUND_BLUR_STYLE, &item); + return err; + } + int32_t SetTransformCenter(float number) + { + ArkUI_NumberValue centerPointArray[] = {number}; + ArkUI_AttributeItem item = { .value = centerPointArray, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSFORM_CENTER, &item); + return err; + } + int32_t SetSweepGradient() + { + ArkUI_NumberValue nums[NUMBER_6]; + nums[NUMBER_0].f32 = SMALL_LENGTH; + nums[NUMBER_1].f32 = SMALL_LENGTH; + nums[NUMBER_2].f32 = NUMBER_0; + nums[NUMBER_3].f32 = NUMBER_359; + nums[NUMBER_4].f32 = NUMBER_45; + nums[NUMBER_5].f32 = NUMBER_1; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_6, .object = &colorStop }; + auto err = nativeModule_->setAttribute(handle_, NODE_SWEEP_GRADIENT, &item); + return err; + } + int32_t SetRadialGradient() + { + ArkUI_NumberValue nums[NUMBER_4]; + nums[NUMBER_0].f32 = SMALL_LENGTH; + nums[NUMBER_1].f32 = SMALL_LENGTH; + nums[NUMBER_2].f32 = NUMBER_60; + nums[NUMBER_3].f32 = NUMBER_1; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_4, .object = &colorStop }; + auto err = nativeModule_->setAttribute(handle_, NODE_RADIAL_GRADIENT, &item); + return err; + } + int32_t SetMask() + { + ArkUI_NumberValue nums[NUMBER_4]; + nums[NUMBER_0].i32 = ARKUI_MASK_TYPE_PROGRESS; + nums[NUMBER_1].f32 = NUMBER_10; + nums[NUMBER_2].f32 = NUMBER_100; + nums[NUMBER_3].u32 = COLOR_WHITE; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_4 }; + auto err = nativeModule_->setAttribute(handle_, NODE_MASK, &item); + return err; + } + int32_t SetGrayScale(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_GRAY_SCALE, &item); + return err; + } + int32_t SetInvert(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_INVERT, &item); + return err; + } + int32_t SetSepia(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_SEPIA, &item); + return err; + } + int32_t SetContrast(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_CONTRAST, &item); + return err; + } + int32_t SetColumnJustifyContent(int32_t number) + { + ArkUI_NumberValue nums[] = { { .i32 = number } }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_COLUMN_JUSTIFY_CONTENT, &item); + return err; + } + ~ArkUIColumnNode() override {} +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUILISTNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINode.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINode.h new file mode 100644 index 000000000..7ee5b530c --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINode.h @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUINODE_H +#define MYAPPLICATION_ARKUINODE_H + +#include "ArkUIBaseNode.h" +#include "NativeModule.h" +#include +#include +#include +#include +#include "ArkUINumber.h" + +namespace NativeModule { +class ArkUINode : public ArkUIBaseNode { +public: + explicit ArkUINode(ArkUI_NodeHandle handle) : ArkUIBaseNode(handle) {} + + ~ArkUINode() override {} + + void SetWidth(float width) + { + ArkUI_NumberValue value[] = {{.f32 = width}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_WIDTH, &item); + } + void SetPercentWidth(float percent) + { + ArkUI_NumberValue value[] = {{.f32 = percent}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_WIDTH_PERCENT, &item); + } + void SetHeight(float height) + { + ArkUI_NumberValue value[] = {{.f32 = height}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_HEIGHT, &item); + } + void SetPercentHeight(float percent) + { + ArkUI_NumberValue value[] = {{.f32 = percent}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_HEIGHT_PERCENT, &item); + } + void SetBackgroundColor(uint32_t color) + { + ArkUI_NumberValue value[] = {{.u32 = color}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BACKGROUND_COLOR, &item); + } + int32_t SetZIndex(int32_t number) + { + ArkUI_NumberValue value[] = {{.i32 = number}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_Z_INDEX, &item); + return err; + } + int32_t SetForegroundColor(uint32_t color) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].u32 = color; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_FOREGROUND_COLOR, &item); + return err; + } + int32_t SetMarkAnchor(float x, float y) + { + ArkUI_NumberValue nums[NUMBER_2] = {x, y}; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_2}; + auto err = nativeModule_->setAttribute(handle_, NODE_MARK_ANCHOR, &item); + return err; + } + int32_t SetVisibility(int32_t visibility) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].i32 = visibility; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_VISIBILITY, &item); + return err; + } + void RegisterNodeEvent(ArkUI_NodeHandle node, + ArkUI_NodeEventType eventType, int32_t targetId, void* userData) + { + nativeModule_->registerNodeEvent(node, eventType, targetId, userData); + } + void RegisterNodeEventReceiver(void (*eventReceiver)(ArkUI_NodeEvent* event)) + { + nativeModule_->registerNodeEventReceiver(eventReceiver); + } + int32_t SetOpacityTransition() + { + ArkUI_NumberValue opacityTransition[] = { + NUMBER_02, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_EASE_IN_OUT) } + }; + ArkUI_AttributeItem item = { .value = opacityTransition, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_OPACITY_TRANSITION, &item); + return err; + } + int32_t SetRotateTransition() + { + ArkUI_NumberValue rotateTransition[] = { + NUMBER_00, + NUMBER_00, + NUMBER_1F, + NUMBER_180, + NUMBER_0, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = rotateTransition, .size = NUMBER_7}; + auto err = nativeModule_->setAttribute(handle_, NODE_ROTATE_TRANSITION, &item); + return err; + } + int32_t SetScaleTransition() + { + ArkUI_NumberValue scaleTransition[] = { + NUMBER_00, + NUMBER_00, + NUMBER_00, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = scaleTransition, .size = NUMBER_5}; + auto err = nativeModule_->setAttribute(handle_, NODE_SCALE_TRANSITION, &item); + return err; + } + int32_t SetTranslateTransition() + { + ArkUI_NumberValue translateTransition[] = { + NUMBER_100F, + NUMBER_100F, + NUMBER_00, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = translateTransition, .size = NUMBER_5}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSLATE_TRANSITION, &item); + return err; + } + int32_t SetMoveTransition() + { + ArkUI_NumberValue translateTransition[] = { + {.i32 = ARKUI_TRANSITION_EDGE_START }, + {.i32 = NUMBER_3000 }, + {.i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = translateTransition, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_MOVE_TRANSITION, &item); + return err; + } + int32_t SetForegroundBlurStyle(int32_t number) + { + ArkUI_NumberValue nums[] = { { .i32 = number} }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_FOREGROUND_BLUR_STYLE, &item); + return err; + } + int32_t SetColorBlend(uint32_t color) + { + ArkUI_NumberValue nums[] = { { .u32 = color} }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_COLOR_BLEND, &item); + return err; + } + int32_t SetTransition(ArkUI_TransitionEffect* effect) + { + ArkUI_AttributeItem item = { .object = effect}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSITION, &item); + return err; + } + int32_t SetBackdropBlur(float round) + { + ArkUI_NumberValue nums[] = { round, NUMBER_100, NUMBER_100 }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_BACKDROP_BLUR, &item); + return err; + } + void SetTranslateWithPercent(float x, float y, float z) + { + ArkUI_NumberValue nums[NUMBER_3] = {x, y, z}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + nativeModule_->setAttribute(handle_, NODE_TRANSLATE_WITH_PERCENT, &item); + } + void SetRotateAngle(float x, float y, float z, float see) + { + ArkUI_NumberValue nums[NUMBER_4] = {x, y, z, see}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_4}; + nativeModule_->setAttribute(handle_, NODE_ROTATE_ANGLE, &item); + } + int32_t SetGeometryTransition(int32_t share, const char* str) + { + ArkUI_NumberValue nums[NUMBER_1] = { {.i32 = share} }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1, .string = str}; + auto err = nativeModule_->setAttribute(handle_, NODE_GEOMETRY_TRANSITION, &item); + return err; + } + int32_t SetCustomShadow() + { + ArkUI_NumberValue nums[NUMBER_7] = { + NUMBER_20, + {.i32 = NUMBER_0 }, + SMALL_LENGTH, + SMALL_LENGTH, + { .i32 = ARKUI_SHADOW_TYPE_COLOR }, + { .u32 = COLOR_RED }, + { .u32 = NUMBER_0 } + }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_7}; + auto err = nativeModule_->setAttribute(handle_, NODE_CUSTOM_SHADOW, &item); + return err; + } + int32_t SetBlur(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_BLUR, &item); + return err; + } + int32_t SetBackGroundImage(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_BLUR, &item); + return err; + } + int32_t SetRenderFit(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_RENDER_FIT, &item); + return err; + } + int32_t SetRenderGroup(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_1] = { { .i32 = number } }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_RENDER_GROUP, &item); + return err; + } +protected: + void OnAddChild(const std::shared_ptr &child) override + { + nativeModule_->addChild(handle_, child->GetHandle()); + } + void OnRemoveChild(const std::shared_ptr &child) override + { + nativeModule_->removeChild(handle_, child->GetHandle()); + } + void OnInsertChild(const std::shared_ptr &child, int32_t index) override + { + nativeModule_->insertChildAt(handle_, child->GetHandle(), index); + } +}; +} // namespace NativeModule +#endif // MYAPPLICATION_ARKUINODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINumber.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINumber.h new file mode 100644 index 000000000..258e01c6b --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUINumber.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUINUMBER_H +#define ARKUINUMBER_H +namespace NativeModule { +constexpr uint32_t COLOR_1 = 0x33FF0000; +constexpr uint32_t COLOR_2 = 0x3300FF00; +constexpr uint32_t COLOR_3 = 0x330000FF; +constexpr uint32_t COLOR_BLACK = 0xFF000000; +constexpr uint32_t COLOR_PINK = 0x33FF0000; +constexpr uint32_t COLOR_RED = 0xFFFF0000; +constexpr uint32_t COLOR_WHITE = 0xFFFFFFFF; +constexpr int32_t DURATION_TIME = 2000; +constexpr int32_t LARGE_LENGTH = 300; +constexpr int32_t MIDDLE_LENGTH = 200; +constexpr int32_t NUMBER_0 = 0; +constexpr float NUMBER_00 = 0.0; +constexpr float NUMBER_01 = 0.1; +constexpr float NUMBER_02 = 0.2; +constexpr float NUMBER_03 = 0.3; +constexpr float NUMBER_04 = 0.4; +constexpr float NUMBER_05 = 0.5; +constexpr float NUMBER_06 = 0.6; +constexpr int32_t NUMBER_1 = 1; +constexpr float NUMBER_1F = 1.0; +constexpr int32_t NUMBER_2 = 2; +constexpr int32_t NUMBER_3 = 3; +constexpr int32_t NUMBER_4 = 4; +constexpr int32_t NUMBER_5 = 5; +constexpr int32_t NUMBER_6 = 6; +constexpr int32_t NUMBER_7 = 7; +constexpr int32_t NUMBER_10 = 10; +constexpr int32_t NUMBER_16 = 16; +constexpr int32_t NUMBER_20 = 20; +constexpr int32_t NUMBER_25 = 25; +constexpr int32_t NUMBER_30 = 30; +constexpr int32_t NUMBER_45 = 45; +constexpr int32_t NUMBER_60 = 60; +constexpr int32_t NUMBER_90 = 90; +constexpr int32_t NUMBER_100 = 100; +constexpr float NUMBER_100F = 100.0; +constexpr int32_t NUMBER_150 = 150; +constexpr int32_t NUMBER_180 = 180; +constexpr int32_t NUMBER_1000 = 1000; +constexpr int32_t NUMBER_3000 = 3000; +constexpr int32_t NUMBER_359 = 359; +constexpr int32_t SMALL_LENGTH = 50; +} +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUITextNode.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUITextNode.h new file mode 100644 index 000000000..0426e46b1 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUITextNode.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// ArkUITextNode.h +#ifndef MYAPPLICATION_ARKUITEXTNODE_H +#define MYAPPLICATION_ARKUITEXTNODE_H + +#include "ArkUINode.h" + +#include + +namespace NativeModule { +class ArkUITextNode : public ArkUINode { +public: + ArkUITextNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_TEXT)) {} + void SetFontSize(float fontSize) + { + ArkUI_NumberValue value[] = {{.f32 = fontSize}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_FONT_SIZE, &item); + } + void SetFontColor(uint32_t color) + { + ArkUI_NumberValue value[] = {{.u32 = color}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_FONT_COLOR, &item); + } + void SetTextContent(const std::string &content) + { + ArkUI_AttributeItem item = {nullptr, 0, content.c_str()}; + nativeModule_->setAttribute(handle_, NODE_TEXT_CONTENT, &item); + } + void SetTextAlign(ArkUI_TextAlignment align) + { + ArkUI_NumberValue value[] = {{.i32 = align}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_TEXT_ALIGN, &item); + } +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUITEXTNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h new file mode 100644 index 000000000..05dcf46b9 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h @@ -0,0 +1,468 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIVISUALEFFECTSNODE_H +#define MYAPPLICATION_ARKUIVISUALEFFECTSNODE_H +#include "ArkUIColumnNode.h" +#include "ArkUITextNode.h" +#include + +namespace NativeModule { +std::shared_ptr CreateVisualEffectsFrameNode1() +{ + auto column = std::make_shared(); + auto textNodeTran = std::make_shared(); + textNodeTran->SetTextContent("translate"); + textNodeTran->SetWidth(MIDDLE_LENGTH); + textNodeTran->SetHeight(SMALL_LENGTH); + auto columnTran = std::make_shared(); + columnTran->SetWidth(SMALL_LENGTH); + columnTran->SetHeight(SMALL_LENGTH); + columnTran->SetBackgroundColor(COLOR_PINK); + columnTran->SetTranslate(SMALL_LENGTH, NUMBER_0, NUMBER_0); + + auto textNodeScale = std::make_shared(); + textNodeScale->SetTextContent("scale"); + textNodeScale->SetWidth(MIDDLE_LENGTH); + textNodeScale->SetHeight(SMALL_LENGTH); + auto columnScale = std::make_shared(); + columnScale->SetWidth(SMALL_LENGTH); + columnScale->SetHeight(SMALL_LENGTH); + columnScale->SetBackgroundColor(COLOR_PINK); + columnScale->SetScale(NUMBER_2, NUMBER_05); + + auto textNodeRotate = std::make_shared(); + textNodeRotate->SetTextContent("rotate"); + textNodeRotate->SetWidth(SMALL_LENGTH); + textNodeRotate->SetHeight(SMALL_LENGTH); + auto columnRotate = std::make_shared(); + columnRotate->SetWidth(SMALL_LENGTH); + columnRotate->SetHeight(SMALL_LENGTH); + columnRotate->SetBackgroundColor(COLOR_PINK); + columnRotate->SetRotate(NUMBER_0, NUMBER_0, NUMBER_1, LARGE_LENGTH, NUMBER_0); + + column->AddChild(textNodeTran); + column->AddChild(columnTran); + column->AddChild(textNodeScale); + column->AddChild(columnScale); + column->AddChild(textNodeRotate); + column->AddChild(columnRotate); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode2() +{ + auto column = std::make_shared(); + auto textNodeBrightness = std::make_shared(); + textNodeBrightness->SetTextContent("Brightness"); + textNodeBrightness->SetWidth(MIDDLE_LENGTH); + textNodeBrightness->SetHeight(SMALL_LENGTH); + auto columnBrightness = std::make_shared(); + columnBrightness->SetWidth(NUMBER_100); + columnBrightness->SetHeight(NUMBER_100); + columnBrightness->SetBackgroundColor(COLOR_PINK); + columnBrightness->SetBrightness(NUMBER_05); + column->AddChild(textNodeBrightness); + column->AddChild(columnBrightness); + + auto textNodeSaturate = std::make_shared(); + textNodeSaturate->SetTextContent("saturate"); + textNodeSaturate->SetWidth(MIDDLE_LENGTH); + textNodeSaturate->SetHeight(SMALL_LENGTH); + auto columnSaturate = std::make_shared(); + columnSaturate->SetWidth(NUMBER_100); + columnSaturate->SetHeight(NUMBER_100); + columnSaturate->SetBackgroundColor(COLOR_PINK); + columnSaturate->SetSaturate(NUMBER_30); + column->AddChild(textNodeSaturate); + column->AddChild(columnSaturate); + + auto textNodeBlur = std::make_shared(); + textNodeBlur->SetTextContent("blur"); + textNodeBlur->SetWidth(MIDDLE_LENGTH); + textNodeBlur->SetHeight(SMALL_LENGTH); + + auto text = std::make_shared(); + text->SetTextContent("NODE_BLUR"); + text->SetWidth(MIDDLE_LENGTH); + text->SetHeight(NUMBER_100); + text->SetBackgroundColor(COLOR_PINK); + text->SetBlur(NUMBER_10); + column->AddChild(textNodeBlur); + column->AddChild(text); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode3() +{ + auto column = std::make_shared(); + auto textNodeLinearGradient = std::make_shared(); + textNodeLinearGradient->SetTextContent("linearGradient"); + textNodeLinearGradient->SetWidth(MIDDLE_LENGTH); + textNodeLinearGradient->SetHeight(SMALL_LENGTH); + auto columnLinearGradient = std::make_shared(); + columnLinearGradient->SetWidth(NUMBER_100); + columnLinearGradient->SetHeight(NUMBER_100); + columnLinearGradient->SetLinearGradient(NUMBER_90, ARKUI_LINEAR_GRADIENT_DIRECTION_CUSTOM, NUMBER_0); + column->AddChild(textNodeLinearGradient); + column->AddChild(columnLinearGradient); + + auto textNodeOpacity = std::make_shared(); + textNodeOpacity->SetTextContent("opacity"); + textNodeOpacity->SetWidth(MIDDLE_LENGTH); + textNodeOpacity->SetHeight(SMALL_LENGTH); + auto columnOpacity = std::make_shared(); + columnOpacity->SetWidth(NUMBER_100); + columnOpacity->SetHeight(NUMBER_100); + columnOpacity->SetBackgroundColor(COLOR_PINK); + columnOpacity->SetOpacity(NUMBER_03); + column->AddChild(textNodeOpacity); + column->AddChild(columnOpacity); + + auto textNodeClip = std::make_shared(); + textNodeClip->SetTextContent("clip"); + textNodeClip->SetWidth(MIDDLE_LENGTH); + textNodeClip->SetHeight(SMALL_LENGTH); + auto columnInside = std::make_shared(); + columnInside->SetWidth(NUMBER_100); + columnInside->SetHeight(NUMBER_100); + columnInside->SetBackgroundColor(COLOR_PINK); + columnInside->SetBorderRadius(NUMBER_20); + auto columnClip = std::make_shared(); + columnClip->SetBorderRadius(NUMBER_20); + columnClip->SetClip(NUMBER_1); + columnClip->AddChild(columnInside); + column->AddChild(textNodeClip); + column->AddChild(columnClip); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode4() +{ + auto column = std::make_shared(); + auto textNodeCircleShape = std::make_shared(); + textNodeCircleShape->SetTextContent("CircleShape"); + textNodeCircleShape->SetWidth(MIDDLE_LENGTH); + textNodeCircleShape->SetHeight(SMALL_LENGTH); + auto columnCircleShape = std::make_shared(); + columnCircleShape->SetWidth(MIDDLE_LENGTH); + columnCircleShape->SetHeight(MIDDLE_LENGTH); + columnCircleShape->SetBackgroundColor(COLOR_PINK); + columnCircleShape->SetCircleShape(ARKUI_CLIP_TYPE_CIRCLE, MIDDLE_LENGTH, MIDDLE_LENGTH); + column->AddChild(textNodeCircleShape); + column->AddChild(columnCircleShape); + + auto textNodeTransform = std::make_shared(); + textNodeTransform->SetTextContent("Transform"); + textNodeTransform->SetWidth(MIDDLE_LENGTH); + textNodeTransform->SetHeight(SMALL_LENGTH); + auto columnTransform = std::make_shared(); + columnTransform->SetWidth(MIDDLE_LENGTH); + columnTransform->SetHeight(MIDDLE_LENGTH); + columnTransform->SetBackgroundColor(COLOR_PINK); + columnTransform->SetTransform(); + column->AddChild(textNodeTransform); + column->AddChild(columnTransform); + + auto textNodeShadow = std::make_shared(); + textNodeShadow->SetTextContent("Shadow"); + textNodeShadow->SetWidth(MIDDLE_LENGTH); + textNodeShadow->SetHeight(SMALL_LENGTH); + auto columnShadow = std::make_shared(); + columnShadow->SetWidth(MIDDLE_LENGTH); + columnShadow->SetHeight(MIDDLE_LENGTH); + columnShadow->SetBackgroundColor(COLOR_PINK); + columnShadow->SetShadow(ARKUI_SHADOW_STYLE_OUTER_DEFAULT_LG); + column->AddChild(textNodeShadow); + column->AddChild(columnShadow); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode5() +{ + auto column = std::make_shared(); + auto textNodeSweepGradient = std::make_shared(); + textNodeSweepGradient->SetTextContent("sweepGradient"); + textNodeSweepGradient->SetWidth(MIDDLE_LENGTH); + textNodeSweepGradient->SetHeight(SMALL_LENGTH); + auto columnSweepGradient = std::make_shared(); + columnSweepGradient->SetWidth(MIDDLE_LENGTH); + columnSweepGradient->SetHeight(MIDDLE_LENGTH); + columnSweepGradient->SetBackgroundColor(COLOR_PINK); + columnSweepGradient->SetSweepGradient(); + column->AddChild(textNodeSweepGradient); + column->AddChild(columnSweepGradient); + + auto textNodeRadialGradient = std::make_shared(); + textNodeRadialGradient->SetTextContent("radialGradient"); + textNodeRadialGradient->SetWidth(MIDDLE_LENGTH); + textNodeRadialGradient->SetHeight(SMALL_LENGTH); + auto columnRadialGradient = std::make_shared(); + columnRadialGradient->SetWidth(MIDDLE_LENGTH); + columnRadialGradient->SetHeight(MIDDLE_LENGTH); + columnSweepGradient->SetBackgroundColor(COLOR_PINK); + columnRadialGradient->SetRadialGradient(); + column->AddChild(textNodeRadialGradient); + column->AddChild(columnRadialGradient); + + auto textNodeMask = std::make_shared(); + textNodeMask->SetTextContent("mask"); + textNodeMask->SetWidth(MIDDLE_LENGTH); + textNodeMask->SetHeight(SMALL_LENGTH); + auto columnMask = std::make_shared(); + columnMask->SetWidth(MIDDLE_LENGTH); + columnMask->SetHeight(MIDDLE_LENGTH); + columnMask->SetBackgroundColor(COLOR_PINK); + columnMask->SetMask(); + column->AddChild(textNodeMask); + column->AddChild(columnMask); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode6() +{ + auto column = std::make_shared(); + auto textNodeGrayScale = std::make_shared(); + textNodeGrayScale->SetTextContent("GrayScale"); + textNodeGrayScale->SetWidth(MIDDLE_LENGTH); + textNodeGrayScale->SetHeight(SMALL_LENGTH); + auto columnGrayScale = std::make_shared(); + columnGrayScale->SetWidth(MIDDLE_LENGTH); + columnGrayScale->SetHeight(MIDDLE_LENGTH); + columnGrayScale->SetBackgroundColor(COLOR_PINK); + columnGrayScale->SetGrayScale(NUMBER_05); + column->AddChild(textNodeGrayScale); + column->AddChild(columnGrayScale); + + auto textNodeInvert = std::make_shared(); + textNodeInvert->SetTextContent("Invert"); + textNodeInvert->SetWidth(MIDDLE_LENGTH); + textNodeInvert->SetHeight(SMALL_LENGTH); + auto columnInvert = std::make_shared(); + columnInvert->SetWidth(MIDDLE_LENGTH); + columnInvert->SetHeight(MIDDLE_LENGTH); + columnInvert->SetBackgroundColor(COLOR_PINK); + columnInvert->SetInvert(NUMBER_05); + column->AddChild(textNodeInvert); + column->AddChild(columnInvert); + + auto textNodeSepia = std::make_shared(); + textNodeSepia->SetTextContent("Sepia"); + textNodeSepia->SetWidth(MIDDLE_LENGTH); + textNodeSepia->SetHeight(SMALL_LENGTH); + auto columnSepia = std::make_shared(); + columnSepia->SetWidth(MIDDLE_LENGTH); + columnSepia->SetHeight(MIDDLE_LENGTH); + columnSepia->SetBackgroundColor(COLOR_PINK); + columnSepia->SetSepia(NUMBER_05); + column->AddChild(textNodeSepia); + column->AddChild(columnSepia); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode7() +{ + auto column = std::make_shared(); + auto textNodeContrast = std::make_shared(); + textNodeContrast->SetTextContent("Contrast"); + textNodeContrast->SetWidth(MIDDLE_LENGTH); + textNodeContrast->SetHeight(SMALL_LENGTH); + auto columnContrast = std::make_shared(); + columnContrast->SetWidth(MIDDLE_LENGTH); + columnContrast->SetHeight(MIDDLE_LENGTH); + columnContrast->SetBackgroundColor(COLOR_PINK); + columnContrast->SetContrast(NUMBER_01); + column->AddChild(textNodeContrast); + column->AddChild(columnContrast); + + auto columBlank = std::make_shared(); + columBlank->SetHeight(NUMBER_20); + column->AddChild(columBlank); + + auto textNodeForegroundColor = std::make_shared(); + textNodeForegroundColor->SetTextContent("ForegroundColor"); + textNodeForegroundColor->SetWidth(MIDDLE_LENGTH); + textNodeForegroundColor->SetHeight(SMALL_LENGTH); + textNodeForegroundColor->SetBackgroundColor(COLOR_PINK); + textNodeForegroundColor->SetForegroundColor(COLOR_RED); + column->AddChild(textNodeForegroundColor); + + auto textNodeMarkAnchor = std::make_shared(); + textNodeMarkAnchor->SetTextContent("MarkAnchor"); + textNodeMarkAnchor->SetWidth(MIDDLE_LENGTH); + textNodeMarkAnchor->SetHeight(SMALL_LENGTH); + auto columnMarkAnchor = std::make_shared(); + columnMarkAnchor->SetWidth(MIDDLE_LENGTH); + columnMarkAnchor->SetHeight(MIDDLE_LENGTH); + columnMarkAnchor->SetBackgroundColor(COLOR_PINK); + auto textNode = std::make_shared(); + textNode->SetTextContent("text"); + textNode->SetHeight(NUMBER_25); + textNode->SetHeight(NUMBER_25); + textNode->SetMarkAnchor(NUMBER_25, NUMBER_25); + column->AddChild(textNodeMarkAnchor); + column->AddChild(columnMarkAnchor); + column->AddChild(textNode); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode8() +{ + auto column = std::make_shared(); + auto textNodeTranslateWithPercent = std::make_shared(); + textNodeTranslateWithPercent->SetTextContent("TranslateWithPercent"); + textNodeTranslateWithPercent->SetWidth(MIDDLE_LENGTH); + textNodeTranslateWithPercent->SetHeight(SMALL_LENGTH); + auto columnTranslateWithPercent = std::make_shared(); + columnTranslateWithPercent->SetWidth(MIDDLE_LENGTH); + columnTranslateWithPercent->SetHeight(MIDDLE_LENGTH); + columnTranslateWithPercent->SetBackgroundColor(COLOR_PINK); + columnTranslateWithPercent->SetTranslateWithPercent(NUMBER_04, NUMBER_02, NUMBER_0); + column->AddChild(textNodeTranslateWithPercent); + column->AddChild(columnTranslateWithPercent); + + auto textNodeRotateAngle = std::make_shared(); + textNodeRotateAngle->SetTextContent("RotateAngle"); + textNodeRotateAngle->SetWidth(MIDDLE_LENGTH); + textNodeRotateAngle->SetHeight(SMALL_LENGTH); + auto columnRotateAngle = std::make_shared(); + columnRotateAngle->SetWidth(MIDDLE_LENGTH); + columnRotateAngle->SetHeight(MIDDLE_LENGTH); + columnRotateAngle->SetBackgroundColor(COLOR_PINK); + columnRotateAngle->SetRotateAngle(NUMBER_45, NUMBER_45, NUMBER_0, NUMBER_0); + column->AddChild(textNodeRotateAngle); + column->AddChild(columnRotateAngle); + + auto textNodeCustomShadow = std::make_shared(); + textNodeCustomShadow->SetTextContent("CustomShadow"); + textNodeCustomShadow->SetWidth(MIDDLE_LENGTH); + textNodeCustomShadow->SetHeight(SMALL_LENGTH); + auto columnCustomShadow = std::make_shared(); + columnCustomShadow->SetWidth(MIDDLE_LENGTH); + columnCustomShadow->SetHeight(MIDDLE_LENGTH); + columnCustomShadow->SetBackgroundColor(COLOR_PINK); + columnCustomShadow->SetCustomShadow(); + column->AddChild(textNodeCustomShadow); + column->AddChild(columnCustomShadow); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode9() +{ + auto column = std::make_shared(); + auto textNodeBlurStyle = std::make_shared(); + textNodeBlurStyle->SetTextContent("BackgroundBlurStyle"); + textNodeBlurStyle->SetWidth(MIDDLE_LENGTH); + textNodeBlurStyle->SetHeight(SMALL_LENGTH); + auto columnBlurStyle = std::make_shared(); + columnBlurStyle->SetWidth(MIDDLE_LENGTH); + columnBlurStyle->SetHeight(MIDDLE_LENGTH); + columnBlurStyle->SetBackgroundColor(COLOR_PINK); + columnBlurStyle->SetBackgroundBlurStyle(ARKUI_BLUR_STYLE_THICK); + column->AddChild(textNodeBlurStyle); + column->AddChild(columnBlurStyle); + + auto textNodeForegroundBlurStyle = std::make_shared(); + textNodeForegroundBlurStyle->SetTextContent("ForegroundBlurStyle"); + textNodeForegroundBlurStyle->SetWidth(MIDDLE_LENGTH); + textNodeForegroundBlurStyle->SetHeight(SMALL_LENGTH); + auto columnTextNode = std::make_shared(); + columnTextNode->SetTextContent("厚材质模糊"); + columnTextNode->SetWidth(MIDDLE_LENGTH); + columnTextNode->SetHeight(SMALL_LENGTH); + columnTextNode->SetBackgroundColor(COLOR_PINK); + columnTextNode->SetForegroundBlurStyle(ARKUI_BLUR_STYLE_THICK); + column->AddChild(textNodeForegroundBlurStyle); + column->AddChild(columnTextNode); + + auto textNodeTranslateWithPercent = std::make_shared(); + textNodeTranslateWithPercent->SetTextContent("TranslateWithPercent"); + textNodeTranslateWithPercent->SetWidth(MIDDLE_LENGTH); + textNodeTranslateWithPercent->SetHeight(SMALL_LENGTH); + auto columnTranslateWithPercent = std::make_shared(); + columnTranslateWithPercent->SetWidth(MIDDLE_LENGTH); + columnTranslateWithPercent->SetHeight(MIDDLE_LENGTH); + columnTranslateWithPercent->SetBackgroundColor(COLOR_PINK); + columnTranslateWithPercent->SetTranslateWithPercent(NUMBER_04, -NUMBER_02, NUMBER_0); + column->AddChild(textNodeTranslateWithPercent); + column->AddChild(columnTranslateWithPercent); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode10() +{ + auto column = std::make_shared(); + auto textNodeBackdropBlur = std::make_shared(); + textNodeBackdropBlur->SetTextContent("BackdropBlur"); + textNodeBackdropBlur->SetWidth(MIDDLE_LENGTH); + textNodeBackdropBlur->SetHeight(SMALL_LENGTH); + textNodeBackdropBlur->SetBackgroundColor(COLOR_PINK); + auto textNode = std::make_shared(); + textNode->SetTextContent("backdropBlur"); + textNode->SetWidth(MIDDLE_LENGTH); + textNode->SetHeight(MIDDLE_LENGTH); + textNode->SetBackgroundColor(COLOR_PINK); + textNode->SetBackdropBlur(NUMBER_20); + column->AddChild(textNodeBackdropBlur); + column->AddChild(textNode); + + auto textNodeRenderGroup = std::make_shared(); + textNodeRenderGroup->SetTextContent("RenderGroup"); + textNodeRenderGroup->SetWidth(MIDDLE_LENGTH); + textNodeRenderGroup->SetHeight(SMALL_LENGTH); + auto column1 = std::make_shared(); + column1->SetWidth(MIDDLE_LENGTH); + column1->SetHeight(MIDDLE_LENGTH); + column1->SetBackgroundColor(COLOR_BLACK); + column1->SetOpacity(NUMBER_1); + column1->SetColumnJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + + auto column2 = std::make_shared(); + column2->SetWidth(NUMBER_150); + column2->SetHeight(NUMBER_150); + column2->SetBackgroundColor(COLOR_WHITE); + column2->SetColumnJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + column2->SetOpacity(NUMBER_06); + column2->SetRenderGroup(NUMBER_1); + + auto column3 = std::make_shared(); + column3->SetWidth(NUMBER_100); + column3->SetHeight(NUMBER_100); + column3->SetBackgroundColor(COLOR_BLACK); + column3->SetOpacity(NUMBER_1); + column3->SetColumnJustifyContent(ARKUI_FLEX_ALIGNMENT_CENTER); + + column->AddChild(textNodeRenderGroup); + column->AddChild(column1); + column1->AddChild(column2); + column2->AddChild(column3); + column->AddChild(column1); + + return column; +} + + +} // namespace NativeModule + +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/NativeModule.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/NativeModule.h new file mode 100644 index 000000000..a46cd0b11 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/NativeModule.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_NATIVEMODULE_H +#define MYAPPLICATION_NATIVEMODULE_H + +#include +#include +#include +#include + +namespace NativeModule { + +class NativeModuleInstance { +public: + static NativeModuleInstance *GetInstance() + { + static NativeModuleInstance instance; + return &instance; + } + + NativeModuleInstance() + { + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, arkUINativeNodeApi_); + } + ArkUI_NativeNodeAPI_1 *GetNativeNodeAPI() { return arkUINativeNodeApi_; } + +private: + ArkUI_NativeNodeAPI_1 *arkUINativeNodeApi_ = nullptr; +}; +} // namespace NativeModule +#endif // MYAPPLICATION_NATIVEMODULE_H \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.cpp b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.cpp index 3309abb2a..600bc784e 100644 --- a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.cpp +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.cpp @@ -14,6 +14,8 @@ */ #include "manager.h" +#include "ArkUIAnimationNode.h" +#include "ArkUIVisualEffectsNode.h" #include "NavigationContext.h" #include "napi/native_api.h" #include @@ -22,6 +24,8 @@ #include #include #include +#include +#include Manager Manager::manager_; ArkUI_NativeNodeAPI_1 *Manager::nodeAPI_ = reinterpret_cast( @@ -59,4 +63,250 @@ napi_value Manager::CreateNativeNaviNode(napi_env env, napi_callback_info info) } } return nullptr; +} + +napi_value createNativeRootAnimation1(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode1(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation2(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode2(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation3(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode3(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation4(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode4(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation5(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode5(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects1(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode1(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects2(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode2(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects3(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode3(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects4(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode4(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects5(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode5(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects6(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode6(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects7(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode7(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects8(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode8(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects9(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode9(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects10(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode10(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value DestroyNativeRoot(napi_env env, napi_callback_info info) +{ + Manager::GetInstance()->DisposeRootNode(); + return nullptr; } \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.h b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.h index 935bb89e6..058227c4a 100644 --- a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.h +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/manager.h @@ -16,6 +16,7 @@ #ifndef NATIVE_NODE_NAPI_SAMPLE_MANAGER_H #define NATIVE_NODE_NAPI_SAMPLE_MANAGER_H +#include "ArkUIBaseNode.h" #include #include #include @@ -25,15 +26,56 @@ #include #include +napi_value createNativeRootAnimation1(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation2(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation3(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation4(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation5(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects1(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects2(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects3(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects4(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects5(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects6(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects7(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects8(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects9(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects10(napi_env env, napi_callback_info info); +napi_value DestroyNativeRoot(napi_env env, napi_callback_info info); + const unsigned int LOG_PRINT_DOMAIN = 0xFF00; class Manager { public: static ArkUI_NativeNodeAPI_1 *nodeAPI_; ~Manager(){}; + static Manager *GetInstance() + { + static Manager nativeEntry; + return &nativeEntry; + } + + void SetContentHandle(ArkUI_NodeContentHandle handle) + { + handle_ = handle; + } + + void SetRootNode(const std::shared_ptr &baseNode) + { + root_ = baseNode; + OH_ArkUI_NodeContent_AddNode(handle_, root_->GetHandle()); + } + void DisposeRootNode() + { + OH_ArkUI_NodeContent_RemoveNode(handle_, root_->GetHandle()); + root_.reset(); + } + static napi_value CreateNativeNaviNode(napi_env env, napi_callback_info info); private: static Manager manager_; + std::shared_ptr root_; + ArkUI_NodeContentHandle handle_; }; #endif // NATIVE_NODE_NAPI_SAMPLE_MANAGER_H diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/napi_init.cpp index 95bb78be2..46c21ea76 100644 --- a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/napi_init.cpp +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/napi_init.cpp @@ -28,7 +28,37 @@ static napi_value Init(napi_env env, napi_value exports) napi_property_descriptor desc[] = { {"createNativeNaviNode", nullptr, Manager::CreateNativeNaviNode, nullptr, nullptr, nullptr, napi_default, nullptr}, - // 参考Navigation新增其他createNative方法和Context类 + {"createNativeRootAnimation1", nullptr, createNativeRootAnimation1, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation2", nullptr, createNativeRootAnimation2, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation3", nullptr, createNativeRootAnimation3, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation4", nullptr, createNativeRootAnimation4, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation5", nullptr, createNativeRootAnimation5, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects1", nullptr, createNativeRootVisualEffects1, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects2", nullptr, createNativeRootVisualEffects2, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects3", nullptr, createNativeRootVisualEffects3, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects4", nullptr, createNativeRootVisualEffects4, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects5", nullptr, createNativeRootVisualEffects5, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects6", nullptr, createNativeRootVisualEffects6, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects7", nullptr, createNativeRootVisualEffects7, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects8", nullptr, createNativeRootVisualEffects8, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects9", nullptr, createNativeRootVisualEffects9, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects10", nullptr, createNativeRootVisualEffects10, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyNativeRoot", nullptr, DestroyNativeRoot, nullptr, nullptr, nullptr, napi_default, nullptr}, }; if (napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc) != napi_ok) { diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/types/libentry/Index.d.ts index 8f0d36c6a..a3516e2a9 100644 --- a/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/cpp/types/libentry/Index.d.ts @@ -13,4 +13,20 @@ * limitations under the License. */ -export const createNativeNaviNode: (content: Object) =>void; \ No newline at end of file +export const createNativeNaviNode: (content: Object) =>void; +export const createNativeRootAnimation1: (content: Object) => void; +export const createNativeRootAnimation2: (content: Object) => void; +export const createNativeRootAnimation3: (content: Object) => void; +export const createNativeRootAnimation4: (content: Object) => void; +export const createNativeRootAnimation5: (content: Object) => void; +export const createNativeRootVisualEffects1: (content: Object) => void; +export const createNativeRootVisualEffects2: (content: Object) => void; +export const createNativeRootVisualEffects3: (content: Object) => void; +export const createNativeRootVisualEffects4: (content: Object) => void; +export const createNativeRootVisualEffects5: (content: Object) => void; +export const createNativeRootVisualEffects6: (content: Object) => void; +export const createNativeRootVisualEffects7: (content: Object) => void; +export const createNativeRootVisualEffects8: (content: Object) => void; +export const createNativeRootVisualEffects9: (content: Object) => void; +export const createNativeRootVisualEffects10: (content: Object) => void; +export const destroyNativeRoot: () => void; \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/Index.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/Index.ets index 6b8a15b09..9f5f3be3d 100644 --- a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/Index.ets +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/Index.ets @@ -27,6 +27,8 @@ struct MenuIndex { [ { title: 'Navigation', url: 'pages/page_navigation' }, { title: 'add your router', url: 'pages/page_navigation' }, + { title: 'Animation', url: 'pages/page_animation' }, + { title: 'Visual Effects', url: 'pages/page_visual_effects' }, ]; build() { diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex1.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex1.ets new file mode 100644 index 000000000..718551ca4 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex1.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation1(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex2.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex2.ets new file mode 100644 index 000000000..e0da3b358 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex2.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation2(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex3.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex3.ets new file mode 100644 index 000000000..4acc67fe2 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex3.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation3(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex4.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex4.ets new file mode 100644 index 000000000..c73973af7 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex4.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation4(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex5.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex5.ets new file mode 100644 index 000000000..767658ca2 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/animation/animationIndex5.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation5(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_animation.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_animation.ets new file mode 100644 index 000000000..2f0eb49df --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_animation.ets @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +interface ListCategories { + title:string, + url:string +} + +@Entry +@Component +struct AnimationIndex { + @State message: string = 'CApi'; + @State isShow: boolean = false; + private items : ListCategories[] = [ + {title:'NODE_TRANSFORM_CENTER, NODE_TRANSITION',url:'pages/animation/animationIndex1'}, + {title:'NODE_OPACITY_TRANSITION,NODE_ROTATE_TRANSITION,NODE_SCALE_TRANSITION',url:'pages/animation/animationIndex2'}, + {title:'NODE_TRANSLATE_TRANSITION,NODE_MOVE_TRANSITION,',url:'pages/animation/animationIndex3'}, + {title:'NODE_RENDER_FIT',url:'pages/animation/animationIndex4'}, + {title:'NODE_GEOMETRY_TRANSITION',url:'pages/animation/animationIndex5'}, + ]; + + @Builder cApiMenu() { + Grid() { + ForEach(this.items, (item: ListCategories) => { + GridItem() { + Button(item.title) + .key(item.title) + .width('100%') + .height('100%') + .fontSize(10) + .padding(1) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr') + .columnsGap(8) + .rowsGap(8) + .width('100%') + } + + build() { + Scroll(new Scroller()) { + Column() { + Stack() { + Row() { + Text(this.message) + .fontSize(22) + .fontColor(0xFFFFFF) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width('100%') + .height(50) + .backgroundColor('#FF08528A') + }.width('100%') + Button('menu') + .key('menu') + .onClick(() => { + this.isShow = true; + }) + .fontSize(10) + .position({top: 5, right: 5}) + .backgroundColor(Color.Transparent) + .fontColor(Color.Transparent) + .bindSheet($$this.isShow, this.cApiMenu(), { + showClose: false, + preferType: SheetType.BOTTOM + }) + } + + List({ space: '20vp' }) { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Button(item.title) + .fontSize(15) + .labelStyle({ maxLines: 10 }) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('90%').height('90%') + }.width('100%').height('100%').backgroundColor('#FFDDE7F6') + } + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_visual_effects.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_visual_effects.ets new file mode 100644 index 000000000..66da8b323 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/page_visual_effects.ets @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +interface ListCategories { + title:string, + url:string +} + +@Entry +@Component +struct VisualEffectsIndex { + @State message: string = 'CApi'; + @State isShow: boolean = false; + private items : ListCategories[] = [ + {title:'NODE_TRANSLATE,NODE_SCALE,NODE_ROTATE',url:'pages/visualEffects/visualEffectsIndex1'}, + {title:'NODE_BRIGHTNESS,NODE_SATURATION,NODE_BLUR',url:'pages/visualEffects/visualEffectsIndex2'}, + {title:'NODE_LINEAR_GRADIENT,NODE_OPACITY,NODE_CLIP',url:'pages/visualEffects/visualEffectsIndex3'}, + {title:'NODE_CLIP_SHAPE,NODE_TRANSFORM,NODE_SHADOW',url:'pages/visualEffects/visualEffectsIndex4'}, + {title:'NODE_SWEEP_GRADIENT,NODE_RADIAL_GRADIENT,NODE_MASK',url:'pages/visualEffects/visualEffectsIndex5'}, + {title:'NODE_GRAY_SCALE,NODE_INVERT,NODE_SEPIA',url:'pages/visualEffects/visualEffectsIndex6'}, + {title:'NODE_CONTRAST,NODE_FOREGROUND_COLOR,NODE_MARK_ANCHOR',url:'pages/visualEffects/visualEffectsIndex7'}, + {title:'NODE_TRANSLATE_WITH_PERCENT,NODE_ROTATE_ANGLE,NODE_CUSTOM_SHADOW', + url:'pages/visualEffects/visualEffectsIndex8'}, + {title:'NODE_BACKGROUND_BLUR_STYLE,NODE_FOREGROUND_BLUR_STYLE,NODE_COLOR_BLEND', + url:'pages/visualEffects/visualEffectsIndex9'}, + {title:'NODE_BACKDROP_BLUR,NODE_RENDER_GROUP',url:'pages/visualEffects/visualEffectsIndex10'}, + ]; + + @Builder cApiMenu() { + Grid() { + ForEach(this.items, (item: ListCategories) => { + GridItem() { + Button(item.title) + .key(item.title) + .width('100%') + .height('100%') + .fontSize(10) + .padding(1) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr') + .columnsGap(8) + .rowsGap(8) + .width('100%') + } + + build() { + Scroll(new Scroller()) { + Column() { + Stack() { + Row() { + Text(this.message) + .fontSize(22) + .fontColor(0xFFFFFF) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width('100%') + .height(50) + .backgroundColor('#FF08528A') + }.width('100%') + Button('menu') + .key('menu') + .onClick(() => { + this.isShow = true; + }) + .fontSize(10) + .position({top: 5, right: 5}) + .backgroundColor(Color.Transparent) + .fontColor(Color.Transparent) + .bindSheet($$this.isShow, this.cApiMenu(), { + showClose: false, + preferType: SheetType.BOTTOM + }) + } + + List({ space: '20vp' }) { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Button(item.title) + .fontSize(15) + .labelStyle({ maxLines: 10 }) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('90%').height('90%') + }.width('100%').height('100%').backgroundColor('#FFDDE7F6') + } + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets new file mode 100644 index 000000000..94fc947ff --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects1(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex10.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex10.ets new file mode 100644 index 000000000..851093f08 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex10.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects10(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets new file mode 100644 index 000000000..d8f357ffd --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects2(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets new file mode 100644 index 000000000..bc29d96ff --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects3(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex4.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex4.ets new file mode 100644 index 000000000..4b6b68f61 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex4.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects4(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex5.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex5.ets new file mode 100644 index 000000000..ba1387c19 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex5.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects5(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex6.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex6.ets new file mode 100644 index 000000000..e84d7ef53 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex6.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects6(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex7.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex7.ets new file mode 100644 index 000000000..aa7002c7a --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex7.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects7(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex8.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex8.ets new file mode 100644 index 000000000..f709a9739 --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex8.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects8(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex9.ets b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex9.ets new file mode 100644 index 000000000..78da5607f --- /dev/null +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex9.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects9(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeNodeNapiSample/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/NativeNodeNapiSample/entry/src/main/resources/base/profile/main_pages.json index 0fab58386..a57d496de 100644 --- a/ArkUIKit/NativeNodeNapiSample/entry/src/main/resources/base/profile/main_pages.json +++ b/ArkUIKit/NativeNodeNapiSample/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,23 @@ { "src": [ "pages/Index", - "pages/page_navigation" + "pages/page_navigation", + "pages/page_animation", + "pages/animation/animationIndex1", + "pages/animation/animationIndex2", + "pages/animation/animationIndex3", + "pages/animation/animationIndex4", + "pages/animation/animationIndex5", + "pages/page_visual_effects", + "pages/visualEffects/visualEffectsIndex1", + "pages/visualEffects/visualEffectsIndex2", + "pages/visualEffects/visualEffectsIndex3", + "pages/visualEffects/visualEffectsIndex4", + "pages/visualEffects/visualEffectsIndex5", + "pages/visualEffects/visualEffectsIndex6", + "pages/visualEffects/visualEffectsIndex7", + "pages/visualEffects/visualEffectsIndex8", + "pages/visualEffects/visualEffectsIndex9", + "pages/visualEffects/visualEffectsIndex10" ] -} +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/README.md b/ArkUIKit/NativeTypeSample/README.md index 00ea12c0e..0b897fba9 100644 --- a/ArkUIKit/NativeTypeSample/README.md +++ b/ArkUIKit/NativeTypeSample/README.md @@ -1,8 +1,8 @@ -# Native_type_Sample +# Native_node_Sample ## 介绍 -本示例展示了如何创建文本、输入框、文本域等组件,配置其样式、属性与事件设置等功能,构建文本页面。 +本示例展示了如何创建文本、输入框、文本域、视效、动效等组件,配置其样式、属性与事件设置等功能,构建文本页面。 ## 效果预览 @@ -18,16 +18,27 @@ ## 工程目录 ``` -Native_type_Sample +StyledStringNDK entry/src/main/ets/ └── pages ├── Index.ets (获取导航页面) + ├── page_animation.ets (动效界面) + ├── page_visual_effects.ets (视效界面) └── page_text.ets (文本界面) entry/src/main/ ├── cpp │ ├── types │ │ └── libentry │ │ └── Index.d.ts (函数对应的js映射) +│ ├── ArkUIAnimationNode.h +│ ├── ArkUIBaseNode.h +│ ├── ArkUIButtonNode.h +│ ├── ArkUIColumnNode.h +│ ├── ArkUINode.h +│ ├── ArkUINumber.h +│ ├── ArkUITextNode.h +│ ├── ArkUIVisualEffectsNode.h +│ ├── NativeModule.h │ ├── CMakeLists.txt (CMake脚本) | ├── manager.cpp | ├── manager.h @@ -69,7 +80,7 @@ entry/src/main/ ``` git init git config core.sparsecheckout true -echo code/DocsSample/NativeType/native_type_sample > .git/info/sparse-checkout +echo code/DocsSample/NativeType/native_node_sample > .git/info/sparse-checkout git remote add origin https://gitcode.com/openharmony/applications_app_samples.git git pull origin master ``` \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIAnimationNode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIAnimationNode.h new file mode 100644 index 000000000..95003e746 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIAnimationNode.h @@ -0,0 +1,518 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIDOBASENODE_H +#define MYAPPLICATION_ARKUIDOBASENODE_H +#include "ArkUIColumnNode.h" +#include "ArkUITextNode.h" +#include "ArkUINumber.h" +#include "ArkUIButtonNode.h" +#include + +namespace NativeModule { +constexpr int32_t NUM_100 = 100; +constexpr int32_t NUM_120 = 120; +constexpr int32_t NUM_150 = 150; +constexpr int32_t NUM_200 = 200; +constexpr int32_t NUM_250 = 250; +constexpr int32_t NUM_300 = 300; +constexpr int32_t NUM_400 = 400; +constexpr int32_t NUM_500 = 500; +constexpr int32_t NUM_1000 = 1000; +constexpr int32_t NUM_1500 = 1500; +constexpr int32_t NUM_2000 = 2000; +constexpr int32_t NUM_0 = 0; +constexpr int32_t NUM_1 = 1; +constexpr int32_t NUM_2 = 2; +constexpr int32_t NUM_3 = 3; +constexpr int32_t NUM_4 = 4; +constexpr int32_t NUM_5 = 5; +constexpr int32_t NUM_6 = 6; +constexpr int32_t NUM_7 = 7; +constexpr int32_t NUM_8 = 8; +constexpr int32_t NUM_9 = 9; +constexpr int32_t NUM_10 = 10; +constexpr int32_t NUM_20 = 20; +constexpr int32_t NUM_30 = 30; +constexpr int32_t NUM_40 = 40; +constexpr int32_t NUM_50 = 50; +constexpr int32_t NUM_60 = 60; +constexpr int32_t NUM_80 = 80; +std::shared_ptr g_keyframe_button = nullptr; +std::shared_ptr g_keyframe_text = nullptr; +std::shared_ptr g_animateto_button = nullptr; +std::shared_ptr g_animateto_text = nullptr; +std::shared_ptr g_transition_button = nullptr; +std::shared_ptr g_animator_button = nullptr; +std::shared_ptr g_animator_text = nullptr; +ArkUI_AnimatorHandle animatorHandle = nullptr; +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; + +struct KeyFrameAnimateToData { + ArkUI_KeyframeAnimateOption* option; + ArkUI_CurveHandle curve; +}; + +struct AnimateData { + ArkUI_AnimateOption* option; + ArkUI_CurveHandle curve; +}; + +struct TransitionData { + ArkUI_AnimateOption* option; + ArkUI_TransitionEffect* effect; +}; +std::shared_ptr CreateAnimationFrameNode1() +{ + auto column = std::make_shared(); + auto textNodeMoveTransition = std::make_shared(); + textNodeMoveTransition->SetTextContent("ArkUI_TransitionEdge"); + textNodeMoveTransition->SetWidth(MIDDLE_LENGTH); + textNodeMoveTransition->SetHeight(SMALL_LENGTH); + auto columnMoveTransition = std::make_shared(); + columnMoveTransition->SetWidth(MIDDLE_LENGTH); + columnMoveTransition->SetHeight(MIDDLE_LENGTH); + columnMoveTransition->SetBackgroundColor(COLOR_PINK); + columnMoveTransition->SetMoveTransition(); + column->AddChild(textNodeMoveTransition); + column->AddChild(columnMoveTransition); + + return column; +} + +std::shared_ptr CreateAnimationFrameNode2() +{ + auto column = std::make_shared(); + auto textNode = std::make_shared(); + textNode->SetTextContent("ArkUI_RenderFit"); + textNode->SetWidth(MIDDLE_LENGTH); + textNode->SetHeight(SMALL_LENGTH); + + auto text = std::make_shared(); + text->SetWidth(MIDDLE_LENGTH); + text->SetHeight(SMALL_LENGTH); + text->SetBackgroundColor(COLOR_PINK); + text->SetTextContent("NODE_RENDER_FIT"); + text->SetRenderFit(ARKUI_RENDER_FIT_BOTTOM); + + g_keyframe_text = text; + text->RegisterNodeEvent(text->GetHandle(), NODE_ON_CLICK, NUMBER_1, nullptr); + auto onTouch1 = [](ArkUI_NodeEvent *event) { + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUMBER_1) { + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_keyframe_text->GetHandle()); + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + static ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + completeCallback->callback = [](void *userData) { + }; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + g_keyframe_text->SetWidth(LARGE_LENGTH); + g_keyframe_text->SetHeight(MIDDLE_LENGTH); + g_keyframe_text->SetBackgroundColor(COLOR_RED); + }; + animateApi->animateTo(context, option, update, completeCallback); + } + }; + text->RegisterNodeEventReceiver(onTouch1); + column->AddChild(textNode); + column->AddChild(text); + + return column; +} + +std::shared_ptr CreateAnimeteto() +{ + auto column = std::make_shared(); + column->SetWidth(NUM_300); + column->SetHeight(NUM_250); + // 创建文本节点,内容区介绍“这是animateto动画” + auto textNode = std::make_shared(); + textNode->SetTextContent("这是animateto动画"); + textNode->SetWidth(NUM_150); + textNode->SetHeight(NUM_50); + // 创建button,后续创建的动画作用在button组件上 + auto button = std::make_shared(); + // 设置button初始宽高及颜色 + button->SetWidth(NUM_100); + button->SetHeight(NUM_100); + button->SetBackgroundColor(0xFFA280FF); + // 存储button全局变量,在onTouch注册时需要使用 + g_animateto_button = button; + // 注册点击事件到button上 + button->RegisterNodeEvent(button->GetHandle(), NODE_ON_CLICK, NUM_2, nullptr); + g_animateto_text = std::make_shared(); + g_animateto_text->AnimatetoToString(); + auto onTouch = [](ArkUI_NodeEvent *event) { + // 获取context对象 + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_animateto_button->GetHandle()); + // 点击button按钮时触发该逻辑 + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUM_2) { + // 获取ArkUI_NativeAnimateAPI接口 + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + + // 设置动画参数 + ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetDuration(option, NUM_2000); + OH_ArkUI_AnimateOption_SetTempo(option, 1.1); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + ArkUI_CurveHandle cubicBezierCurve = OH_ArkUI_Curve_CreateCubicBezierCurve(0.5f, 4.0f, 1.2f, 0.0f); + // 设置动画的动画曲线,优先于OH_ArkUI_AnimateOption_SetCurve生效 + OH_ArkUI_AnimateOption_SetICurve(option, cubicBezierCurve); + OH_ArkUI_AnimateOption_SetDelay(option, NUM_20); + OH_ArkUI_AnimateOption_SetIterations(option, NUM_1); + OH_ArkUI_AnimateOption_SetPlayMode(option, ARKUI_ANIMATION_PLAY_MODE_REVERSE); + ArkUI_ExpectedFrameRateRange *range = new ArkUI_ExpectedFrameRateRange; + range->min = NUM_10; + range->max = NUM_120; + range->expected = NUM_60; + OH_ArkUI_AnimateOption_SetExpectedFrameRateRange(option, range); + + // 设置完成的回调 + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + AnimateData* data = new AnimateData(); + data->option = option; + data->curve = cubicBezierCurve; + completeCallback->userData = reinterpret_cast(data); + completeCallback->callback = [](void *userData) { + AnimateData* data = reinterpret_cast(userData); + if (data) { + ArkUI_AnimateOption* option = data->option; + ArkUI_CurveHandle curve = data->curve; + if (option) { + OH_ArkUI_AnimateOption_Dispose(option); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "Init", "CXX OH_ArkUI_AnimateOption_Dispose success!"); + } + if (curve) { + OH_ArkUI_Curve_DisposeCurve(curve); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "Init", "CXX OH_ArkUI_Curve_DisposeCurve success!"); + } + delete data; // 释放结构体 + } + }; + + // 设置闭包函数 + static bool isback = true; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + // 对应的属性变化 width height + if (isback) { + g_animateto_button->SetWidth(NUM_200); + g_animateto_button->SetHeight(NUM_80); + g_animateto_button->SetBackgroundColor(0xFFA280FF); + } else { + g_animateto_button->SetWidth(NUM_100); + g_animateto_button->SetHeight(NUM_40); + g_animateto_button->SetBackgroundColor(0xFFFF2E77); + } + isback = !isback; + }; + // 执行对应的动画 + animateApi->animateTo(context, option, update, completeCallback); + + auto duration = OH_ArkUI_AnimateOption_GetDuration(option); + auto tempo = OH_ArkUI_AnimateOption_GetTempo(option); + auto curve = OH_ArkUI_AnimateOption_GetCurve(option); + auto delay = OH_ArkUI_AnimateOption_GetDelay(option); + auto iteration = OH_ArkUI_AnimateOption_GetIterations(option); + auto playmode = OH_ArkUI_AnimateOption_GetPlayMode(option); + auto expectedFrameRateRange = OH_ArkUI_AnimateOption_GetExpectedFrameRateRange(option); + auto iCurve = OH_ArkUI_AnimateOption_GetICurve(option); // 获取动画的动画曲线 + g_animateto_text->AnimatetoToString(duration, tempo, curve, delay, iteration, playmode, + *expectedFrameRateRange); + } + }; + button->RegisterNodeEventReceiver(onTouch); + column->AddChild(g_animateto_text); + column->AddChild(textNode); + column->AddChild(button); + return column; +} + +std::shared_ptr CreateAnimator() +{ + auto column = std::make_shared(); + column->SetWidth(NUM_300); + column->SetHeight(NUM_250); + // 创建文本节点,内容区介绍“这是animator动画” + auto textNode = std::make_shared(); + textNode->SetTextContent("这是animator动画"); + textNode->SetWidth(NUM_120); + textNode->SetHeight(NUM_50); + // 创建createButton,用于初始化animator参数 + auto createButton = std::make_shared(); + // 创建button,后续创建的animator动画作用在button组件上 + auto button = std::make_shared(); + // 设置button初始宽高 + button->SetWidth(NUM_100); + button->SetHeight(NUM_100); + // 存储button全局变量,在onTouch注册时需要使用 + g_animator_button = button; + // 注册点击事件到button上 + createButton->RegisterNodeEvent(createButton->GetHandle(), NODE_ON_CLICK, NUM_3, nullptr); + g_animator_text = std::make_shared(); + g_animator_text->AnimatorToString(); + auto onTouch = [](ArkUI_NodeEvent *event) { + // 点击button按钮时触发该逻辑 + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUM_3) { + // 获取context对象 + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_animator_button->GetHandle()); + + // 获取ArkUI_NativeAnimateAPI接口 + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + + // 以下代码为创建Animator动画的关键流程,包括设置Animator动画参数、开启Animator动画 + // 设置ArkUI_AnimatorOption参数,通过提供的C方法设置对应的参数 + static ArkUI_AnimatorOption *option = OH_ArkUI_AnimatorOption_Create(NUM_0); // Animator动画状态数 + OH_ArkUI_AnimatorOption_SetDuration(option, NUM_2000); + OH_ArkUI_AnimatorOption_SetDelay(option, NUM_10); + OH_ArkUI_AnimatorOption_SetIterations(option, NUM_3); + OH_ArkUI_AnimatorOption_SetFill(option, ARKUI_ANIMATION_FILL_MODE_NONE); + OH_ArkUI_AnimatorOption_SetDirection(option, ARKUI_ANIMATION_DIRECTION_NORMAL); + ArkUI_CurveHandle curve = OH_ArkUI_Curve_CreateCubicBezierCurve(0.5f, 4.0f, 1.2f, 0.0f); // 构造三阶贝塞尔曲线对象 + OH_ArkUI_AnimatorOption_SetCurve(option, curve); + OH_ArkUI_AnimatorOption_SetBegin(option, NUM_100); + OH_ArkUI_AnimatorOption_SetEnd(option, NUM_150); + ArkUI_ExpectedFrameRateRange *range = new ArkUI_ExpectedFrameRateRange; + range->max = NUM_120; + range->expected = NUM_60; + range->min = NUM_30; + OH_ArkUI_AnimatorOption_SetExpectedFrameRateRange(option, range); + OH_ArkUI_AnimatorOption_SetKeyframe(option, 0.5, 120.5, NUM_0); // 设置animator动画关键帧参数 + OH_ArkUI_AnimatorOption_SetKeyframeCurve(option, curve, NUM_0); // 设置animator动画关键帧曲线类型 + OH_ArkUI_AnimatorOption_RegisterOnFrameCallback(option, nullptr, [](ArkUI_AnimatorOnFrameEvent *event) + { + OH_ArkUI_AnimatorOnFrameEvent_GetUserData(event); // 获取动画事件对象中的用户自定义对象 + auto value = OH_ArkUI_AnimatorOnFrameEvent_GetValue(event); // 获取动画事件对象中的当前进度 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Init", + "CXX OH_ArkUI_AnimatorOption_RegisterOnFrameCallback %{public}f", value); + g_animator_button->SetWidth(value); + }); + OH_ArkUI_AnimatorOption_RegisterOnFinishCallback(option, nullptr, [](ArkUI_AnimatorEvent* event) + { + OH_ArkUI_AnimatorEvent_GetUserData(event); // 获取动画事件对象中的用户自定义对象 + }); + OH_ArkUI_AnimatorOption_RegisterOnCancelCallback(option, nullptr, [](ArkUI_AnimatorEvent* event) + { + }); + OH_ArkUI_AnimatorOption_RegisterOnRepeatCallback(option, nullptr, [](ArkUI_AnimatorEvent* event) + { + }); + // 执行对应的动画 + animatorHandle = animateApi->createAnimator(context, option); + + auto duration = OH_ArkUI_AnimatorOption_GetDuration(option); + auto delay = OH_ArkUI_AnimatorOption_GetDelay(option); + auto iterations = OH_ArkUI_AnimatorOption_GetIterations(option); + auto fill = OH_ArkUI_AnimatorOption_GetFill(option); + auto direction = OH_ArkUI_AnimatorOption_GetDirection(option); + auto curves = OH_ArkUI_AnimatorOption_GetCurve(option); // 获取animator动画插值曲线 + auto begin = OH_ArkUI_AnimatorOption_GetBegin(option); + auto end = OH_ArkUI_AnimatorOption_GetEnd(option); // 获取animator动画插值终点 + auto expected = OH_ArkUI_AnimatorOption_GetExpectedFrameRateRange(option); // 获取关键帧动画参数的期望帧率 + auto keyframeTime = OH_ArkUI_AnimatorOption_GetKeyframeTime(option, NUM_0); // 获取animator动画关键帧时间 + auto keyframeValue = OH_ArkUI_AnimatorOption_GetKeyframeValue(option, NUM_0); // 获取animator动画关键帧数值 + auto keyframeCurve = OH_ArkUI_AnimatorOption_GetKeyframeCurve(option, NUM_0); // 获取animator动画关键帧动画插值曲线 + g_animator_text->AnimatorToString(duration, delay, iterations, fill, direction, begin, + end, *expected, keyframeTime, keyframeValue); + } + }; + // 注册点击事件的回调函数 + createButton->RegisterNodeEventReceiver(onTouch); + createButton->SetButtonLabel("create"); + // 创建容器,用于存放button按键 + auto buttoColumn = std::make_shared(); + buttoColumn->SetPadding(NUM_30, false); // 设置布局格式,调整组件内间距 + buttoColumn->SetWidth(NUM_300); + // 创建容器,用于存放playButton按键 + auto playButtonColumn = std::make_shared(); + playButtonColumn->SetPadding(NUM_10, false); // 设置布局格式,调整组件内间距 + playButtonColumn->SetWidth(NUM_300); + // 设置animator播放按钮 + auto playButton = std::make_shared(); + playButton->SetButtonLabel("play"); + playButton->RegisterNodeEvent(playButton->GetHandle(), NODE_ON_CLICK, NUM_4, nullptr); + auto onTouchPlay = [](ArkUI_NodeEvent *event) { + // 点击button按钮时触发该逻辑 + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUM_4) { + OH_ArkUI_Animator_Play(animatorHandle); + } + }; + playButton->RegisterNodeEventReceiver(onTouchPlay); + // 设置animator结束按钮 + auto finishButton = std::make_shared(); + finishButton->SetButtonLabel("finish"); + finishButton->RegisterNodeEvent(finishButton->GetHandle(), NODE_ON_CLICK, NUM_5, nullptr); + auto onTouchFinish = [](ArkUI_NodeEvent *event) { + // 点击button按钮时触发该逻辑 + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUM_5) { + OH_ArkUI_Animator_Finish(animatorHandle); + } + }; + finishButton->RegisterNodeEventReceiver(onTouchFinish); + // 将button挂载在column上,返回column节点 + column->AddChild(g_animator_text); + column->AddChild(textNode); + column->AddChild(button); + buttoColumn->AddChild(createButton); + playButtonColumn->AddChild(playButton); + buttoColumn->AddChild(playButtonColumn); + buttoColumn->AddChild(finishButton); + column->AddChild(buttoColumn); + return column; +} + +std::shared_ptr CreateTransitionEffect() +{ + auto column = std::make_shared(); + column->SetWidth(NUM_300); + column->SetHeight(NUM_250); + // 创建文本节点,内容区介绍“这是TransitionEffect” + auto textNode = std::make_shared(); + textNode->SetTextContent("这是TransitionEffect"); + textNode->SetWidth(NUM_150); + textNode->SetHeight(NUM_50); + // 创建transitionButton,后续创建的动画作用在transitionButton组件上 + auto transitionButton = std::make_shared(); + // 设置button初始宽高及颜色 + transitionButton->SetWidth(NUM_100); + transitionButton->SetHeight(NUM_100); + transitionButton->SetBackgroundColor(0xFFA280FF); + // 存储button全局变量 + g_transition_button = transitionButton; + g_transition_button->SetVisibility(ARKUI_VISIBILITY_VISIBLE); + // 创建button,后续动画逻辑在button的点击事件中实现 + auto button = std::make_shared(); + button->SetButtonLabel("transition"); + // 创建buttonColumn容器,用于调整button的布局效果 + auto buttonColumn = std::make_shared(); + buttonColumn->SetWidth(NUM_300); + buttonColumn->SetPadding(NUM_10, false); // 设置布局格式,调整组件内间距 + // 注册点击事件到button上 + button->RegisterNodeEvent(button->GetHandle(), NODE_ON_CLICK, NUM_10, nullptr); + auto onTouch = [](ArkUI_NodeEvent *event) { + // 获取context对象 + static ArkUI_ContextHandle context = nullptr; + context = OH_ArkUI_GetContextByNode(g_transition_button->GetHandle()); + // 点击button按钮时触发该逻辑 + if (OH_ArkUI_NodeEvent_GetTargetId(event) == NUM_10) { + // 获取ArkUI_NativeAnimateAPI接口 + ArkUI_NativeAnimateAPI_1 *animateApi = nullptr; + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi); + + // 设置动画参数 + ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create(); + OH_ArkUI_AnimateOption_SetDuration(option, NUM_2000); + OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE); + // 根据业务所需调整OH_ArkUI_TransitionEffect_SetAnimation的第一个入参 + // 创建组件转场时的透明度效果对象 + auto opacityTransitionEffect = OH_ArkUI_CreateOpacityTransitionEffect(0.7); + // 创建组件转场时的平移效果对象 + ArkUI_TranslationOptions* translate = new ArkUI_TranslationOptions; + translate->x = NUM_10; + translate->y = NUM_0; + translate->z = NUM_0; + auto translationTransitionEffect = OH_ArkUI_CreateTranslationTransitionEffect(translate); + // 创建组件转场时的缩放效果对象 + ArkUI_ScaleOptions* scale = new ArkUI_ScaleOptions; + scale->x = 1.5; + scale->y = 0.0; + scale->z = 0.0; + scale->centerX = 0.0; + scale->centerY = 0.0; + auto scaleTransitionEffect = OH_ArkUI_CreateScaleTransitionEffect(scale); + // 创建组件转场时的旋转效果对象 + ArkUI_RotationOptions* rotate = new ArkUI_RotationOptions; + rotate->x = 10.0; + rotate->y = 0.0; + rotate->z = 0.0; + rotate->centerX = 0.0; + rotate->centerY = 0.1; + rotate->angle = 30.0; + rotate->centerZ = 0.1; + rotate->perspective = NUM_0; + auto rotationTransition = OH_ArkUI_CreateRotationTransitionEffect(rotate); + // 创建组件平移效果对象 + auto movementTransition = OH_ArkUI_CreateMovementTransitionEffect(ARKUI_TRANSITION_EDGE_TOP); + // 创建非对称的转场效果对象 + auto asymmetricTransition = OH_ArkUI_CreateAsymmetricTransitionEffect( + rotationTransition, movementTransition); + // 设置转场效果动画参数,此动画设置的是透明度效果 + OH_ArkUI_TransitionEffect_SetAnimation(opacityTransitionEffect, option); + // 设置转场效果链式组合,以形成包含多种转场效果的TransitionEffect + OH_ArkUI_TransitionEffect_Combine(translationTransitionEffect, scaleTransitionEffect); + + // 设置完成的回调 + ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback; + completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED; + TransitionData* data = new TransitionData(); + data->option = option; + data->effect = opacityTransitionEffect; + completeCallback->userData = reinterpret_cast(data); + completeCallback->callback = [](void *userData) { + TransitionData* data = reinterpret_cast(userData); + if (data) { + ArkUI_AnimateOption* option = data->option; + ArkUI_TransitionEffect* effect = data->effect; + if (option) { + OH_ArkUI_AnimateOption_Dispose(option); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "Init", "CXX OH_ArkUI_AnimateOption_Dispose success!"); + } + if (effect) { + OH_ArkUI_TransitionEffect_Dispose(effect); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "Init", "CXX OH_ArkUI_TransitionEffect_Dispose success!"); + } + delete data; // 释放结构体 + } + }; + + // 设置闭包函数 + static bool transitionIsBack = false; + ArkUI_ContextCallback *update = new ArkUI_ContextCallback; + update->callback = [](void *user) { + // 通过transitionIsBack变量使组件做显隐变化 + if (transitionIsBack) { + g_transition_button->SetVisibility(ARKUI_VISIBILITY_VISIBLE); + } else { + g_transition_button->SetVisibility(ARKUI_VISIBILITY_HIDDEN); + } + transitionIsBack = !transitionIsBack; + }; + // 执行对应的动画 + animateApi->animateTo(context, option, update, completeCallback); + } + }; + button->RegisterNodeEventReceiver(onTouch); + column->AddChild(textNode); + column->AddChild(transitionButton); + buttonColumn->AddChild(button); + column->AddChild(buttonColumn); + return column; +} +} // namespace NativeModule +#endif // MYAPPLICATION_ARKUIDOBASENODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIBaseNode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIBaseNode.h new file mode 100644 index 000000000..9931c7d72 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIBaseNode.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIBASENODE_H +#define MYAPPLICATION_ARKUIBASENODE_H + +#include +#include +#include + +#include "manager.h" +#include "NativeModule.h" + +namespace NativeModule { + +class ArkUIBaseNode { +public: + explicit ArkUIBaseNode(ArkUI_NodeHandle handle) + : handle_(handle), nativeModule_(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()) {} + + virtual ~ArkUIBaseNode() + { + if (!children_.empty()) { + for (const auto& child : children_) { + nativeModule_->removeChild(handle_, child->GetHandle()); + } + children_.clear(); + } + nativeModule_->disposeNode(handle_); + } + void AddChild(const std::shared_ptr &child) + { + children_.emplace_back(child); + OnAddChild(child); + } + void RemoveChild(const std::shared_ptr &child) + { + children_.remove(child); + OnRemoveChild(child); + } + void InsertChild(const std::shared_ptr &child, int32_t index) + { + if (index >= children_.size()) { + AddChild(child); + } else { + auto iter = children_.begin(); + std::advance(iter, index); + children_.insert(iter, child); + OnInsertChild(child, index); + } + } + ArkUI_NodeHandle GetHandle() const { return handle_; } + ArkUI_NativeNodeAPI_1* GetNativeModule() const + { + return nativeModule_; + } + +protected: + virtual void OnAddChild(const std::shared_ptr &child) {} + virtual void OnRemoveChild(const std::shared_ptr &child) {} + virtual void OnInsertChild(const std::shared_ptr &child, int32_t index) {} + + ArkUI_NodeHandle handle_; + ArkUI_NativeNodeAPI_1 *nativeModule_ = nullptr; + +private: + std::list> children_; +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUIBASENODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIButtonNode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIButtonNode.h new file mode 100644 index 000000000..69514851b --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIButtonNode.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIBUTTONNODE_H +#define MYAPPLICATION_ARKUIBUTTONNODE_H + +#include "ArkUINode.h" + +#include + +namespace NativeModule { +class ArkUIButtonNode : public ArkUINode { +public: + // 创建ArkUI的button组件。 + ArkUIButtonNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_BUTTON)) {} + + ~ArkUIButtonNode() override {} + void SetContentWithAnimete() + {} + + void SetButtonLabel(const std::string &content) + { + ArkUI_AttributeItem item = {nullptr, 0, content.c_str()}; + nativeModule_->setAttribute(handle_, NODE_BUTTON_LABEL, &item); + } +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUIBUTTONNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIColumnNode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIColumnNode.h new file mode 100644 index 000000000..b51935def --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIColumnNode.h @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUICOLUMNNODE_H +#define MYAPPLICATION_ARKUICOLUMNNODE_H + +#include "ArkUINode.h" +#include + +namespace NativeModule { +class ArkUIColumnNode : public ArkUINode { +public: + ArkUIColumnNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_COLUMN)) {} + + void SetTranslate(float x, float y, float z) + { + ArkUI_NumberValue nums[NUMBER_3] = {x, y, z}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + nativeModule_->setAttribute(handle_, NODE_TRANSLATE, &item); + } + void SetScale(float x, float y) + { + ArkUI_NumberValue nums[NUMBER_2] = {x, y}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_2}; + nativeModule_->setAttribute(handle_, NODE_SCALE, &item); + } + void SetRotate(float x, float y, float z, float angle, float center) + { + ArkUI_NumberValue nums[NUMBER_5] = {x, y, z, angle, center}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_5}; + nativeModule_->setAttribute(handle_, NODE_ROTATE, &item); + } + void SetBrightness(float light) + { + ArkUI_NumberValue nums[NUMBER_1] = {light}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BRIGHTNESS, &item); + } + void SetSaturate(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_SATURATION, &item); + } + int32_t SetLinearGradient(float angle, int32_t direction, int32_t repeat) + { + ArkUI_NumberValue nums[NUMBER_3]; + nums[NUMBER_0].f32 = angle; + nums[NUMBER_1].i32 = direction; + nums[NUMBER_2].i32 = repeat; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3, .object = &colorStop}; + auto err = nativeModule_->setAttribute(handle_, NODE_LINEAR_GRADIENT, &item); + return err; + } + void SetOpacity(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_OPACITY, &item); + } + void SetBorderRadius(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BORDER_RADIUS, &item); + } + int32_t SetClip(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].i32 = number; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_CLIP, &item); + return err; + } + int32_t SetCircleShape(int32_t number, float width, float height) + { + ArkUI_NumberValue nums[NUMBER_3]; + nums[NUMBER_0].i32 = number; + nums[NUMBER_1].f32 = width; + nums[NUMBER_2].f32 = height; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_CLIP_SHAPE, &item); + return err; + } + int32_t SetTransform() + { + ArkUI_NumberValue value2[NUMBER_16]; + for (int i = NUMBER_0; i < NUMBER_16; i++) { + value2[i].f32 = NUMBER_0; + } + value2[NUMBER_0].f32 = NUMBER_1; + value2[NUMBER_1].f32 = NUMBER_1; + ArkUI_AttributeItem item = { .value = value2, .size = NUMBER_3 }; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSFORM, &item); + return err; + } + int32_t SetShadow(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_0]; + nums[NUMBER_0].i32 = number; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_SHADOW, &item); + return err; + } + int32_t SetBackgroundBlurStyle(int32_t number) + { + ArkUI_NumberValue blurStyle[NUMBER_6]; + blurStyle[NUMBER_0].i32 = number; + blurStyle[NUMBER_2].i32 = ARKUI_ADAPTIVE_COLOR_AVERAGE; + ArkUI_AttributeItem item = { .value = blurStyle, .size = NUMBER_2}; + auto err = nativeModule_->setAttribute(handle_, NODE_BACKGROUND_BLUR_STYLE, &item); + return err; + } + int32_t SetTransformCenter(float number) + { + ArkUI_NumberValue centerPointArray[] = {number}; + ArkUI_AttributeItem item = { .value = centerPointArray, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSFORM_CENTER, &item); + return err; + } + int32_t SetSweepGradient() + { + ArkUI_NumberValue nums[NUMBER_6]; + nums[NUMBER_0].f32 = SMALL_LENGTH; + nums[NUMBER_1].f32 = SMALL_LENGTH; + nums[NUMBER_2].f32 = NUMBER_0; + nums[NUMBER_3].f32 = NUMBER_359; + nums[NUMBER_4].f32 = NUMBER_45; + nums[NUMBER_5].f32 = NUMBER_1; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_6, .object = &colorStop }; + auto err = nativeModule_->setAttribute(handle_, NODE_SWEEP_GRADIENT, &item); + return err; + } + int32_t SetRadialGradient() + { + ArkUI_NumberValue nums[NUMBER_4]; + nums[NUMBER_0].f32 = SMALL_LENGTH; + nums[NUMBER_1].f32 = SMALL_LENGTH; + nums[NUMBER_2].f32 = NUMBER_60; + nums[NUMBER_3].f32 = NUMBER_1; + ArkUI_ColorStop colorStop; + const uint32_t colors[] = {COLOR_1, COLOR_2, COLOR_3}; + float stops[] = {NUMBER_00, NUMBER_05, NUMBER_1F}; + int size = NUMBER_3; + colorStop.colors = colors; + colorStop.stops = stops; + colorStop.size = size; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_4, .object = &colorStop }; + auto err = nativeModule_->setAttribute(handle_, NODE_RADIAL_GRADIENT, &item); + return err; + } + int32_t SetMask() + { + ArkUI_NumberValue nums[NUMBER_4]; + nums[NUMBER_0].i32 = ARKUI_MASK_TYPE_PROGRESS; + nums[NUMBER_1].f32 = NUMBER_10; + nums[NUMBER_2].f32 = NUMBER_100; + nums[NUMBER_3].u32 = COLOR_WHITE; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_4 }; + auto err = nativeModule_->setAttribute(handle_, NODE_MASK, &item); + return err; + } + int32_t SetGrayScale(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_GRAY_SCALE, &item); + return err; + } + int32_t SetInvert(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_INVERT, &item); + return err; + } + int32_t SetSepia(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_SEPIA, &item); + return err; + } + int32_t SetContrast(float number) + { + ArkUI_NumberValue nums[] = { number }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_CONTRAST, &item); + return err; + } + int32_t SetColumnJustifyContent(int32_t number) + { + ArkUI_NumberValue nums[] = { { .i32 = number } }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_COLUMN_JUSTIFY_CONTENT, &item); + return err; + } + ~ArkUIColumnNode() override {} +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUILISTNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINode.h new file mode 100644 index 000000000..2da51a5a1 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINode.h @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUINODE_H +#define MYAPPLICATION_ARKUINODE_H + +#include "ArkUIBaseNode.h" +#include "NativeModule.h" +#include +#include +#include +#include +#include "ArkUINumber.h" + +namespace NativeModule { +class ArkUINode : public ArkUIBaseNode { +public: + explicit ArkUINode(ArkUI_NodeHandle handle) : ArkUIBaseNode(handle) {} + + ~ArkUINode() override {} + + void SetWidth(float width) + { + ArkUI_NumberValue value[] = {{.f32 = width}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_WIDTH, &item); + } + void SetPercentWidth(float percent) + { + ArkUI_NumberValue value[] = {{.f32 = percent}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_WIDTH_PERCENT, &item); + } + void SetHeight(float height) + { + ArkUI_NumberValue value[] = {{.f32 = height}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_HEIGHT, &item); + } + void SetPercentHeight(float percent) + { + ArkUI_NumberValue value[] = {{.f32 = percent}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_HEIGHT_PERCENT, &item); + } + void SetBackgroundColor(uint32_t color) + { + ArkUI_NumberValue value[] = {{.u32 = color}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + nativeModule_->setAttribute(handle_, NODE_BACKGROUND_COLOR, &item); + } + int32_t SetZIndex(int32_t number) + { + ArkUI_NumberValue value[] = {{.i32 = number}}; + ArkUI_AttributeItem item = {value, NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_Z_INDEX, &item); + return err; + } + int32_t SetForegroundColor(uint32_t color) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].u32 = color; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_FOREGROUND_COLOR, &item); + return err; + } + int32_t SetMarkAnchor(float x, float y) + { + ArkUI_NumberValue nums[NUMBER_2] = {x, y}; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_2}; + auto err = nativeModule_->setAttribute(handle_, NODE_MARK_ANCHOR, &item); + return err; + } + int32_t SetVisibility(int32_t visibility) + { + ArkUI_NumberValue nums[NUMBER_1]; + nums[NUMBER_0].i32 = visibility; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_VISIBILITY, &item); + return err; + } + void RegisterNodeEvent(ArkUI_NodeHandle node, + ArkUI_NodeEventType eventType, int32_t targetId, void* userData) + { + nativeModule_->registerNodeEvent(node, eventType, targetId, userData); + } + void RegisterNodeEventReceiver(void (*eventReceiver)(ArkUI_NodeEvent* event)) + { + nativeModule_->registerNodeEventReceiver(eventReceiver); + } + int32_t SetOpacityTransition() + { + ArkUI_NumberValue opacityTransition[] = { + NUMBER_02, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_EASE_IN_OUT) } + }; + ArkUI_AttributeItem item = { .value = opacityTransition, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_OPACITY_TRANSITION, &item); + return err; + } + int32_t SetRotateTransition() + { + ArkUI_NumberValue rotateTransition[] = { + NUMBER_00, + NUMBER_00, + NUMBER_1F, + NUMBER_180, + NUMBER_0, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = rotateTransition, .size = NUMBER_7}; + auto err = nativeModule_->setAttribute(handle_, NODE_ROTATE_TRANSITION, &item); + return err; + } + int32_t SetScaleTransition() + { + ArkUI_NumberValue scaleTransition[] = { + NUMBER_00, + NUMBER_00, + NUMBER_00, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = scaleTransition, .size = NUMBER_5}; + auto err = nativeModule_->setAttribute(handle_, NODE_SCALE_TRANSITION, &item); + return err; + } + int32_t SetTranslateTransition() + { + ArkUI_NumberValue translateTransition[] = { + NUMBER_100F, + NUMBER_100F, + NUMBER_00, + { .i32 = NUMBER_3000 }, + { .i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = translateTransition, .size = NUMBER_5}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSLATE_TRANSITION, &item); + return err; + } + int32_t SetMoveTransition() + { + ArkUI_NumberValue translateTransition[] = { + {.i32 = ARKUI_TRANSITION_EDGE_START }, + {.i32 = NUMBER_3000 }, + {.i32 = static_cast(ARKUI_CURVE_SHARP) } + }; + ArkUI_AttributeItem item = { .value = translateTransition, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_MOVE_TRANSITION, &item); + return err; + } + int32_t SetForegroundBlurStyle(int32_t number) + { + ArkUI_NumberValue nums[] = { { .i32 = number} }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_FOREGROUND_BLUR_STYLE, &item); + return err; + } + int32_t SetColorBlend(uint32_t color) + { + ArkUI_NumberValue nums[] = { { .u32 = color} }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_COLOR_BLEND, &item); + return err; + } + int32_t SetTransition(ArkUI_TransitionEffect* effect) + { + ArkUI_AttributeItem item = { .object = effect}; + auto err = nativeModule_->setAttribute(handle_, NODE_TRANSITION, &item); + return err; + } + int32_t SetBackdropBlur(float round) + { + ArkUI_NumberValue nums[] = { round, NUMBER_100, NUMBER_100 }; + ArkUI_AttributeItem item = { .value = nums, .size = NUMBER_3}; + auto err = nativeModule_->setAttribute(handle_, NODE_BACKDROP_BLUR, &item); + return err; + } + void SetTranslateWithPercent(float x, float y, float z) + { + ArkUI_NumberValue nums[NUMBER_3] = {x, y, z}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_3}; + nativeModule_->setAttribute(handle_, NODE_TRANSLATE_WITH_PERCENT, &item); + } + void SetRotateAngle(float x, float y, float z, float see) + { + ArkUI_NumberValue nums[NUMBER_4] = {x, y, z, see}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_4}; + nativeModule_->setAttribute(handle_, NODE_ROTATE_ANGLE, &item); + } + int32_t SetGeometryTransition(int32_t share, const char* str) + { + ArkUI_NumberValue nums[NUMBER_1] = { {.i32 = share} }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1, .string = str}; + auto err = nativeModule_->setAttribute(handle_, NODE_GEOMETRY_TRANSITION, &item); + return err; + } + int32_t SetCustomShadow() + { + ArkUI_NumberValue nums[NUMBER_7] = { + NUMBER_20, + {.i32 = NUMBER_0 }, + SMALL_LENGTH, + SMALL_LENGTH, + { .i32 = ARKUI_SHADOW_TYPE_COLOR }, + { .u32 = COLOR_RED }, + { .u32 = NUMBER_0 } + }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_7}; + auto err = nativeModule_->setAttribute(handle_, NODE_CUSTOM_SHADOW, &item); + return err; + } + int32_t SetBlur(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_BLUR, &item); + return err; + } + int32_t SetBackGroundImage(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_BLUR, &item); + return err; + } + int32_t SetRenderFit(float number) + { + ArkUI_NumberValue nums[NUMBER_1] = {number}; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_RENDER_FIT, &item); + return err; + } + int32_t SetRenderGroup(int32_t number) + { + ArkUI_NumberValue nums[NUMBER_1] = { { .i32 = number } }; + ArkUI_AttributeItem item = {.value = nums, .size = NUMBER_1}; + auto err = nativeModule_->setAttribute(handle_, NODE_RENDER_GROUP, &item); + return err; + } + void SetPadding(float padding, bool isPercent = false) + { + ArkUI_NumberValue value[] = {{.f32 = padding}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, isPercent ? NODE_PADDING_PERCENT : NODE_PADDING, &item); + } +protected: + void OnAddChild(const std::shared_ptr &child) override + { + nativeModule_->addChild(handle_, child->GetHandle()); + } + void OnRemoveChild(const std::shared_ptr &child) override + { + nativeModule_->removeChild(handle_, child->GetHandle()); + } + void OnInsertChild(const std::shared_ptr &child, int32_t index) override + { + nativeModule_->insertChildAt(handle_, child->GetHandle(), index); + } +}; +} // namespace NativeModule +#endif // MYAPPLICATION_ARKUINODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINumber.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINumber.h new file mode 100644 index 000000000..9c0c30fe9 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUINumber.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARKUINUMBER_H +#define ARKUINUMBER_H +namespace NativeModule { +constexpr uint32_t COLOR_1 = 0x33FF0000; +constexpr uint32_t COLOR_2 = 0x3300FF00; +constexpr uint32_t COLOR_3 = 0x330000FF; +constexpr uint32_t COLOR_BLACK = 0xFF000000; +constexpr uint32_t COLOR_PINK = 0x33FF0000; +constexpr uint32_t COLOR_RED = 0xFFFF0000; +constexpr uint32_t COLOR_WHITE = 0xFFFFFFFF; +constexpr int32_t DURATION_TIME = 2000; +constexpr int32_t LARGE_LENGTH = 300; +constexpr int32_t MIDDLE_LENGTH = 200; +constexpr int32_t NUMBER_0 = 0; +constexpr float NUMBER_00 = 0.0; +constexpr float NUMBER_01 = 0.1; +constexpr float NUMBER_02 = 0.2; +constexpr float NUMBER_03 = 0.3; +constexpr float NUMBER_04 = 0.4; +constexpr float NUMBER_05 = 0.5; +constexpr float NUMBER_06 = 0.6; +constexpr int32_t NUMBER_1 = 1; +constexpr float NUMBER_1F = 1.0; +constexpr int32_t NUMBER_2 = 2; +constexpr int32_t NUMBER_3 = 3; +constexpr int32_t NUMBER_4 = 4; +constexpr int32_t NUMBER_5 = 5; +constexpr int32_t NUMBER_6 = 6; +constexpr int32_t NUMBER_7 = 7; +constexpr int32_t NUMBER_10 = 10; +constexpr int32_t NUMBER_16 = 16; +constexpr int32_t NUMBER_20 = 20; +constexpr int32_t NUMBER_25 = 25; +constexpr int32_t NUMBER_30 = 30; +constexpr int32_t NUMBER_45 = 45; +constexpr int32_t NUMBER_60 = 60; +constexpr int32_t NUMBER_90 = 90; +constexpr int32_t NUMBER_100 = 100; +constexpr float NUMBER_100F = 100.0; +constexpr int32_t NUMBER_150 = 150; +constexpr int32_t NUMBER_180 = 180; +constexpr int32_t NUMBER_3000 = 3000; +constexpr int32_t NUMBER_359 = 359; +constexpr int32_t SMALL_LENGTH = 50; +} +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUITextNode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUITextNode.h new file mode 100644 index 000000000..852bda881 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUITextNode.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// ArkUITextNode.h +#ifndef MYAPPLICATION_ARKUITEXTNODE_H +#define MYAPPLICATION_ARKUITEXTNODE_H + +#include "ArkUINode.h" + +#include + +namespace NativeModule { +class ArkUITextNode : public ArkUINode { +public: + ArkUITextNode() + : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_TEXT)) {} + void SetFontSize(float fontSize) + { + ArkUI_NumberValue value[] = {{.f32 = fontSize}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_FONT_SIZE, &item); + } + void SetFontColor(uint32_t color) + { + ArkUI_NumberValue value[] = {{.u32 = color}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_FONT_COLOR, &item); + } + void SetTextContent(const std::string &content) + { + ArkUI_AttributeItem item = {nullptr, 0, content.c_str()}; + nativeModule_->setAttribute(handle_, NODE_TEXT_CONTENT, &item); + } + void SetTextAlign(ArkUI_TextAlignment align) + { + ArkUI_NumberValue value[] = {{.i32 = align}}; + ArkUI_AttributeItem item = {value, 1}; + nativeModule_->setAttribute(handle_, NODE_TEXT_ALIGN, &item); + } + void AnimatetoToString( + int duration = 0, float tempo = 0, int curve = 0, int delay = 0, + int iteration = 0, ArkUI_AnimationPlayMode playmode = ARKUI_ANIMATION_PLAY_MODE_REVERSE, + const ArkUI_ExpectedFrameRateRange& expectedFrameRateRange = { 0, 0, 0 }) + { + SetTextContent("animateto{ dur:" + std::to_string(duration) + + "; tempo:" + std::to_string(tempo) + + "; curve:" + std::to_string(static_cast(curve)) + + "; delay:" + std::to_string(delay) + + "; iteration:" + std::to_string(iteration) + + "; playmode:" + std::to_string(static_cast(playmode)) + + "; expectedFrameRateRange:[ max:" + + std::to_string(expectedFrameRateRange.max) + ", min:" + + std::to_string(expectedFrameRateRange.min) + ", expected:" + + std::to_string(expectedFrameRateRange.expected) + "]}"); + } + void AnimatorToString( + int duration = 0, int delay = 0, int iterations = 0, + ArkUI_AnimationFillMode fill = ARKUI_ANIMATION_FILL_MODE_FORWARDS, + ArkUI_AnimationDirection direction = ARKUI_ANIMATION_DIRECTION_REVERSE, float begin = 0.0, float end = 0.0, + const ArkUI_ExpectedFrameRateRange& expectedFrameRateRange = { 0, 0, 0 }, + float keyframeTime = 0.0, float keyframeValue = 0.0) + { + SetTextContent("Animator{ dur:" + std::to_string(duration) + + "; delay:" + std::to_string(delay) + + "; iterations:" + std::to_string(iterations) + + "; fill:" + std::to_string(fill) + + "; direction:" + std::to_string(direction) + + "; begin:" + std::to_string(begin) + + "; end:" + std::to_string(end) + + "; expectedFrameRateRange:[ max:" + + std::to_string(expectedFrameRateRange.max) + ", min:" + + std::to_string(expectedFrameRateRange.min) + ", expected:" + + std::to_string(expectedFrameRateRange.expected) + "]" + + "; keyframeTime:" + std::to_string(keyframeTime) + + "; keyframeValue:" + std::to_string(keyframeValue) + + "}"); + } +}; +} // namespace NativeModule + +#endif // MYAPPLICATION_ARKUITEXTNODE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h new file mode 100644 index 000000000..1c8f268ef --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/ArkUIVisualEffectsNode.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_ARKUIVISUALEFFECTSNODE_H +#define MYAPPLICATION_ARKUIVISUALEFFECTSNODE_H +#include "ArkUIColumnNode.h" +#include "ArkUITextNode.h" +#include + +namespace NativeModule { +std::shared_ptr CreateVisualEffectsFrameNode1() +{ + auto column = std::make_shared(); + auto textNodeCustomShadow = std::make_shared(); + textNodeCustomShadow->SetTextContent("ArkUI_ShadowType"); + textNodeCustomShadow->SetWidth(MIDDLE_LENGTH); + textNodeCustomShadow->SetHeight(SMALL_LENGTH); + auto columnCustomShadow = std::make_shared(); + columnCustomShadow->SetWidth(MIDDLE_LENGTH); + columnCustomShadow->SetHeight(MIDDLE_LENGTH); + columnCustomShadow->SetBackgroundColor(COLOR_PINK); + columnCustomShadow->SetCustomShadow(); + column->AddChild(textNodeCustomShadow); + column->AddChild(columnCustomShadow); + + auto textNodeShadow = std::make_shared(); + textNodeShadow->SetTextContent("ArkUI_ShadowStyle"); + textNodeShadow->SetWidth(MIDDLE_LENGTH); + textNodeShadow->SetHeight(SMALL_LENGTH); + auto columnShadow = std::make_shared(); + columnShadow->SetWidth(MIDDLE_LENGTH); + columnShadow->SetHeight(MIDDLE_LENGTH); + columnShadow->SetBackgroundColor(COLOR_PINK); + columnShadow->SetShadow(ARKUI_SHADOW_STYLE_OUTER_DEFAULT_LG); + column->AddChild(textNodeShadow); + column->AddChild(columnShadow); + + auto textNodeMask = std::make_shared(); + textNodeMask->SetTextContent("ArkUI_MaskType"); + textNodeMask->SetWidth(MIDDLE_LENGTH); + textNodeMask->SetHeight(SMALL_LENGTH); + auto columnMask = std::make_shared(); + columnMask->SetWidth(MIDDLE_LENGTH); + columnMask->SetHeight(MIDDLE_LENGTH); + columnMask->SetBackgroundColor(COLOR_PINK); + columnMask->SetMask(); + column->AddChild(textNodeMask); + column->AddChild(columnMask); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode2() +{ + auto column = std::make_shared(); + auto textNodeBlurStyle = std::make_shared(); + textNodeBlurStyle->SetTextContent("ArkUI_AdaptiveColor ArkUI_BlurStyle"); + textNodeBlurStyle->SetWidth(MIDDLE_LENGTH); + textNodeBlurStyle->SetHeight(SMALL_LENGTH); + auto columnBlurStyle = std::make_shared(); + columnBlurStyle->SetWidth(MIDDLE_LENGTH); + columnBlurStyle->SetHeight(MIDDLE_LENGTH); + columnBlurStyle->SetBackgroundColor(COLOR_PINK); + columnBlurStyle->SetBackgroundBlurStyle(ARKUI_BLUR_STYLE_THICK); + column->AddChild(textNodeBlurStyle); + column->AddChild(columnBlurStyle); + + auto textNodeCircleShape = std::make_shared(); + textNodeCircleShape->SetTextContent("ArkUI_ClipType"); + textNodeCircleShape->SetWidth(MIDDLE_LENGTH); + textNodeCircleShape->SetHeight(SMALL_LENGTH); + auto columnCircleShape = std::make_shared(); + columnCircleShape->SetWidth(MIDDLE_LENGTH); + columnCircleShape->SetHeight(MIDDLE_LENGTH); + columnCircleShape->SetBackgroundColor(COLOR_PINK); + columnCircleShape->SetCircleShape(ARKUI_CLIP_TYPE_CIRCLE, MIDDLE_LENGTH, MIDDLE_LENGTH); + column->AddChild(textNodeCircleShape); + column->AddChild(columnCircleShape); + + return column; +} + +std::shared_ptr CreateVisualEffectsFrameNode3() +{ + auto column = std::make_shared(); + auto textNodeLinearGradient = std::make_shared(); + textNodeLinearGradient->SetTextContent("ArkUI_ColorStop ArkUI_LinearGradientDirection"); + textNodeLinearGradient->SetWidth(MIDDLE_LENGTH); + textNodeLinearGradient->SetHeight(SMALL_LENGTH); + auto columnLinearGradient = std::make_shared(); + columnLinearGradient->SetWidth(NUMBER_100); + columnLinearGradient->SetHeight(NUMBER_100); + columnLinearGradient->SetLinearGradient(NUMBER_90, ARKUI_LINEAR_GRADIENT_DIRECTION_CUSTOM, NUMBER_0); + column->AddChild(textNodeLinearGradient); + column->AddChild(columnLinearGradient); + + return column; +} +} // namespace NativeModule + +#endif \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/NativeModule.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/NativeModule.h new file mode 100644 index 000000000..a46cd0b11 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/NativeModule.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MYAPPLICATION_NATIVEMODULE_H +#define MYAPPLICATION_NATIVEMODULE_H + +#include +#include +#include +#include + +namespace NativeModule { + +class NativeModuleInstance { +public: + static NativeModuleInstance *GetInstance() + { + static NativeModuleInstance instance; + return &instance; + } + + NativeModuleInstance() + { + OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, arkUINativeNodeApi_); + } + ArkUI_NativeNodeAPI_1 *GetNativeNodeAPI() { return arkUINativeNodeApi_; } + +private: + ArkUI_NativeNodeAPI_1 *arkUINativeNodeApi_ = nullptr; +}; +} // namespace NativeModule +#endif // MYAPPLICATION_NATIVEMODULE_H \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/SwiperMaker.cpp b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/SwiperMaker.cpp index cc265537f..e1f1a9a9b 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/SwiperMaker.cpp +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/SwiperMaker.cpp @@ -17,7 +17,7 @@ #include "baseUtils.h" namespace ConstIde { - const float TEXT_WIDTH_VP = 400.0f; // 宽度 + const float TEXT_WIDTH_VP = 500.0f; // 宽度 const float TEXT_HEIGHT_VP = 200.0f; // 高度 const uint32_t TEXT_BG_COLOR = 0xFFAFEEEE; // 淡蓝色 const int32_t TEXT_ALIGN_CENTER = 1; // 居中 diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/TextMaker.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/TextMaker.h index bbd3557af..bea13eb36 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/TextMaker.h +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/TextMaker.h @@ -26,4 +26,4 @@ public: static ArkUI_NodeHandle createTextPage(); }; -#endif // NATIVE_TYPE_SAMPLE_SWIPERMAKER_H \ No newline at end of file +#endif // NATIVE_TYPE_SAMPLE_SWIPERMAKER_H diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.cpp b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.cpp index df022f8cd..1f826dd7d 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.cpp +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.cpp @@ -14,6 +14,8 @@ */ #include "manager.h" +#include "ArkUIAnimationNode.h" +#include "ArkUIVisualEffectsNode.h" #include "SwiperMaker.h" #include "TextMaker.h" #include "baseUtils.h" @@ -87,4 +89,138 @@ napi_value Manager::CreateNativeTextNode(napi_env env, napi_callback_info info) } } return nullptr; +} + +napi_value createNativeRootAnimation1(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode1(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation2(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimationFrameNode2(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation3(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimeteto(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation4(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateAnimator(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootAnimation5(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateTransitionEffect(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects1(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode1(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects2(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode2(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value createNativeRootVisualEffects3(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + Manager::GetInstance()->SetContentHandle(contentHandle); + + auto column = NativeModule::CreateVisualEffectsFrameNode3(); + Manager::GetInstance()->SetRootNode(column); + return nullptr; +} + +napi_value DestroyNativeRoot(napi_env env, napi_callback_info info) +{ + Manager::GetInstance()->DisposeRootNode(); + return nullptr; } \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.h b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.h index 6f9fc2489..c3102c226 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.h +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/manager.h @@ -15,7 +15,7 @@ #ifndef NATIVE_NODE_NAPI_SAMPLE_MANAGER_H #define NATIVE_NODE_NAPI_SAMPLE_MANAGER_H - +#include "ArkUIBaseNode.h" #include #include #include @@ -26,16 +26,49 @@ #include const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +napi_value createNativeRootAnimation1(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation2(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation3(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation4(napi_env env, napi_callback_info info); +napi_value createNativeRootAnimation5(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects1(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects2(napi_env env, napi_callback_info info); +napi_value createNativeRootVisualEffects3(napi_env env, napi_callback_info info); +napi_value DestroyNativeRoot(napi_env env, napi_callback_info info); + class Manager { public: static ArkUI_NativeNodeAPI_1 *nodeAPI_; ~Manager(){}; + static Manager *GetInstance() + { + static Manager nativeEntry; + return &nativeEntry; + } + + void SetContentHandle(ArkUI_NodeContentHandle handle) + { + handle_ = handle; + } + + void SetRootNode(const std::shared_ptr &baseNode) + { + root_ = baseNode; + OH_ArkUI_NodeContent_AddNode(handle_, root_->GetHandle()); + } + void DisposeRootNode() + { + OH_ArkUI_NodeContent_RemoveNode(handle_, root_->GetHandle()); + root_.reset(); + } static napi_value CreateNativeSwiperNode(napi_env env, napi_callback_info info); static napi_value CreateNativeTextNode(napi_env env, napi_callback_info info); - + private: static Manager manager_; + std::shared_ptr root_; + ArkUI_NodeContentHandle handle_; }; #endif // NATIVE_NODE_NAPI_SAMPLE_MANAGER_H diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/napi_init.cpp index 60f2a287e..11726f043 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/napi_init.cpp +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/napi_init.cpp @@ -16,9 +16,9 @@ #include "manager.h" #include + EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ +static napi_value Init(napi_env env, napi_value exports) { OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "Init begins"); if ((env == nullptr) || (exports == nullptr)) { OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Init", "env or exports is null"); @@ -26,10 +26,23 @@ static napi_value Init(napi_env env, napi_value exports) } napi_property_descriptor desc[] = { - {"createNativeSwiperNode", nullptr, Manager::CreateNativeSwiperNode, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"createNativeTextNode", nullptr, Manager::CreateNativeTextNode, nullptr, nullptr, nullptr, napi_default, - nullptr} + {"createNativeRootAnimation1", nullptr, createNativeRootAnimation1, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation2", nullptr, createNativeRootAnimation2, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation3", nullptr, createNativeRootAnimation3, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation4", nullptr, createNativeRootAnimation4, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootAnimation5", nullptr, createNativeRootAnimation5, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects1", nullptr, createNativeRootVisualEffects1, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects2", nullptr, createNativeRootVisualEffects2, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createNativeRootVisualEffects3", nullptr, createNativeRootVisualEffects3, + nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyNativeRoot", nullptr, DestroyNativeRoot, nullptr, nullptr, nullptr, napi_default, nullptr}, // 参考Swiper新增其他createNative方法和Maker类 }; @@ -40,7 +53,6 @@ static napi_value Init(napi_env env, napi_value exports) return exports; } EXTERN_C_END - static napi_module demoModule = { .nm_version = 1, .nm_flags = 0, diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/types/libentry/Index.d.ts index e9279a70f..1674b6242 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/ArkUIKit/NativeTypeSample/entry/src/main/cpp/types/libentry/Index.d.ts @@ -14,4 +14,13 @@ */ export const createNativeSwiperNode: (content: Object) =>void; -export const createNativeTextNode: (content: Object) =>void; \ No newline at end of file +export const createNativeTextNode: (content: Object) =>void; +export const createNativeRootAnimation1: (content: Object) => void; +export const createNativeRootAnimation2: (content: Object) => void; +export const createNativeRootAnimation3: (content: Object) => void; +export const createNativeRootAnimation4: (content: Object) => void; +export const createNativeRootAnimation5: (content: Object) => void; +export const createNativeRootVisualEffects1: (content: Object) => void; +export const createNativeRootVisualEffects2: (content: Object) => void; +export const createNativeRootVisualEffects3: (content: Object) => void; +export const destroyNativeRoot: () => void; \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/Index.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/Index.ets index 0c09df3da..933af8631 100644 --- a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/Index.ets +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/Index.ets @@ -27,6 +27,8 @@ struct MenuIndex { [ { title: 'Swiper', url: 'pages/page_swiper' }, { title: 'text', url: 'pages/page_text' }, + { title: 'Animation', url: 'pages/page_animation' }, + { title: 'Visual Effects', url: 'pages/page_visual_effects' }, ]; build() { diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex1.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex1.ets new file mode 100644 index 000000000..718551ca4 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex1.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation1(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex2.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex2.ets new file mode 100644 index 000000000..e0da3b358 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex2.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation2(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex3.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex3.ets new file mode 100644 index 000000000..4acc67fe2 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex3.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation3(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex4.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex4.ets new file mode 100644 index 000000000..c73973af7 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex4.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation4(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex5.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex5.ets new file mode 100644 index 000000000..767658ca2 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/animation/animationIndex5.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootAnimation5(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_animation.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_animation.ets new file mode 100644 index 000000000..503c7af84 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_animation.ets @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +interface ListCategories { + title:string, + url:string +} + +@Entry +@Component +struct AnimationIndex { + @State message: string = 'CApi'; + @State isShow: boolean = false; + private items : ListCategories[] = [ + {title:'ArkUI_TransitionEdge',url:'pages/animation/animationIndex1'}, + {title:'ArkUI_RenderFit',url:'pages/animation/animationIndex2'}, + {title:'ArkUI_AnimationCurve, ArkUI_AnimationPlayMode, ArkUI_FinishCallbackType', + url:'pages/animation/animationIndex3'}, + {title:'ArkUI_AnimationFillMode, ArkUI_AnimationDirection',url:'pages/animation/animationIndex4'}, + {title:'ArkUI_TranslationOptions, ArkUI_TranslationOptions, ArkUI_RotationOptions', + url:'pages/animation/animationIndex5'}, + ]; + + @Builder cApiMenu() { + Grid() { + ForEach(this.items, (item: ListCategories) => { + GridItem() { + Button(item.title) + .key(item.title) + .width('100%') + .height('100%') + .fontSize(10) + .padding(1) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr') + .columnsGap(8) + .rowsGap(8) + .width('100%') + } + + build() { + Scroll(new Scroller()) { + Column() { + Stack() { + Row() { + Text(this.message) + .fontSize(22) + .fontColor(0xFFFFFF) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width('100%') + .height(50) + .backgroundColor('#FF08528A') + }.width('100%') + Button('menu') + .key('menu') + .onClick(() => { + this.isShow = true; + }) + .fontSize(10) + .position({top: 5, right: 5}) + .backgroundColor(Color.Transparent) + .fontColor(Color.Transparent) + .bindSheet($$this.isShow, this.cApiMenu(), { + showClose: false, + preferType: SheetType.BOTTOM + }) + } + + List({ space: '20vp' }) { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Button(item.title) + .fontSize(15) + .labelStyle({ maxLines: 10 }) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('90%').height('90%') + }.width('100%').height('100%').backgroundColor('#FFDDE7F6') + } + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_visual_effects.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_visual_effects.ets new file mode 100644 index 000000000..d6a0a5a90 --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/page_visual_effects.ets @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +interface ListCategories { + title:string, + url:string +} + +@Entry +@Component +struct VisualEffectsIndex { + @State message: string = 'CApi'; + @State isShow: boolean = false; + private items : ListCategories[] = [ + {title:'ArkUI_ShadowType, ArkUI_ShadowStyle, ArkUI_MaskType',url:'pages/visualEffects/visualEffectsIndex1'}, + {title:'ArkUI_AdaptiveColor, ArkUI_BlurStyle, ArkUI_ClipType',url:'pages/visualEffects/visualEffectsIndex2'}, + {title:'ArkUI_ColorStop, ArkUI_LinearGradientDirection',url:'pages/visualEffects/visualEffectsIndex3'}, + ]; + + @Builder cApiMenu() { + Grid() { + ForEach(this.items, (item: ListCategories) => { + GridItem() { + Button(item.title) + .key(item.title) + .width('100%') + .height('100%') + .fontSize(10) + .padding(1) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr') + .columnsGap(8) + .rowsGap(8) + .width('100%') + } + + build() { + Scroll(new Scroller()) { + Column() { + Stack() { + Row() { + Text(this.message) + .fontSize(22) + .fontColor(0xFFFFFF) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width('100%') + .height(50) + .backgroundColor('#FF08528A') + }.width('100%') + Button('menu') + .key('menu') + .onClick(() => { + this.isShow = true; + }) + .fontSize(10) + .position({top: 5, right: 5}) + .backgroundColor(Color.Transparent) + .fontColor(Color.Transparent) + .bindSheet($$this.isShow, this.cApiMenu(), { + showClose: false, + preferType: SheetType.BOTTOM + }) + } + + List({ space: '20vp' }) { + ForEach(this.items, (item: ListCategories) => { + ListItem() { + Button(item.title) + .fontSize(15) + .labelStyle({ maxLines: 10 }) + .onClick(() => { + router.pushUrl({ url: item.url }); + }) + } + }) + }.alignListItem(ListItemAlign.Center).margin({ top: '10vp' }).width('90%').height('90%') + }.width('100%').height('100%').backgroundColor('#FFDDE7F6') + } + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets new file mode 100644 index 000000000..94fc947ff --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex1.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects1(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets new file mode 100644 index 000000000..d8f357ffd --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex2.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects2(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets new file mode 100644 index 000000000..bc29d96ff --- /dev/null +++ b/ArkUIKit/NativeTypeSample/entry/src/main/ets/pages/visualEffects/visualEffectsIndex3.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Napi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; +@Entry +@Component +struct Index5 { + private rootSlot = new NodeContent(); + @State isModuleLoaded: boolean = false; + + aboutToAppear(): void { + if (Napi) { + Napi?.createNativeRootVisualEffects3(this.rootSlot); + } + } + aboutToDisappear(): void { + if (Napi) { + Napi.destroyNativeRoot(); + } + } + + build() { + Column() { + Row() { + ContentSlot(this.rootSlot) + }.layoutWeight(1) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file -- Gitee