1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_MODEL_NG_H
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/pattern/list/list_model.h"
20 #include "core/components_v2/list/list_properties.h"
21 
22 namespace OHOS::Ace::NG {
23 
24 class ACE_EXPORT ListModelNG : public ListModel {
25 public:
26     void Create() override;
27     void SetSpace(const Dimension& space) override;
28     void SetInitialIndex(int32_t initialIndex) override;
29     RefPtr<ScrollControllerBase> CreateScrollController() override;
30     void SetScroller(RefPtr<ScrollControllerBase> scroller, RefPtr<ScrollProxy> proxy) override;
31     void SetListDirection(Axis axis) override;
32     void SetScrollBar(DisplayMode scrollBar) override;
33     void SetScrollBarColor(const std::string& value) override;
34     void SetScrollBarWidth(const std::string& value) override;
35     void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled) override;
36     void SetEditMode(bool editMode) override;
37     void SetDivider(const V2::ItemDivider& divider) override;
38     void SetChainAnimation(bool enableChainAnimation) override;
39     void SetChainAnimationOptions(const ChainAnimationOptions& options) override;
40     void SetLanes(int32_t lanes) override;
41     void SetLaneConstrain(const Dimension& laneMinLength, const Dimension& laneMaxLength) override;
42     void SetLaneMinLength(const Dimension& laneMinLength) override;
43     void SetLaneMaxLength(const Dimension& laneMaxLength) override;
44     void SetLaneGutter(const Dimension& laneGutter) override;
45     void SetListItemAlign(V2::ListItemAlign listItemAlign) override;
46     void SetCachedCount(int32_t cachedCount, bool show = false) override;
47     void SetMultiSelectable(bool selectable) override;
SetHasWidth(bool hasWidth)48     void SetHasWidth(bool hasWidth) override {}
SetHasHeight(bool hasHeight)49     void SetHasHeight(bool hasHeight) override {}
50     void SetSticky(V2::StickyStyle stickyStyle) override;
51     void SetContentStartOffset(float startOffset) override;
52     void SetContentEndOffset(float endOffset) override;
53     void SetScrollSnapAlign(V2::ScrollSnapAlign scrollSnapAlign) override;
54     void SetNestedScroll(const NestedScrollOptions& nestedOpt) override;
55     void SetScrollEnabled(bool scrollEnabled) override;
56     void SetFriction(double friction) override;
57     void SetMaintainVisibleContentPosition(bool enabled) override;
58     void SetOnScroll(OnScrollEvent&& onScroll) override;
59     void SetOnScrollBegin(OnScrollBeginEvent&& onScrollBegin) override;
60     void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& onScrollFrameBegin) override;
61     void SetOnScrollStart(OnScrollStartEvent&& onScrollStart) override;
62     void SetOnScrollStop(OnScrollStopEvent&& onScrollStop) override;
63     void SetOnScrollIndex(OnScrollIndexEvent&& onScrollIndex) override;
64     void SetOnScrollVisibleContentChange(OnScrollVisibleContentChangeEvent&& onScrollVisibleContentChange) override;
65     void SetOnReachStart(OnReachEvent&& onReachStart) override;
66     void SetOnReachEnd(OnReachEvent&& onReachEnd) override;
SetOnItemDelete(OnItemDeleteEvent && onItemDelete)67     void SetOnItemDelete(OnItemDeleteEvent&& onItemDelete) override {}
68     void SetOnItemMove(OnItemMoveEvent&& onItemMove) override;
69     void SetOnItemDragStart(OnItemDragStartFunc&& onItemDragStart) override;
70     void SetOnItemDragEnter(OnItemDragEnterFunc&& onItemDragEnter) override;
71     void SetOnItemDragLeave(OnItemDragLeaveFunc&& onItemDragLeave) override;
72     void SetOnItemDragMove(OnItemDragMoveFunc&& onItemDragMove) override;
73     void SetOnItemDrop(OnItemDropFunc&& onItemDrop) override;
74     RefPtr<ListChildrenMainSize> GetOrCreateListChildrenMainSize() override;
75 
76     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId);
77     static RefPtr<ScrollControllerBase> GetOrCreateController(FrameNode* frameNode);
78     static void ScrollToEdge(FrameNode* frameNode, ScrollEdgeType scrollEdgeType, bool smooth);
79     static void SetInitialIndex(FrameNode* frameNode, int32_t initialIndex);
80     static void SetEditMode(FrameNode* frameNode, bool editMode);
81     static void SetMultiSelectable(FrameNode* frameNode, bool selectable);
82     static void SetChainAnimation(FrameNode* frameNode, bool chainAnimation);
83     static void SetCachedCount(FrameNode* frameNode, int32_t cachedCount);
84     static void SetShowCached(FrameNode* frameNode, bool show);
85     static int32_t GetCachedCount(FrameNode* frameNode);
86     static bool GetShowCached(FrameNode* frameNode);
87     static int32_t GetScrollEnabled(FrameNode* frameNode);
88     static void SetScrollEnabled(FrameNode* frameNode, bool enableScrollInteraction);
89     static int32_t GetSticky(FrameNode* frameNode);
90     static void SetSticky(FrameNode* frameNode, int32_t stickyStyle);
91     static void SetEdgeEffect(FrameNode* frameNode, int32_t edgeEffect, bool alwaysEnabled);
92     static int32_t GetListDirection(FrameNode* frameNode);
93     static void SetListDirection(FrameNode* frameNode, int32_t axis);
94     static float GetListFriction(FrameNode* frameNode);
95     static void SetListFriction(FrameNode* frameNode, double friction);
96     static void SetListMaintainVisibleContentPosition(FrameNode* frameNode, bool enabled);
97     static void SetListNestedScroll(FrameNode* frameNode, const NestedScrollOptions& nestedOpt);
98     static int32_t GetListScrollBar(FrameNode* frameNode);
99     static void SetListScrollBar(FrameNode* frameNode, int32_t barState);
100     static float GetScrollBarWidth(FrameNode* frameNode);
101     static void SetListScrollBarWidth(FrameNode* frameNode, const std::string& value);
102     static uint32_t GetScrollBarColor(FrameNode* frameNode);
103     static void SetListScrollBarColor(FrameNode* frameNode, const std::string& value);
104     static void SetFlingSpeedLimit(FrameNode* frameNode, double maxSpeed);
105     static void SetLanes(FrameNode* frameNode, int32_t lanes);
106     static void SetLaneConstrain(FrameNode* frameNode, const Dimension& laneMinLength, const Dimension& laneMaxLength);
107     static void SetLaneMinLength(FrameNode* frameNode, const Dimension& laneMinLength);
108     static void SetLaneMaxLength(FrameNode* frameNode, const Dimension& laneMaxLength);
109     static void SetLaneGutter(FrameNode* frameNode, const Dimension& laneGutter);
110     static int32_t GetListItemAlign(FrameNode* frameNode);
111     static void SetListItemAlign(FrameNode* frameNode, V2::ListItemAlign listItemAlign);
112     static float GetListSpace(FrameNode* frameNode);
113     static void SetListSpace(FrameNode* frameNode, const Dimension& space);
114     static int32_t GetEdgeEffectAlways(FrameNode* frameNode);
115     static void SetScrollSnapAlign(FrameNode* frameNode, V2::ScrollSnapAlign scrollSnapAlign);
116     static void SetContentStartOffset(FrameNode* frameNode, float startOffset);
117     static void SetContentEndOffset(FrameNode* frameNode, float endOffset);
118     static void SetDivider(FrameNode* frameNode, const V2::ItemDivider& divider);
119     static void SetChainAnimationOptions(FrameNode* frameNode, const ChainAnimationOptions& options);
120     static int32_t GetEdgeEffect(FrameNode* frameNode);
121     static void SetOnScroll(FrameNode* frameNode, OnScrollEvent&& onScroll);
122     static void SetOnScrollFrameBegin(FrameNode* frameNode, OnScrollFrameBeginEvent&& onScrollFrameBegin);
123     static void SetOnScrollStart(FrameNode* frameNode, OnScrollStartEvent&& onScrollStart);
124     static void SetOnScrollStop(FrameNode* frameNode, OnScrollStopEvent&& onScrollStop);
125     static void SetOnScrollIndex(FrameNode* frameNode, OnScrollIndexEvent&& onScrollIndex);
126     static NestedScrollOptions GetListNestedScroll(FrameNode* frameNode);
127     DisplayMode GetDisplayMode() const override;
128     static void SetScrollToIndex(FrameNode* frameNode, int32_t index, int32_t animation, int32_t alignment);
129     static void SetScrollBy(FrameNode* frameNode, double x, double y);
130     static void SetOnReachStart(FrameNode* frameNode, OnReachEvent&& onReachStart);
131     static void SetOnReachEnd(FrameNode* frameNode, OnReachEvent&& onReachEnd);
132     static void SetListChildrenMainSize(
133         FrameNode* frameNode, float defaultSize, const std::vector<float>& mainSize);
134     static void ResetListChildrenMainSize(FrameNode* frameNode);
135     static int32_t GetInitialIndex(FrameNode* frameNode);
136     static V2::ItemDivider GetDivider(FrameNode* frameNode);
137     static void SetScroller(FrameNode* frameNode, RefPtr<ScrollControllerBase> scroller, RefPtr<ScrollProxy> proxy);
138     static void SetOnScrollVisibleContentChange(
139         FrameNode* frameNode, OnScrollVisibleContentChangeEvent&& onScrollVisibleContentChange);
140     static void SetOnItemMove(FrameNode* frameNode, OnItemMoveEvent&& onItemMove);
141     static void SetOnItemDragStart(FrameNode* frameNode, OnItemDragStartFunc&& onItemDragStart);
142     static void SetOnItemDragEnter(FrameNode* frameNode, OnItemDragEnterFunc&& onItemDragEnter);
143     static void SetOnItemDragLeave(FrameNode* frameNode, OnItemDragLeaveFunc&& onItemDragLeave);
144     static void SetOnItemDragMove(FrameNode* frameNode, OnItemDragMoveFunc&& onItemDragMove);
145     static void SetOnItemDrop(FrameNode* frameNode, OnItemDropFunc&& onItemDrop);
146 private:
147     void AddDragFrameNodeToManager() const;
148     static void AddDragFrameNodeToManager(FrameNode* frameNode);
149 };
150 
151 } // namespace OHOS::Ace::NG
152 
153 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_MODEL_NG_H
154