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 c691232cbb42a77a4e8a2a3509a532321c4f1b80..88de1ff168170a15804ee3aaecdd92c60b90cfb8 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 3fe57ad3924f96f7b2a39b5023a1cdfe3e698374..bef97e92b848582e419ee4df55ba7e9396a61f3e 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 0a6fc0796d7e74396751b2827a682bdedf0e1515..30aabdda7482cb371365f793ac11ed42f820be1e 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