diff --git a/ArkUIKit/LayoutSample/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/LayoutSample/entry/src/main/cpp/CMakeLists.txt index f4f30dcd128ef753461f393d40a9b012c48f5a6a..8a0ffe61289401efcf43397cbe376d4908af23f6 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 874a7464709d4af96aa066e9e7f2c7ee33a0f773..54237845df8d78b89d1056c9850f856e11ccaac3 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 8b19796274103f68460a05da7bac546af2572b96..5777b14d01846f463f7b66492e8555a7668d3614 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 e49e92966bc052b3459ead5396e0d87950feb26a..ff57cd859ae7df2e72ed127822d8eecdb5669d35 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,37 +92,14 @@ 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 23f1a34e30674148cb109ec2ac802ca25b7d4847..167bcdb5011da771f3697b56f8930020f910164d 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 37aaa93424d1eb880416f1891efec75a93c027f9..b23b100b98c4c2782542934d5101dc642d47a60c 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 3c9b09aeffe6b5e1ccd8c2a853ffd907ed17e903..072abefa8cc6a9ea4e0de5db61f31f73be5b5511 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 d2e4dca1575948b73d20c7dd726fd1cc452684d2..946af776461632c54d9dd6c0fd9b2ee23a040347 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 483158327dcfb5d3c2efe462f03a68f920822e5c..949fa6187c76982a2ad8b9afd68d96acf86e7cd3 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",