From 56abd4f7f2ac0cc1903f0b87e9249077edb3a380 Mon Sep 17 00:00:00 2001 From: zwt Date: Thu, 18 Dec 2025 14:27:55 +0800 Subject: [PATCH 1/2] refresh event delete Signed-off-by: zwt --- .../entry/src/main/cpp/CMakeLists.txt | 2 +- .../entry/src/main/cpp/NativeEntry.cpp | 6 +-- .../entry/src/main/cpp/NativeEntry.h | 4 +- ...Example.h => onVisibleAreaChangeExample.h} | 42 +++++-------------- .../entry/src/main/cpp/napi_init.cpp | 2 +- .../src/main/cpp/types/libentry/Index.d.ts | 4 +- .../entry/src/main/ets/pages/node.ets | 4 +- ...s => createOnVisibleAreaChangeExample.ets} | 6 +-- .../resources/base/profile/main_pages.json | 2 +- 9 files changed, 25 insertions(+), 47 deletions(-) rename ArkUIKit/LayoutSample/entry/src/main/cpp/examples/{refreshOffsetChangeExample.h => onVisibleAreaChangeExample.h} (68%) rename ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/{createRefreshOffsetEventExample.ets => createOnVisibleAreaChangeExample.ets} (87%) diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/LayoutSample/entry/src/main/cpp/CMakeLists.txt index f4f30dcd1..8a0ffe612 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/CMakeLists.txt +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/CMakeLists.txt @@ -19,5 +19,5 @@ find_library( hilog_ndk.z ) -add_library(entry SHARED napi_init.cpp NativeEntry.cpp NativeEntry.h NativeModule.h nodes/ArkUINode.h nodes/ArkUINode.cpp examples/guidelineOptionExample.h examples/barrierOptionExample.h examples/listChildrenMainSizeExample.h nodes/ArkUIListNode.h examples/itemAlignmentExample.h nodes/ArkUIFlexNode.h examples/relativeLayoutChainExample.h examples/flexExample.h nodes/ArkUIStackNode.h examples/stackExample.h examples/rowExample.h examples/columnExample.h examples/layoutPositionExample.h nodes/ArkUICustomColumnNode.h examples/safeAreaExample.h examples/layoutPolicyExample.h examples/positionEdgesExample.h nodes/ArkUIButtonNode.h) +add_library(entry SHARED napi_init.cpp NativeEntry.cpp NativeEntry.h NativeModule.h nodes/ArkUINode.h nodes/ArkUINode.cpp examples/guidelineOptionExample.h examples/barrierOptionExample.h examples/listChildrenMainSizeExample.h nodes/ArkUIListNode.h examples/itemAlignmentExample.h nodes/ArkUIFlexNode.h examples/relativeLayoutChainExample.h examples/flexExample.h nodes/ArkUIStackNode.h examples/stackExample.h examples/rowExample.h examples/columnExample.h examples/layoutPositionExample.h nodes/ArkUICustomColumnNode.h examples/safeAreaExample.h examples/layoutPolicyExample.h examples/positionEdgesExample.h nodes/ArkUIButtonNode.h examples/onVisibleAreaChangeExample.h) target_link_libraries(entry PUBLIC libace_napi.z.so libace_ndk.z.so ${hilog-lib} libhilog_ndk.z.so) \ No newline at end of file diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.cpp b/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.cpp index 874a74647..54237845d 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.cpp +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.cpp @@ -30,7 +30,7 @@ #include "examples/columnExample.h" #include "examples/layoutPositionExample.h" #include "examples/safeAreaExample.h" -#include "examples/refreshOffsetChangeExample.h" +#include "examples/onVisibleAreaChangeExample.h" #include "examples/positionEdgesExample.h" #include "examples/pixelRoundExample.h" @@ -106,8 +106,8 @@ DEFINE_CREATE_DESTROY_FUNCTIONS(Column, CreateColumnExample) DEFINE_CREATE_DESTROY_FUNCTIONS(LayoutPosition, CreateLayoutPositionExample) // 安全区域模块 DEFINE_CREATE_DESTROY_FUNCTIONS(SafeArea, SafeAreaExample) -// 刷新偏移事件模块 -DEFINE_CREATE_DESTROY_FUNCTIONS(RefreshOffsetEvent, CreateRefreshOffsetEventExample) +// 可视区域变化 +DEFINE_CREATE_DESTROY_FUNCTIONS(OnVisibleAreaChange, CreateOnVisibleAreaChangeExample) // 布局策略模块 DEFINE_CREATE_DESTROY_FUNCTIONS(LayoutPolicy, CreateLayoutPolicyExample) // 位置边缘模块 diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.h b/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.h index 8b1979627..5777b14d0 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.h +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/NativeEntry.h @@ -76,8 +76,8 @@ napi_value CreateSafeAreaNativeRoot(napi_env env, napi_callback_info info); napi_value DestroySafeAreaNativeRoot(napi_env env, napi_callback_info info); // 刷新偏移事件相关接口 -napi_value CreateRefreshOffsetEventNativeRoot(napi_env env, napi_callback_info info); -napi_value DestroyRefreshOffsetEventNativeRoot(napi_env env, napi_callback_info info); +napi_value CreateOnVisibleAreaChangeNativeRoot(napi_env env, napi_callback_info info); +napi_value DestroyOnVisibleAreaChangeNativeRoot(napi_env env, napi_callback_info info); // 布局策略相关接口 napi_value CreateLayoutPolicyNativeRoot(napi_env env, napi_callback_info info); diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/refreshOffsetChangeExample.h b/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h similarity index 68% rename from ArkUIKit/LayoutSample/entry/src/main/cpp/examples/refreshOffsetChangeExample.h rename to ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h index e49e92966..a33e0b6a3 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/refreshOffsetChangeExample.h +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h @@ -37,7 +37,7 @@ constexpr float VISIBLE_AREA_RATIO = 0.5f; constexpr float OFFSET_INCREMENT = 10.0f; } // namespace RefreshConstants -std::shared_ptr CreateRefreshListItemText(int index) +std::shared_ptr CreateOnVisibleAreaChangeListItemText(int index) { auto text = std::make_shared(); text->SetTextContent("item-" + std::to_string(index)); @@ -49,14 +49,13 @@ std::shared_ptr CreateRefreshListItemText(int index) text->SetTextAlignment(ARKUI_TEXT_ALIGNMENT_CENTER); // 注册事件 - text->SetRegisterRefreshEvent(); text->SetVisibleAreaChangeRatio(RefreshConstants::VISIBLE_AREA_RATIO); text->SetRegisterVisibleAreaChangeEvent(); return text; } -std::shared_ptr CreateRefreshListItem(std::shared_ptr text) +std::shared_ptr CreateOnVisibleAreaChangeListItem(std::shared_ptr text) { auto child = std::make_shared(); child->AddChild(text); @@ -69,15 +68,15 @@ struct ListWithTexts { std::vector> texts; }; -ListWithTexts CreateRefreshPopulatedList() +ListWithTexts CreateOnVisibleAreaChangePopulatedList() { auto list = std::make_shared(); std::vector> texts; // 创建列表项 for (int i = 0; i < RefreshConstants::LIST_ITEM_COUNT; ++i) { - auto text = CreateRefreshListItemText(i); - auto listItem = CreateRefreshListItem(text); + auto text = CreateOnVisibleAreaChangeListItemText(i); + auto listItem = CreateOnVisibleAreaChangeListItem(text); list->AddChild(listItem); texts.push_back(text); } @@ -85,7 +84,7 @@ ListWithTexts CreateRefreshPopulatedList() return {list, texts}; } -void ConfigureRefreshListProperties(std::shared_ptr list) +void ConfigureOnVisibleAreaChangeListProperties(std::shared_ptr list) { list->SetBackgroundColor(RefreshConstants::LIST_BACKGROUND_COLOR); list->SetLayoutWeight(1); @@ -93,36 +92,15 @@ void ConfigureRefreshListProperties(std::shared_ptr list) list->SetListItemAlign(ARKUI_LIST_ITEM_ALIGNMENT_CENTER); } -std::shared_ptr CreateRefreshOffsetButton(const std::vector>& texts) -{ - auto btn = std::make_shared(); - btn->SetTextContent("refreshOffset+50"); - btn->SetWidth(RefreshConstants::BUTTON_WIDTH); - btn->SetHeight(Sizes::MEDIUM); - btn->SetBackgroundColor(Colors::YELLOW); - - // 使用shared_ptr管理偏移量 - auto offset = std::make_shared(Sizes::MEDIUM); - btn->SetOnClick([offset, texts]() { - texts[Indices::ZERO]->SetRefreshOffset(*offset); - *offset += RefreshConstants::OFFSET_INCREMENT; - }); - - return btn; -} - -std::shared_ptr CreateRefreshOffsetEventExample() +std::shared_ptr CreateOnVisibleAreaChangeExample() { auto column = std::make_shared(); // 创建并配置列表 - 使用结构体避免C++17结构化绑定 - ListWithTexts listData = CreateRefreshPopulatedList(); - ConfigureRefreshListProperties(listData.list); + ListWithTexts listData = CreateOnVisibleAreaChangePopulatedList(); + ConfigureOnVisibleAreaChangeListProperties(listData.list); column->AddChild(listData.list); - - // 创建按钮 - auto button = CreateRefreshOffsetButton(listData.texts); - column->AddChild(button); + return column; } diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/LayoutSample/entry/src/main/cpp/napi_init.cpp index 23f1a34e3..167bcdb50 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/napi_init.cpp +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/napi_init.cpp @@ -48,7 +48,7 @@ static napi_value Init(napi_env env, napi_value exports) // 位置和区域相关组件 REGISTER_COMPONENT(LayoutPosition), REGISTER_COMPONENT(SafeArea), - REGISTER_COMPONENT(RefreshOffsetEvent), + REGISTER_COMPONENT(OnVisibleAreaChange), // 策略和边缘相关组件 REGISTER_COMPONENT(LayoutPolicy), diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/LayoutSample/entry/src/main/cpp/types/libentry/Index.d.ts index 37aaa9342..b23b100b9 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/types/libentry/Index.d.ts @@ -37,8 +37,8 @@ export const DestroyLayoutPositionNativeRoot: () => void; export const CreateSafeAreaNativeRoot: (content: Object) => void; export const DestroySafeAreaNativeRoot: () => void; -export const CreateRefreshOffsetEventNativeRoot: (content: Object) => void; -export const DestroyRefreshOffsetEventNativeRoot: () => void; +export const CreateOnVisibleAreaChangeNativeRoot: (content: Object) => void; +export const DestroyOnVisibleAreaChangeNativeRoot: () => void; export const CreatePositionEdgesNativeRoot: (content: Object) => void; export const DestroyPositionEdgesNativeRoot: () => void; diff --git a/ArkUIKit/LayoutSample/entry/src/main/ets/pages/node.ets b/ArkUIKit/LayoutSample/entry/src/main/ets/pages/node.ets index 3c9b09aef..072abefa8 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/ets/pages/node.ets +++ b/ArkUIKit/LayoutSample/entry/src/main/ets/pages/node.ets @@ -46,8 +46,8 @@ struct NodeTestPage { page: 'pages/nodeTest/createSafeAreaExample' }, { - title: 'refreshOffsetEvent测试', - page: 'pages/nodeTest/createRefreshOffsetEventExample' + title: 'OnVisibleAreaChange测试', + page: 'pages/nodeTest/createOnVisibleAreaChangeExample' }, { title: 'layoutPolicy测试', diff --git a/ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/createRefreshOffsetEventExample.ets b/ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/createOnVisibleAreaChangeExample.ets similarity index 87% rename from ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/createRefreshOffsetEventExample.ets rename to ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/createOnVisibleAreaChangeExample.ets index d2e4dca15..946af7764 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/createRefreshOffsetEventExample.ets +++ b/ArkUIKit/LayoutSample/entry/src/main/ets/pages/nodeTest/createOnVisibleAreaChangeExample.ets @@ -23,16 +23,16 @@ export interface DataClass { @Entry @Component -struct createRefreshOffsetEventTest { +struct createOnVisibleAreaChangeTest { // 初始化NodeContent对象。 private rootSlot = new NodeContent(); aboutToAppear(): void { - nativeNode.CreateRefreshOffsetEventNativeRoot(this.rootSlot) + nativeNode.CreateOnVisibleAreaChangeNativeRoot(this.rootSlot) } aboutToDisappear(): void { - nativeNode.DestroyRefreshOffsetEventNativeRoot() + nativeNode.DestroyOnVisibleAreaChangeNativeRoot() } build() { diff --git a/ArkUIKit/LayoutSample/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/LayoutSample/entry/src/main/resources/base/profile/main_pages.json index 483158327..949fa6187 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/resources/base/profile/main_pages.json +++ b/ArkUIKit/LayoutSample/entry/src/main/resources/base/profile/main_pages.json @@ -13,7 +13,7 @@ "pages/nodeTest/createColumnExample", "pages/nodeTest/createFlexExample", "pages/nodeTest/createLayoutPositionExample", - "pages/nodeTest/createRefreshOffsetEventExample", + "pages/nodeTest/createOnVisibleAreaChangeExample", "pages/nodeTest/createRowExample", "pages/nodeTest/createSafeAreaExample", "pages/nodeTest/createStackExample", -- Gitee From 64dc7ea7631e61a4f7db4f6c429949fdeef58594 Mon Sep 17 00:00:00 2001 From: zwt Date: Thu, 18 Dec 2025 15:27:25 +0800 Subject: [PATCH 2/2] refresh event delete Signed-off-by: zwt --- .../entry/src/main/cpp/examples/onVisibleAreaChangeExample.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h b/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h index a33e0b6a3..ff57cd859 100755 --- a/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h +++ b/ArkUIKit/LayoutSample/entry/src/main/cpp/examples/onVisibleAreaChangeExample.h @@ -100,8 +100,6 @@ std::shared_ptr CreateOnVisibleAreaChangeExample() ListWithTexts listData = CreateOnVisibleAreaChangePopulatedList(); ConfigureOnVisibleAreaChangeListProperties(listData.list); column->AddChild(listData.list); - - return column; } -- Gitee