From 262e4dff3aa8755c97986e4ded1d9e46446a3606 Mon Sep 17 00:00:00 2001 From: zakalyukinalexander_ac40 Date: Mon, 4 Aug 2025 12:31:42 +0300 Subject: [PATCH] Description: capi waterflow accessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 是否涉及非兼容变更: 否 TDD自验结果(如有失败用例需提供基线执行情况): Pass XTS自验结果(如有失败用例需提供基线执行情况): 不涉及 检视意见是否都已闭环(无检视意见填是):是 Signed-off-by: zakalyukinalexander_ac40 --- .../water_flow_sections_accessor.cpp | 10 ++++- .../native/utility/callback_keeper.h | 3 +- .../water_flow_section_accessor_test.cpp | 37 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/frameworks/core/interfaces/native/implementation/water_flow_sections_accessor.cpp b/frameworks/core/interfaces/native/implementation/water_flow_sections_accessor.cpp index c691232cbb4..88de1ff1681 100644 --- a/frameworks/core/interfaces/native/implementation/water_flow_sections_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/water_flow_sections_accessor.cpp @@ -59,7 +59,14 @@ void AssignArkValue(Ark_SectionOptions& dst, const WaterFlowSections::Section& s { dst.itemsCount = Converter::ArkValue(src.itemsCount); dst.crossCount = Converter::ArkValue(src.crossCount); - LOGE("CallbackKeeper does not support callback with parameters, dst.onGetItemMainSizeByIndex isn't converted"); + auto cb = [src](const Ark_Number index, const Callback_Number_Void continuation) { + auto result = src.onGetItemMainSizeByIndex(Converter::Convert(index)); + auto helper = CallbackHelper(continuation); + helper.Invoke(Converter::ArkValue(result)); + }; + auto rc = CallbackKeeper::RegisterReverseCallback<::GetItemMainSizeByIndex, + std::function>(cb); + dst.onGetItemMainSizeByIndex = Converter::ArkValue(rc); dst.columnsGap = Converter::ArkValue(src.columnsGap); dst.rowsGap = Converter::ArkValue(src.rowsGap); dst.margin = Converter::ArkUnion(src.margin); @@ -128,7 +135,6 @@ Array_SectionOptions ValuesImpl(Ark_WaterFlowSections peer) CHECK_NULL_RETURN(peer, {}); CHECK_NULL_RETURN(peer->GetController(), {}); auto info = peer->GetController()->GetSectionInfo(); - LOGE("WaterFlowSectionAccessor.ValuesImpl -> converter is not fully implemented"); auto options = Converter::ArkValue(info, Converter::FC); return options; } diff --git a/frameworks/core/interfaces/native/utility/callback_keeper.h b/frameworks/core/interfaces/native/utility/callback_keeper.h index 3fe57ad3924..bef97e92b84 100644 --- a/frameworks/core/interfaces/native/utility/callback_keeper.h +++ b/frameworks/core/interfaces/native/utility/callback_keeper.h @@ -48,7 +48,8 @@ using ReverseResultHandler = std::variant< std::function, std::function, std::function, - std::function + std::function, + std::function >; } diff --git a/test/unittest/capi/accessors/water_flow_section_accessor_test.cpp b/test/unittest/capi/accessors/water_flow_section_accessor_test.cpp index 0a6fc0796d7..30aabdda748 100755 --- a/test/unittest/capi/accessors/water_flow_section_accessor_test.cpp +++ b/test/unittest/capi/accessors/water_flow_section_accessor_test.cpp @@ -15,6 +15,7 @@ #include "core/interfaces/native/implementation/water_flow_sections_accessor_peer_impl.h" #include "core/components_ng/pattern/waterflow/water_flow_sections.h" +#include "core/interfaces/native/utility/callback_helper.h" #include "accessor_test_base.h" #include "node_api.h" #include "core/interfaces/native/utility/reverse_converter.h" @@ -120,4 +121,40 @@ HWTEST_F(WaterFlowSectionAccessorTest, ValuesTest, TestSize.Level1) EXPECT_EQ(Converter::OptConvert(section.margin), Converter::OptConvert(sections.array[0].margin)); } + +/** + * @tc.name: OnGetItemMainSizeByIndexTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(WaterFlowSectionAccessorTest, OnGetItemMainSizeByIndexTest, TestSize.Level1) +{ + const auto inputValue = 123; + const auto expextedValue = 789; + auto onGetItemMainSizeByIndex = [](int32_t index) -> float { + return index == 123 ? 789 : 0; + }; + + std::vector waterFlowSections; + WaterFlowSections::Section waterFlowsection; + + waterFlowsection.onGetItemMainSizeByIndex = onGetItemMainSizeByIndex; + waterFlowSections.push_back(waterFlowsection); + auto start = peer_->GetController()->GetSectionInfo().size(); + peer_->GetController()->ChangeData(start, 0, waterFlowSections); + + Array_SectionOptions arkSections = accessor_->values(peer_); + + ASSERT_TRUE(arkSections.length == 1); + auto onGetItemMainSizeByIndeX = Converter::OptConvert<::GetItemMainSizeByIndex> + (arkSections.array[0].onGetItemMainSizeByIndex); + ASSERT_TRUE(onGetItemMainSizeByIndeX); + auto modelCallback = [callback = CallbackHelper(*onGetItemMainSizeByIndeX)] + (int32_t value) -> float { + Ark_Number param = Converter::ArkValue(value); + auto resultOpt = callback.InvokeWithOptConvertResult(param); + return resultOpt.value_or(0); + }; + EXPECT_EQ(modelCallback(inputValue), expextedValue); +} } // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee