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 c3aaac5d4be19c37ba112eeeaf50df0f6e5b7735..552327012e6feb1802a25fb13b3fc209050f4570 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 @@ -318,7 +318,7 @@ export interface WaterFlowAttribute extends ScrollableCommonMethod { nestedScroll(value: NestedScrollOptions | undefined): this { return this; } enableScrollInteraction(value: boolean | undefined): this { return this; } friction(value: number | Resource | undefined): this { return this; } - cachedCount(count: number | undefined, show?: boolean): this { return this; } + cachedCount(count: number | undefined, show: boolean | undefined): this { return this; } cachedCount(value: number | undefined): this { return this; } onReachStart(value: (() => void) | undefined): this { return this; } onReachEnd(value: (() => void) | undefined): this { return this; } @@ -375,7 +375,7 @@ export class ArkWaterFlowStyle extends ArkScrollableCommonMethodStyle implements public friction(value: number | Resource | undefined): this { return this } - public cachedCount(count: number | undefined, show?: boolean): this { + public cachedCount(count: number | undefined, show: boolean | undefined): this { return this } public cachedCount(value: number | undefined): this { @@ -484,15 +484,10 @@ export class ArkWaterFlowComponent extends ArkScrollableCommonMethodComponent im } return this } - public cachedCount(count: number | undefined, show?: boolean): this { + public cachedCount(count: number | undefined, show: boolean | undefined): this { if (this.checkPriority("cachedCount")) { const count_type = runtimeType(count) const show_type = runtimeType(show) - if (((RuntimeType.NUMBER == count_type) || (RuntimeType.UNDEFINED == count_type)) && (RuntimeType.UNDEFINED == show_type)) { - const value_casted = count as (number | undefined) - this.getPeer()?.cachedCount0Attribute(value_casted) - return this - } if (((RuntimeType.NUMBER == count_type) || (RuntimeType.UNDEFINED == count_type)) && ((RuntimeType.BOOLEAN == show_type) || (RuntimeType.UNDEFINED == show_type))) { const count_casted = count as (number | undefined) const show_casted = show as (boolean | undefined) diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_model_static.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_model_static.cpp index 8d310eccf11050683701753bf867dc2786dd5e64..7a0ffd48cec9e6d406d13cbe96749f05d431717a 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_model_static.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_model_static.cpp @@ -85,7 +85,7 @@ void ScrollableModelStatic::SetOnWillScroll(FrameNode* frameNode, OnWillScrollEv void ScrollableModelStatic::SetOnDidScroll(FrameNode* frameNode, OnScrollEvent&& onScroll) { CHECK_NULL_VOID(frameNode); - auto eventHub = frameNode->GetEventHub(); + auto eventHub = frameNode->GetOrCreateEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnDidScroll(std::move(onScroll)); } 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 5c755c032bd79347d8febdd4afd2aa8f150fe412..4e1f3085f8ddf528c646831c10d3e0dcd5888114 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 @@ -24,6 +24,7 @@ namespace OHOS::Ace::NG { const auto DEFAULT_CONSTRAINT_SIZE = CalcLength(0.0_vp); +const auto DEFAULT_CONSTRAINT_UNDEFINED_SIZE = CalcLength(-1.0_vp); RefPtr WaterFlowModelStatic::CreateFrameNode(int32_t nodeId) { @@ -82,10 +83,15 @@ void WaterFlowModelStatic::SetOnScrollFrameBegin(FrameNode* frameNode, OnScrollF ScrollableModelNG::SetOnScrollFrameBegin(frameNode, std::move(ScrollFrameBegin)); } +void WaterFlowModelStatic::SetOnDidScroll(FrameNode* frameNode, OnScrollEvent&& onScroll) +{ + ScrollableModelNG::SetOnDidScroll(frameNode, std::move(onScroll)); +} + void WaterFlowModelStatic::SetOnScrollIndex(FrameNode* frameNode, ScrollIndexFunc&& onScrollIndex) { CHECK_NULL_VOID(frameNode); - auto eventHub = frameNode->GetEventHub(); + auto eventHub = frameNode->GetOrCreateEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnScrollIndex(std::move(onScrollIndex)); } @@ -100,6 +106,21 @@ void WaterFlowModelStatic::SetCachedCount(FrameNode* frameNode, const std::optio } } +void WaterFlowModelStatic::SetCachedCount( + FrameNode* frameNode, const std::optional& count, const std::optional& show) +{ + if (count.has_value() && count.value() >= 0) { + ACE_UPDATE_NODE_LAYOUT_PROPERTY(WaterFlowLayoutProperty, CachedCount, count.value(), frameNode); + } else { + ACE_RESET_NODE_LAYOUT_PROPERTY(WaterFlowLayoutProperty, CachedCount, frameNode); + } + if (show.has_value()) { + ACE_UPDATE_NODE_LAYOUT_PROPERTY(WaterFlowLayoutProperty, ShowCachedItems, show.value(), frameNode); + } else { + ACE_RESET_NODE_LAYOUT_PROPERTY(WaterFlowLayoutProperty, ShowCachedItems, frameNode); + } +} + void WaterFlowModelStatic::SetShowCached(FrameNode* frameNode, bool show) { ACE_UPDATE_NODE_LAYOUT_PROPERTY(WaterFlowLayoutProperty, ShowCachedItems, show, frameNode); @@ -165,6 +186,15 @@ void WaterFlowModelStatic::SetRowsGap(FrameNode* frameNode, const std::optional< } } +void WaterFlowModelStatic::SetItemConstraintSizeUndefined(FrameNode* frameNode) +{ + CHECK_NULL_VOID(frameNode); + auto layoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + layoutProperty->UpdateItemMinSize(CalcSize(DEFAULT_CONSTRAINT_UNDEFINED_SIZE, DEFAULT_CONSTRAINT_UNDEFINED_SIZE)); + layoutProperty->UpdateItemMaxSize(CalcSize(DEFAULT_CONSTRAINT_UNDEFINED_SIZE, DEFAULT_CONSTRAINT_UNDEFINED_SIZE)); +} + void WaterFlowModelStatic::SetItemMinWidth(FrameNode* frameNode, const std::optional& minWidth) { CHECK_NULL_VOID(frameNode); diff --git a/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.h b/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.h index e699164fb858619ff28471ce4c63b4e0a42cfd08..643eb2c17178ac41935939ab43f55d94f557b141 100644 --- a/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.h +++ b/frameworks/core/components_ng/pattern/waterflow/water_flow_model_static.h @@ -31,6 +31,7 @@ public: static void SetScrollEnabled(FrameNode* frameNode, bool scrollEnabled); static void SetColumnsGap(FrameNode* frameNode, const std::optional& value); static void SetRowsGap(FrameNode* frameNode, const std::optional& value); + static void SetItemConstraintSizeUndefined(FrameNode* frameNode); static void SetItemMinWidth(FrameNode* frameNode, const std::optional& minWidth); static void SetItemMaxWidth(FrameNode* frameNode, const std::optional& maxWidth); static void SetItemMinHeight(FrameNode* frameNode, const std::optional& minHeight); @@ -39,10 +40,13 @@ public: static void SetNestedScroll(FrameNode* frameNode, const NestedScrollOptions& nestedOpt); static void SetFriction(FrameNode* frameNode, const std::optional& friction); static void SetCachedCount(FrameNode* frameNode, const std::optional& value); + static void SetCachedCount( + FrameNode* frameNode, const std::optional& count, const std::optional& show); static void SetShowCached(FrameNode* frameNode, bool show); static RefPtr GetOrCreateWaterFlowSections(FrameNode* frameNode); static void ResetSections(FrameNode* frameNode); static void SetOnScrollFrameBegin(FrameNode* frameNode, OnScrollFrameBeginEvent&& ScrollFrameBegin); + static void SetOnDidScroll(FrameNode* frameNode, OnScrollEvent&& onScroll); static void SetOnScrollIndex(FrameNode* frameNode, ScrollIndexFunc&& onScrollIndex); static void SetOnReachStart(FrameNode* frameNode, OnReachEvent&& onReachStart); static void SetOnReachEnd(FrameNode* frameNode, OnReachEvent&& onReachEnd); diff --git a/frameworks/core/interfaces/native/implementation/grid_item_modifier.cpp b/frameworks/core/interfaces/native/implementation/grid_item_modifier.cpp index 930fb5018be76f73f6bb21f5fb8907024282c8e0..810b06c9aaa29bdc722312b0c88fd6d512782684 100644 --- a/frameworks/core/interfaces/native/implementation/grid_item_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/grid_item_modifier.cpp @@ -41,6 +41,7 @@ inline void AssignCast(std::optional& dst, const Ark_GridItemOpti } // namespace OHOS::Ace::NG::Converter namespace OHOS::Ace::NG::GeneratedModifier { +const int32_t DEFAULT_GRID_ITEM_UNDEFINED = -1; namespace GridItemModifier { Ark_NativePointer ConstructImpl(Ark_Int32 id, Ark_Int32 flags) @@ -72,7 +73,7 @@ void RowStartImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + GridItemModelStatic::SetRowStart(frameNode, DEFAULT_GRID_ITEM_UNDEFINED); return; } GridItemModelStatic::SetRowStart(frameNode, *convValue); @@ -84,7 +85,7 @@ void RowEndImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + GridItemModelStatic::SetRowEnd(frameNode, DEFAULT_GRID_ITEM_UNDEFINED); return; } GridItemModelStatic::SetRowEnd(frameNode, *convValue); @@ -96,7 +97,7 @@ void ColumnStartImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + GridItemModelStatic::SetColumnStart(frameNode, DEFAULT_GRID_ITEM_UNDEFINED); return; } GridItemModelStatic::SetColumnStart(frameNode, *convValue); @@ -108,7 +109,7 @@ void ColumnEndImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + GridItemModelStatic::SetColumnEnd(frameNode, DEFAULT_GRID_ITEM_UNDEFINED); return; } GridItemModelStatic::SetColumnEnd(frameNode, *convValue); @@ -132,7 +133,7 @@ void SelectableImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + GridItemModelStatic::SetSelectable(frameNode, true); return; } GridItemModelStatic::SetSelectable(frameNode, *convValue); @@ -156,7 +157,7 @@ void OnSelectImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); if (!optValue) { - // TODO: Reset value + GridItemModelStatic::SetOnSelect(frameNode, nullptr); return; } auto onSelect = [arkCallback = CallbackHelper(*optValue)](bool isSelected) { diff --git a/frameworks/core/interfaces/native/implementation/grid_modifier.cpp b/frameworks/core/interfaces/native/implementation/grid_modifier.cpp index ff30c956c1b5ac75b6f34c7142c9696a6c98863a..baa70e625b43757010b6482893eb52005897b774 100644 --- a/frameworks/core/interfaces/native/implementation/grid_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/grid_modifier.cpp @@ -655,6 +655,7 @@ void OnDidScrollImpl(Ark_NativePointer node, CHECK_NULL_VOID(value); auto callValue = Converter::OptConvert(*value); if (!callValue.has_value()) { + ScrollableModelStatic::SetOnDidScroll(frameNode, nullptr); return; } auto onDidScroll = [arkCallback = CallbackHelper(callValue.value())]( diff --git a/frameworks/core/interfaces/native/implementation/lazy_grid_layout_modifier.cpp b/frameworks/core/interfaces/native/implementation/lazy_grid_layout_modifier.cpp index 74736c66825e6663092af664b12002bcbff2c05b..6a4b91cbd933067c18276680edca777e6a2657bd 100644 --- a/frameworks/core/interfaces/native/implementation/lazy_grid_layout_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/lazy_grid_layout_modifier.cpp @@ -38,6 +38,10 @@ void RowsGapImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); Validator::ValidateNonNegative(convValue); + if (!convValue) { + CalcDimension colGap{0.0}; + convValue = colGap; + } LazyGridLayoutModelStatic::SetRowGap(frameNode, convValue); } void ColumnsGapImpl(Ark_NativePointer node, @@ -47,6 +51,10 @@ void ColumnsGapImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); Validator::ValidateNonNegative(convValue); + if (!convValue) { + CalcDimension colGap{0.0}; + convValue = colGap; + } LazyGridLayoutModelStatic::SetColumnGap(frameNode, convValue); } } // LazyGridLayoutAttributeModifier diff --git a/frameworks/core/interfaces/native/implementation/water_flow_modifier.cpp b/frameworks/core/interfaces/native/implementation/water_flow_modifier.cpp index b9b7f7b851658971b9b53adc23a07b935e7007a2..08d713c86237db59fb87bc10fa87983131c7a22f 100644 --- a/frameworks/core/interfaces/native/implementation/water_flow_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/water_flow_modifier.cpp @@ -107,7 +107,7 @@ void ColumnsTemplateImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + WaterFlowModelStatic::SetColumnsTemplate(frameNode, "1fr"); return; } WaterFlowModelStatic::SetColumnsTemplate(frameNode, *convValue); @@ -119,7 +119,7 @@ void ItemConstraintSizeImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); if (!optValue) { - // TODO: Reset value + WaterFlowModelStatic::SetItemConstraintSizeUndefined(frameNode); return; } auto minWidth = Converter::OptConvert(optValue->minWidth); @@ -142,7 +142,7 @@ void RowsTemplateImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + WaterFlowModelStatic::SetRowsTemplate(frameNode, "1fr"); return; } WaterFlowModelStatic::SetRowsTemplate(frameNode, *convValue); @@ -155,6 +155,10 @@ void ColumnsGapImpl(Ark_NativePointer node, auto convValue = Converter::OptConvert(*value); Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); + if (!convValue) { + CalcDimension colGap{0.0}; + convValue = colGap; + } WaterFlowModelStatic::SetColumnsGap(frameNode, convValue); } void RowsGapImpl(Ark_NativePointer node, @@ -165,6 +169,10 @@ void RowsGapImpl(Ark_NativePointer node, auto convValue = Converter::OptConvert(*value); Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); + if (!convValue) { + CalcDimension colGap{0.0}; + convValue = colGap; + } WaterFlowModelStatic::SetRowsGap(frameNode, convValue); } void LayoutDirectionImpl(Ark_NativePointer node, @@ -173,6 +181,9 @@ void LayoutDirectionImpl(Ark_NativePointer node, auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); + if (!convValue) { + WaterFlowModelStatic::SetLayoutDirection(frameNode, FlexDirection::COLUMN); + } WaterFlowModelStatic::SetLayoutDirection(frameNode, convValue); } void NestedScrollImpl(Ark_NativePointer node, @@ -181,10 +192,6 @@ void NestedScrollImpl(Ark_NativePointer node, auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); - if (!optValue) { - // TODO: Reset value - return; - } auto forward = Converter::OptConvert(optValue->scrollForward); auto backward = Converter::OptConvert(optValue->scrollBackward); NestedScrollOptions options = {.forward = forward ? forward.value() : NestedScrollMode::SELF_ONLY, @@ -198,7 +205,7 @@ void EnableScrollInteractionImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvert(*value); if (!convValue) { - // TODO: Reset value + WaterFlowModelStatic::SetScrollEnabled(frameNode, true); return; } WaterFlowModelStatic::SetScrollEnabled(frameNode, *convValue); @@ -227,6 +234,9 @@ void CachedCount1Impl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + auto countValue = Converter::OptConvert(*count); + auto showValue = Converter::OptConvert(*show); + WaterFlowModelStatic::SetCachedCount(frameNode, countValue, showValue); } void OnReachStartImpl(Ark_NativePointer node, const Opt_Callback_Void* value) @@ -235,7 +245,7 @@ void OnReachStartImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); if (!optValue) { - // TODO: Reset value + WaterFlowModelStatic::SetOnReachStart(frameNode, nullptr); return; } auto onReachStart = [arkCallback = CallbackHelper(*optValue)]() -> void { @@ -250,7 +260,7 @@ void OnReachEndImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); if (!optValue) { - // TODO: Reset value + WaterFlowModelStatic::SetOnReachEnd(frameNode, nullptr); return; } auto onReachEnd = [arkCallback = CallbackHelper(*optValue)]() -> void { @@ -265,7 +275,7 @@ void OnScrollFrameBeginImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); if (!optValue) { - // TODO: Reset value + WaterFlowModelStatic::SetOnScrollFrameBegin(frameNode, nullptr); return; } auto onScrollFrameEvent = [callback = CallbackHelper(*optValue)]( @@ -288,11 +298,13 @@ void OnScrollIndexImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto optValue = Converter::GetOptPtr(value); if (!optValue) { - // TODO: Reset value + WaterFlowModelStatic::SetOnScrollIndex(frameNode, nullptr); return; } auto onScrollIndex = [arkCallback = CallbackHelper(*optValue)](const int32_t first, const int32_t last) { - arkCallback.Invoke(Converter::ArkValue(first), Converter::ArkValue(last)); + auto arkFirst = Converter::ArkValue(first); + auto arkLast = Converter::ArkValue(last); + arkCallback.Invoke(arkFirst, arkLast); }; WaterFlowModelStatic::SetOnScrollIndex(frameNode, std::move(onScrollIndex));