diff --git a/frameworks/bridge/arkts_frontend/ani_water_flow_module.h b/frameworks/bridge/arkts_frontend/ani_water_flow_module.h deleted file mode 100644 index 1ea6f1095e025ca742397ca93e4b3b3e284497b9..0000000000000000000000000000000000000000 --- a/frameworks/bridge/arkts_frontend/ani_water_flow_module.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ARKTS_FRONTEND_ANI_WATER_FLOW_MODULE_H -#define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ARKTS_FRONTEND_ANI_WATER_FLOW_MODULE_H - -#include -#include "core/components_ng/pattern/waterflow/water_flow_sections.h" -#include "core/components_ng/pattern/waterflow/water_flow_model_ng.h" - -typedef class __ani_object* ani_object; -typedef struct __ani_env ani_env; -typedef int64_t ani_long; -typedef class __ani_fn_object* ani_fn_object; -typedef class __ani_ref* ani_ref; - -namespace OHOS::Ace::Framework { - -class AniWaterFlowModule { -public: - static void SetWaterFlowSection(ani_env* env, ani_long ptr, ani_object obj); - static void ParseWaterFlowSections(ani_env* env, ani_ref sections, NG::FrameNode* frameNode); - static NG::WaterFlowSections::Section ParseSectionOptions(ani_env* env, ani_ref section); -}; - -} // namespace OHOS::Ace::Framework -#endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ARKTS_FRONTEND_ANI_WATER_FLOW_MODULE_H diff --git a/frameworks/bridge/arkts_frontend/koala_mirror/arkoala-arkts/arkui/src/ani/native/module.cpp b/frameworks/bridge/arkts_frontend/koala_mirror/arkoala-arkts/arkui/src/ani/native/module.cpp index be178d9056a19a71d937060cc985dd7b9b6b0bec..331c729d198d82ff05a5a133b605595e77184d4f 100644 --- a/frameworks/bridge/arkts_frontend/koala_mirror/arkoala-arkts/arkui/src/ani/native/module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_mirror/arkoala-arkts/arkui/src/ani/native/module.cpp @@ -30,7 +30,7 @@ #include "load.h" #include "log/log.h" #include "utils/convert_utils.h" -#include "water_flow/waterFlowSection_module.h" +#include "water_flow/water_flow_module.h" #include "interop/interop_module.h" #include "web/web_module_methods.h" #include "video/video_module_methods.h" diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentContent.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentContent.ts index 10afc1aa7a6a4eb0ba99a30712684791d349203e..90da9c1880809db15c7dedb47899e40c54efcffc 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentContent.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentContent.ts @@ -23,7 +23,7 @@ import { Content } from "./Content" import { KPointer, pointer } from "@koalaui/interop" export interface ComponentContentBase extends Content { - + getNodePtr(): KPointer | undefined; } export class ComponentContent implements ComponentContentBase { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts index b4cb7e0fb8e8bb57c56bf3e66356aee6d80d3315..2c0b6f595e348f2eaf75cdadc584ba16791cc859 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts @@ -64,7 +64,8 @@ export class ArkUIAniModule { native static _SetDrawCallback(ptr: KPointer, callback: ((context: DrawContext) => void)): void native static _SetDrawModifier(ptr: KPointer, flag: KInt, drawModifier: DrawModifier): void native static _Invalidate(ptr: KPointer): void - native static _SetWaterFlowOptions(ptr: KPointer, options: WaterFlowOptions): void + native static _SetWaterFlowSection(ptr: KPointer, sections: WaterFlowSections): void + native static _SetWaterFlowFooterContent(ptr: KPointer, footerContent: KPointer): void native static _SetListChildrenMainSize(ptr: KPointer, value: ChildrenMainSize): void native static _LazyForEachNode_Construct(id: KInt): KPointer native static _SetOverlay_ComponentContent(node: KPointer, buildNodePtr: KPointer, options?: OverlayOptions): void diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn index ae914f01e0122e296cc298f0eab219290529ffa3..972eb6e5316d71535655476fca7afaf5eb108c7a 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn @@ -52,7 +52,7 @@ ohos_shared_library("arkoala_native_ani") { "video/video_module_methods.cpp", "rich_editor/rich_editor_module.cpp", "stateMgmt/stateMgmt_module.cpp", - "water_flow/waterFlowSection_module.cpp", + "water_flow/water_flow_module.cpp", "list/list_children_main_size_module.cpp", "web/web_module_methods.cpp", "xcomponent/xcomponent_module_methods.cpp", @@ -102,7 +102,7 @@ if (use_linux) { "module_linux.cpp", "stateMgmt/stateMgmt_module.cpp", "utils/ani_utils.cpp", - "water_flow/waterFlowSection_module.cpp", + "water_flow/water_flow_module.cpp", "xcomponent/xcomponent_module_methods.cpp", ] diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp index 109d37894a501527b26485de6930ec418c51402e..8914d86af03f777b0697d55ffc679cd8365eaaf6 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp @@ -32,7 +32,7 @@ #include "load.h" #include "log/log.h" #include "utils/convert_utils.h" -#include "water_flow/waterFlowSection_module.h" +#include "water_flow/water_flow_module.h" #include "interop/interop_module.h" #include "web/web_module_methods.h" #include "video/video_module_methods.h" @@ -374,9 +374,14 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) reinterpret_cast(OHOS::Ace::Ani::SetOverlayComponentContent) }, ani_native_function { - "_SetWaterFlowOptions", - "JLarkui/component/waterFlow/WaterFlowOptions;:V", - reinterpret_cast(OHOS::Ace::Ani::SetWaterFlowOptions) + "_SetWaterFlowSection", + "JLarkui/component/waterFlow/WaterFlowSections;:V", + reinterpret_cast(OHOS::Ace::Ani::SetWaterFlowSection) + }, + ani_native_function { + "_SetWaterFlowFooterContent", + "JJ:V", + reinterpret_cast(OHOS::Ace::Ani::SetWaterFlowFooterContent) }, ani_native_function { "_SetListChildrenMainSize", diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module_linux.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module_linux.cpp index 4d29bb8b864816cb7009853a2bd8592b31880c9e..e6808b8e3cded8e1c5a32c3f20f548e66e46bad7 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module_linux.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module_linux.cpp @@ -24,7 +24,7 @@ #include "list/list_children_main_size_module.h" #include "load.h" #include "log/log.h" -#include "water_flow/waterFlowSection_module.h" +#include "water_flow/water_flow_module.h" #include "interop/interop_module.h" #include "stateMgmt/stateMgmt_module.h" #include "xcomponent/xcomponent_module_methods.h" @@ -135,9 +135,14 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) reinterpret_cast(OHOS::Ace::Ani::SetOverlayComponentContent) }, ani_native_function { - "_SetWaterFlowOptions", - "JLarkui/component/waterFlow/WaterFlowOptions;:V", - reinterpret_cast(OHOS::Ace::Ani::SetWaterFlowOptions) + "_SetWaterFlowSection", + "JLarkui/component/waterFlow/WaterFlowSections;:V", + reinterpret_cast(OHOS::Ace::Ani::SetWaterFlowSection) + }, + ani_native_function { + "_SetWaterFlowFooterContent", + "JJ:V", + reinterpret_cast(OHOS::Ace::Ani::SetWaterFlowFooterContent) }, ani_native_function { "_SetListChildrenMainSize", diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/waterFlowSection_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/waterFlowSection_module.cpp deleted file mode 100644 index 416bd18ec486d8c750a27206ff0d5b04ac11f9b6..0000000000000000000000000000000000000000 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/waterFlowSection_module.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -#include "waterFlowSection_module.h" - -#include - -#include "common/common_module.h" -#include "load.h" -#include "utils/ani_utils.h" - -namespace OHOS::Ace::Ani { -void SetWaterFlowOptions(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_object waterFlowOptions) -{ - const auto* modifier = GetNodeAniModifier(); - CHECK_NULL_VOID(modifier); - modifier->getArkUIAniWaterFlowModifier()->setWaterFlowOptions(env, ptr, waterFlowOptions); -} -} // namespace OHOS::Ace::Ani diff --git a/frameworks/bridge/arkts_frontend/ani_water_flow_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/water_flow_module.cpp similarity index 58% rename from frameworks/bridge/arkts_frontend/ani_water_flow_module.cpp rename to frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/water_flow_module.cpp index 0224c9d7b9ba76a226384552e158812747e7e048..1db6d6018988dd3b11eb0b7131492e4ae6ad8c9c 100644 --- a/frameworks/bridge/arkts_frontend/ani_water_flow_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/water_flow_module.cpp @@ -4,7 +4,7 @@ * 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 + * 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, @@ -13,60 +13,50 @@ * limitations under the License. */ -#include "bridge/arkts_frontend/ani_water_flow_module.h" +#include +#include "water_flow_module.h" +#include "base/utils/utils.h" +#include "load.h" +#include "base/log/log.h" +#include "utils/ani_utils.h" -#include -#include -#include +namespace OHOS::Ace::Ani { -#include "ani_water_flow_module.h" - -#include "base/geometry/calc_dimension.h" -#include "base/utils/string_utils.h" -#include "core/components_ng/base/frame_node.h" -#include "core/components_ng/property/calc_length.h" -#include "core/components_ng/property/measure_property.h" - -namespace { -using namespace OHOS::Ace; - -ani_object CreateDouble(ani_env* env, double value) +void ParseStringToDimension(const std::string& str, ArkUIWaterFlowSectionGap* result) { - CHECK_NULL_RETURN(env, nullptr); - static const char* className = "std.core.Double"; - ani_class doubleCls; - if (ANI_OK != env->FindClass(className, &doubleCls)) { - return nullptr; - } - ani_method doubleCtor; - if (ANI_OK != env->Class_FindMethod(doubleCls, "", "d:", &doubleCtor)) { - return nullptr; + char* suffixPtr = nullptr; + float value = std::strtof(str.c_str(), &suffixPtr); + + if (!suffixPtr || suffixPtr == str.c_str()) { + // not a numeric value + result->unit = -1; + return; } - ani_object doubleObj; - if (ANI_OK != env->Object_New(doubleCls, doubleCtor, &doubleObj, static_cast(value))) { - return nullptr; + result->value = value; + if (suffixPtr[0] == '\0' || (suffixPtr[0] == 'v' && suffixPtr[1] == 'p')) { + // DimensionUnit::VP + result->unit = 1; + } else if (suffixPtr[0] == '%') { + // DimensionUnit::PERCENT + result->unit = 3; + } else if (suffixPtr[0] == 'p' && suffixPtr[1] == 'x') { + // DimensionUnit::PX + result->unit = 0; + } else if (suffixPtr[0] == 'l' && suffixPtr[1] == 'p' && suffixPtr[2] == 'x') { + // DimensionUnit::LPX + result->unit = 4; + } else if (suffixPtr[0] == 'f' && suffixPtr[1] == 'p') { + // DimensionUnit::FP + result->unit = 2; + } else { + // DimensionUnit::NONE + result->unit = -1; } - return doubleObj; } -std::string ANIUtils_ANIStringToStdString(ani_env* env, ani_string ani_str) +ArkUIWaterFlowSectionGap ParseDimension(ani_env *env, ani_ref dimensionRef) { - ani_size strSize; - env->String_GetUTF8Size(ani_str, &strSize); - - std::vector buffer(strSize + 1); - char* utf8Buffer = buffer.data(); - - ani_size bytesWritten = 0; - env->String_GetUTF8(ani_str, utf8Buffer, strSize + 1, &bytesWritten); - utf8Buffer[bytesWritten] = '\0'; - std::string content = std::string(utf8Buffer); - return content; -} - -std::optional ParseDimension(ani_env* env, ani_ref dimensionRef) -{ - std::optional res; + ArkUIWaterFlowSectionGap res; ani_class doubleClass; if (env->FindClass("std.core.Double", &doubleClass) != ANI_OK) { return res; @@ -84,81 +74,51 @@ std::optional ParseDimension(ani_env* env, ani_ref dimensionRef) if (dimension < 0) { dimension = 0; } - res = CalcDimension(dimension, DimensionUnit::VP); + res.value = dimension; + return res; } ani_boolean isString; env->Object_InstanceOf(static_cast(dimensionRef), stringClass, &isString); if (isString) { - auto stringDimension = ANIUtils_ANIStringToStdString(env, static_cast(dimensionRef)); - res = StringUtils::StringToDimension(stringDimension, true); - if (res->Value() < 0) { - res->SetValue(0.0); + auto stringDimension = AniUtils::ANIStringToStdString(env, static_cast(dimensionRef)); + ParseStringToDimension(stringDimension, &res); + if (res.value < 0) { + res.value = 0.0f; } } return res; } -NG::MarginProperty ParsePadding(ani_env* env, ani_ref paddingRef) +ArkUIWaterFlowSectionPadding ParsePadding(ani_env* env, ani_ref paddingRef) { - NG::MarginProperty res; - std::optional left; - std::optional right; - std::optional top; - std::optional bottom; + ArkUIWaterFlowSectionPadding res; ani_ref leftRef; env->Object_GetPropertyByName_Ref(static_cast(paddingRef), "left", &leftRef); - left = ParseDimension(env, leftRef); - if (left.has_value()) { - if (left.value().Unit() == DimensionUnit::CALC) { - res.left = NG::CalcLength(left.value().CalcValue()); - } else { - res.left = NG::CalcLength(left.value()); - } - } + res.left = ParseDimension(env, leftRef); ani_ref rightRef; env->Object_GetPropertyByName_Ref(static_cast(paddingRef), "right", &rightRef); - right = ParseDimension(env, rightRef); - if (right.has_value()) { - if (right.value().Unit() == DimensionUnit::CALC) { - res.right = NG::CalcLength(right.value().CalcValue()); - } else { - res.right = NG::CalcLength(right.value()); - } - } + res.right = ParseDimension(env, rightRef); ani_ref topRef; env->Object_GetPropertyByName_Ref(static_cast(paddingRef), "top", &topRef); - top = ParseDimension(env, topRef); - if (top.has_value()) { - if (top.value().Unit() == DimensionUnit::CALC) { - res.top = NG::CalcLength(top.value().CalcValue()); - } else { - res.top = NG::CalcLength(top.value()); - } - } + res.top = ParseDimension(env, topRef); ani_ref bottomRef; env->Object_GetPropertyByName_Ref(static_cast(paddingRef), "bottom", &bottomRef); - bottom = ParseDimension(env, bottomRef); - if (bottom.has_value()) { - if (bottom.value().Unit() == DimensionUnit::CALC) { - res.bottom = NG::CalcLength(bottom.value().CalcValue()); - } else { - res.bottom = NG::CalcLength(bottom.value()); - } - } + res.bottom = ParseDimension(env, bottomRef); + return res; } -std::optional ParseMargin(ani_env* env, ani_ref marginRef) +ArkUIWaterFlowSectionPadding ParseMargin(ani_env* env, ani_ref marginRef) { - NG::MarginProperty res; + ArkUIWaterFlowSectionPadding res; ani_class paddingClass; if (env->FindClass("arkui.component.units.Padding", &paddingClass) != ANI_OK) { - return std::make_optional(res); + return res; } ani_boolean isPadding; @@ -166,22 +126,18 @@ std::optional ParseMargin(ani_env* env, ani_ref marginRef) if (isPadding) { res = ParsePadding(env, marginRef); } else { - std::optional length = ParseDimension(env, marginRef); - if (length->Unit() == DimensionUnit::CALC) { - res.SetEdges(NG::CalcLength(length->CalcValue())); - } else { - res.SetEdges(NG::CalcLength(length.value())); - } + ArkUIWaterFlowSectionGap length = ParseDimension(env, marginRef); + res.left = length; + res.right = length; + res.top = length; + res.bottom = length; } - return std::make_optional(res); + return res; } -} // namespace - -namespace OHOS::Ace::Framework { -NG::WaterFlowSections::Section AniWaterFlowModule::ParseSectionOptions(ani_env* env, ani_ref section) +ArkUIWaterFlowSection ParseSectionOptions(ani_env* env, ani_ref section) { - NG::WaterFlowSections::Section curSection; + ArkUIWaterFlowSection curSection; ani_double itemsCount; if (env->Object_GetPropertyByName_Double(static_cast(section), "itemsCount", &itemsCount) != ANI_OK) { return curSection; @@ -245,9 +201,9 @@ NG::WaterFlowSections::Section AniWaterFlowModule::ParseSectionOptions(ani_env* env->GlobalReference_Create(func, &fnObjGlobalRef); auto onGetItemMainSizeByIndex = [fnObjGlobalRef, env](int32_t index) { ani_ref aniRes; - ani_ref aniIdx = CreateDouble(env, ani_double(index)); + ani_ref aniIndex = AniUtils::CreateDouble(env, ani_double(index)); - env->FunctionalObject_Call(static_cast(fnObjGlobalRef), 1, &aniIdx, &aniRes); + env->FunctionalObject_Call(static_cast(fnObjGlobalRef), 1, &aniIndex, &aniRes); ani_double res; env->Object_CallMethodByName_Double(static_cast(aniRes), "unboxed", ":d", &res); return static_cast(res); @@ -258,13 +214,26 @@ NG::WaterFlowSections::Section AniWaterFlowModule::ParseSectionOptions(ani_env* return curSection; } -void AniWaterFlowModule::ParseWaterFlowSections(ani_env* env, ani_ref sections, NG::FrameNode* frameNode) +void SetWaterFlowSection(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_object sections) { - auto waterFlowSections = NG::WaterFlowModelNG::GetOrCreateWaterFlowSections(frameNode); - CHECK_NULL_VOID(waterFlowSections); + const auto* modifier = GetNodeAniModifier(); + auto* arkNode = reinterpret_cast(ptr); + if (!modifier || !arkNode) { + return; + } + + ani_class waterflowSections; + if (env->FindClass("Larkui/component/waterFlow/WaterFlowSections;", &waterflowSections) != ANI_OK) { + return; + } + ani_boolean isSections; + env->Object_InstanceOf(sections, waterflowSections, &isSections); + if (!isSections) { + return; + } ani_ref changeArray; - if (env->Object_GetPropertyByName_Ref(static_cast(sections), "changeArray", &changeArray) != ANI_OK) { + if (env->Object_GetPropertyByName_Ref(sections, "changeArray", &changeArray) != ANI_OK) { return; } ani_size changeArrayLength; @@ -313,7 +282,7 @@ void AniWaterFlowModule::ParseWaterFlowSections(ani_env* env, ani_ref sections, } int32_t length = static_cast(aniLength); - std::vector newSections; + std::vector newSections; for (int32_t j = 0; j < length; j++) { ani_ref section; if (env->Array_Get_Ref(static_cast(sectionOptionsArray), j, §ion) != ANI_OK) { @@ -324,35 +293,25 @@ void AniWaterFlowModule::ParseWaterFlowSections(ani_env* env, ani_ref sections, if (!isSectionOptions) { continue; } - NG::WaterFlowSections::Section curSection = ParseSectionOptions(env, section); + ArkUIWaterFlowSection curSection = ParseSectionOptions(env, section); if (curSection.itemsCount < 0) { continue; } newSections.emplace_back(curSection); } - waterFlowSections->ChangeData(start, deleteCount, newSections); + modifier->getArkUIAniWaterFlowModifier()->setWaterFlowSection( + arkNode, start, deleteCount, static_cast(newSections.data()), newSections.size()); } } -void AniWaterFlowModule::SetWaterFlowSection(ani_env* env, ani_long ptr, ani_object obj) +void SetWaterFlowFooterContent(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_long footerPtr) { - auto* frameNode = reinterpret_cast(ptr); - CHECK_NULL_VOID(frameNode); - - ani_ref sections; - if (env->Object_GetPropertyByName_Ref(obj, "sections", §ions) != ANI_OK) { - return; - } - - ani_class waterflowSections; - if (env->FindClass("arkui.component.waterFlow.WaterFlowSections", &waterflowSections) != ANI_OK) { + const auto* modifier = GetNodeAniModifier(); + auto* arkNode = reinterpret_cast(ptr); + auto* footerNode = reinterpret_cast(footerPtr); + if (!modifier || !arkNode || !footerNode) { return; } - - ani_boolean isNumber; - env->Object_InstanceOf(static_cast(sections), waterflowSections, &isNumber); - if (isNumber) { - ParseWaterFlowSections(env, sections, frameNode); - } + modifier->getArkUIAniWaterFlowModifier()->setWaterFlowFooterContent(arkNode, footerNode); } -} // namespace OHOS::Ace::Framework +} // namespace OHOS::Ace::Ani diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/waterFlowSection_module.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/water_flow_module.h similarity index 78% rename from frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/waterFlowSection_module.h rename to frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/water_flow_module.h index 5cefd387c9a276026589ae0c1483e0694b709995..d69e976795b80940ac5ce485603e4fb0de0cf1f1 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/waterFlowSection_module.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/water_flow/water_flow_module.h @@ -19,7 +19,9 @@ #include "ani.h" namespace OHOS::Ace::Ani { -void SetWaterFlowOptions(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_object waterFlowOptions); +void SetWaterFlowSection(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_object waterFlowSection); +void SetWaterFlowFooterContent( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_long footerContent); } // namespace OHOS::Ace::Ani #endif // KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_ANI_NATIVE_WATER_FLOW_MODULE diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts index 237bda946e26dd3b01e727434c9fb565fd5d0fcd..71b3b2accec0d91b002d7308a87f1eb3a22ca9c5 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts @@ -12957,9 +12957,9 @@ export class Deserializer extends DeserializerBase { let footerContent_buf : ComponentContent | undefined if ((RuntimeType.UNDEFINED) != (footerContent_buf_runtimeType)) { - footerContent_buf = (valueDeserializer.readComponentContent() as ComponentContent) + footerContent_buf = undefined } - const footerContent_result : ComponentContent | undefined = footerContent_buf + const footerContent_result : ComponentContent | undefined = undefined const scroller_buf_runtimeType = (valueDeserializer.readInt8() as int32) let scroller_buf : Scroller | undefined if ((RuntimeType.UNDEFINED) != (scroller_buf_runtimeType)) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/waterFlow.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/waterFlow.ts index b4e539857a291ede150d9203a8d53ed1d666f669..81a7793c0b69c17a5c5ec261354588d3aaa91401 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/waterFlow.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/waterFlow.ts @@ -32,9 +32,9 @@ import { Resource } from "global.resource" import { Callback_Number_ScrollState_Literal_Number_offsetRemain, Literal_Number_offsetRemain, Callback_Number_Number_Void } from "./grid" import { ScrollState } from "./list" import { NodeAttach, remember } from "@koalaui/runtime" -import { ComponentContent } from "./arkui-custom" +import { ComponentContentBase } from "../ComponentContent" import { Scroller, OnScrollFrameBeginCallback } from "./scroll" -import { WaterFlowHandWritten } from "../handwritten/WaterFlowImpl" +import { hookWaterFlowOptionsImpl } from "../handwritten/WaterFlowImpl" export class ArkWaterFlowPeer extends ArkScrollableCommonMethodPeer { constructor(peerPtr: KPointer, id: int32, name: string = "", flags: int32 = 0) { @@ -48,7 +48,7 @@ export class ArkWaterFlowPeer extends ArkScrollableCommonMethodPeer { return _peer } setWaterFlowOptionsAttribute(options?: WaterFlowOptions): void { - WaterFlowHandWritten.hookWaterFlowOptionsImpl(this, options); + hookWaterFlowOptionsImpl(this, options); const thisSerializer : Serializer = Serializer.hold() let options_type : int32 = RuntimeType.UNDEFINED options_type = runtimeType(options) @@ -301,7 +301,7 @@ export enum WaterFlowLayoutMode { } export interface WaterFlowOptions { footer?: CustomBuilder; - footerContent?: ComponentContent; + footerContent?: ComponentContentBase; scroller?: Scroller; sections?: WaterFlowSections; layoutMode?: WaterFlowLayoutMode; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/WaterFlowImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/WaterFlowImpl.ts index 1af697dbea18459b00eeae1d29fbdfe65bff40e7..51a542aaaa8e0f6400ea5539d2fdc257aadfbfda 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/WaterFlowImpl.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/WaterFlowImpl.ts @@ -13,14 +13,20 @@ * limitations under the License. */ -import { WaterFlowOptions } from "../component/waterFlow" +import { WaterFlowOptions, ArkWaterFlowPeer } from "../component/waterFlow" import { PeerNode } from "../PeerNode" import { ArkUIAniModule } from "arkui.ani" -export class WaterFlowHandWritten { - static hookWaterFlowOptionsImpl(peer: PeerNode, options: WaterFlowOptions | undefined): void { - if (options !== undefined && options.sections !== undefined) { - ArkUIAniModule._SetWaterFlowOptions(peer.peer.ptr, options) - } +export function hookWaterFlowOptionsImpl(peer: ArkWaterFlowPeer, options: WaterFlowOptions | undefined): void { + if (options === undefined) { + return; + } + + if (options.sections !== undefined) { + ArkUIAniModule._SetWaterFlowSection(peer.peer.ptr, options.sections!) + options.footer = undefined; + } else if (options.footerContent !== undefined) { + ArkUIAniModule._SetWaterFlowFooterContent(peer.peer.ptr, options.footerContent!.getNodePtr()!) + options.footer = undefined; } } \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/waterFlow.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/waterFlow.ts index 3c95d557795ea55d764d0b2a1b9cee2ab8564bc7..69c59c31b46bd05460e4cd7e4e92f61b41a70664 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/waterFlow.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/waterFlow.ts @@ -103,8 +103,7 @@ export class WaterFlowSections implements MaterializedBase { if (deleteCount === undefined && sections === undefined) { intDeleteCount = oldLength - intStart; - } - else if(deleteCount !== undefined) { + } else if (deleteCount !== undefined) { intDeleteCount = Math.trunc(deleteCount); if (intDeleteCount > oldLength - intStart) { intDeleteCount = oldLength - intStart; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h index 3d8e45394fb3c0c5d15da6fabad4a682afb97c46..e5d76e5da651040230241c5d21864ad2b195d328 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h @@ -100454,7 +100454,7 @@ class Deserializer : public DeserializerBase { footer_buf.value = {valueDeserializer.readCallbackResource(), reinterpret_cast(valueDeserializer.readPointerOrDefault(reinterpret_cast(getManagedCallbackCaller(Kind_CustomNodeBuilder)))), reinterpret_cast(valueDeserializer.readPointerOrDefault(reinterpret_cast(getManagedCallbackCallerSync(Kind_CustomNodeBuilder))))}; } value.footer = footer_buf; - const auto footerContent_buf_runtimeType = static_cast(valueDeserializer.readInt8()); + const auto footerContent_buf_runtimeType = INTEROP_RUNTIME_UNDEFINED; Opt_ComponentContent footerContent_buf = {}; footerContent_buf.tag = footerContent_buf_runtimeType == INTEROP_RUNTIME_UNDEFINED ? INTEROP_TAG_UNDEFINED : INTEROP_TAG_OBJECT; if ((INTEROP_RUNTIME_UNDEFINED) != (footerContent_buf_runtimeType)) diff --git a/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.cpp b/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.cpp index 1b379ef20a232c6b737e8382923def9b5c5a172e..c3ef70ddbda4d48b6d131cb3db26333ab8292759 100644 --- a/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.cpp @@ -179,7 +179,7 @@ void WaterFlowModelStatic::SetItemMinHeight(FrameNode* frameNode, const std::opt auto layoutProperty = frameNode->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); if (minHeight) { - layoutProperty->UpdateItemMinSize(CalcSize(CalcLength(minHeight.value()), std::nullopt)); + layoutProperty->UpdateItemMinSize(CalcSize(std::nullopt, CalcLength(minHeight.value()))); } } @@ -189,7 +189,7 @@ void WaterFlowModelStatic::SetItemMaxWidth(FrameNode* frameNode, const std::opti auto layoutProperty = frameNode->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); if (maxWidth) { - layoutProperty->UpdateItemMinSize(CalcSize(CalcLength(maxWidth.value()), std::nullopt)); + layoutProperty->UpdateItemMaxSize(CalcSize(CalcLength(maxWidth.value()), std::nullopt)); } } @@ -199,7 +199,7 @@ void WaterFlowModelStatic::SetItemMaxHeight(FrameNode* frameNode, const std::opt auto layoutProperty = frameNode->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); if (maxHeight) { - layoutProperty->UpdateItemMinSize(CalcSize(CalcLength(maxHeight.value()), std::nullopt)); + layoutProperty->UpdateItemMaxSize(CalcSize(std::nullopt, CalcLength(maxHeight.value()))); } } diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 7929208f96a9cf20502657ad929beac07e00bfe5..d75bc778902d9ba17f7715fe69145ecde5b6453e 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -300,6 +300,26 @@ struct ArkUIXComponentParams { std::function onSurfaceChanged = nullptr; std::function onSurfaceDestroyed = nullptr; }; +struct ArkUIWaterFlowSectionGap { + int32_t unit = 1; + float value = 0.0f; +}; + +struct ArkUIWaterFlowSectionPadding { + ArkUIWaterFlowSectionGap top; + ArkUIWaterFlowSectionGap right; + ArkUIWaterFlowSectionGap bottom; + ArkUIWaterFlowSectionGap left; +}; + +struct ArkUIWaterFlowSection { + int32_t itemsCount = 0; + int32_t crossCount = 1; + ArkUIWaterFlowSectionGap columnsGap; + ArkUIWaterFlowSectionGap rowsGap; + ArkUIWaterFlowSectionPadding margin; + std::function onGetItemMainSizeByIndex; +}; struct ArkUIAniImageModifier { void (*setPixelMap)(ArkUINodeHandle node, void* pixelmap); @@ -431,7 +451,9 @@ struct ArkUIAniLazyForEachNodeModifier { ani_long (*constructLazyForEachNode)(ani_int); }; struct ArkUIAniWaterFlowModifier { - void (*setWaterFlowOptions)(ani_env* env, ani_long ptr, ani_object fnObj); + void (*setWaterFlowSection)( + ArkUINodeHandle node, double start, double deleteCount, void* section, ArkUI_Int32 size); + void (*setWaterFlowFooterContent)(ArkUINodeHandle node, ArkUINodeHandle footerPtr); }; struct ArkUIAniListModifier { bool (*updateDefaultSizeAndGetNeedSync)(ArkUINodeHandle node, double defaultSize); diff --git a/frameworks/core/interfaces/native/ani/waterflow_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/waterflow_ani_modifier.cpp index f2b275e9ceffd04d61654f1cd8ebd18b201de450..27a5f7aebdf87d8697de6ae849592552ea88818f 100644 --- a/frameworks/core/interfaces/native/ani/waterflow_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/waterflow_ani_modifier.cpp @@ -14,25 +14,80 @@ */ #include "waterflow_ani_modifier.h" -#include -#include - -#include "frameworks/bridge/arkts_frontend/ani_water_flow_module.h" #include "base/log/log.h" #include "core/components_ng/base/frame_node.h" +#include "core/components_ng/pattern/waterflow/water_flow_model_static.h" +#include "core/interfaces/native/implementation/frame_node_peer_impl.h" namespace OHOS::Ace::NG { -void SetWaterFlowOptions(ani_env* env, ani_long ptr, ani_object fnObj) + +Dimension ConvertLengthToDimension(const ArkUIWaterFlowSectionGap &src) +{ + auto unit = static_cast(src.unit); + auto value = src.value; + if (unit == OHOS::Ace::DimensionUnit::PERCENT) { + value /= 100.0f; + } + return Dimension(value, unit); +} + +MarginProperty ConvertToMargin(const ArkUIWaterFlowSectionPadding& src) { - auto* frameNode = reinterpret_cast(ptr); + MarginProperty padding; + padding.left = CalcLength(ConvertLengthToDimension(src.left)); + padding.top = CalcLength(ConvertLengthToDimension(src.top)); + padding.right = CalcLength(ConvertLengthToDimension(src.right)); + padding.bottom = CalcLength(ConvertLengthToDimension(src.bottom)); + return padding; +} + +std::vector ConvertToSection(const std::vector §ions) +{ + std::vector res; + for (size_t i = 0; i < sections.size(); i++) { + NG::WaterFlowSections::Section curSection; + curSection.itemsCount = sections[i].itemsCount; + curSection.crossCount = sections[i].crossCount; + curSection.columnsGap = ConvertLengthToDimension(sections[i].columnsGap); + curSection.rowsGap = ConvertLengthToDimension(sections[i].rowsGap); + curSection.margin = ConvertToMargin(sections[i].margin); + curSection.onGetItemMainSizeByIndex = sections[i].onGetItemMainSizeByIndex; + res.emplace_back(curSection); + } + return res; +} + +void SetWaterFlowFooterContent(ArkUINodeHandle node, ArkUINodeHandle footerPtr) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto* footerContentPtr = reinterpret_cast(footerPtr); + CHECK_NULL_VOID(footerContentPtr); + + auto footerContentNodePtr = FrameNodePeer::GetFrameNodeByPeer(footerContentPtr); + CHECK_NULL_VOID(footerContentNodePtr); + NG::WaterFlowModelStatic::SetFooter(frameNode, footerContentNodePtr); +} + +void SetWaterFlowSection(ArkUINodeHandle node, double start, double deleteCount, void* section, ArkUI_Int32 size) +{ + auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - Framework::AniWaterFlowModule::SetWaterFlowSection(env, ptr, fnObj); + CHECK_NULL_VOID(section); + + std::vector sections(static_cast(section), + static_cast(section) + size); + std::vector newSections = ConvertToSection(sections); + auto waterFlowSections = NG::WaterFlowModelStatic::GetOrCreateWaterFlowSections(frameNode); + CHECK_NULL_VOID(waterFlowSections); + waterFlowSections->ChangeData(start, deleteCount, newSections); } const ArkUIAniWaterFlowModifier* GetArkUIAniWaterFlowModifier() { static const ArkUIAniWaterFlowModifier impl = { - .setWaterFlowOptions = OHOS::Ace::NG::SetWaterFlowOptions, + .setWaterFlowSection = OHOS::Ace::NG::SetWaterFlowSection, + .setWaterFlowFooterContent = OHOS::Ace::NG::SetWaterFlowFooterContent, }; return &impl; }