1 /*
2 * Copyright (c) 2022 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 #include "bridge/declarative_frontend/jsview/models/list_model_impl.h"
17
18 #include <memory>
19
20 #include "base/memory/referenced.h"
21 #include "bridge/declarative_frontend/jsview/js_interactable_view.h"
22 #include "bridge/declarative_frontend/jsview/js_view_common_def.h"
23
24 namespace OHOS::Ace::Framework {
25
Create(bool isCreateArc)26 void ListModelImpl::Create(bool isCreateArc)
27 {
28 auto listComponent = AceType::MakeRefPtr<V2::ListComponent>();
29 ViewStackProcessor::GetInstance()->ClaimElementId(listComponent);
30 ViewStackProcessor::GetInstance()->Push(listComponent);
31 JSInteractableView::SetFocusable(true);
32 JSInteractableView::SetFocusNode(true);
33 }
34
SetSpace(const Dimension & space)35 void ListModelImpl::SetSpace(const Dimension& space)
36 {
37 JSViewSetProperty(&V2::ListComponent::SetSpace, space);
38 }
39
SetInitialIndex(int32_t initialIndex)40 void ListModelImpl::SetInitialIndex(int32_t initialIndex)
41 {
42 JSViewSetProperty(&V2::ListComponent::SetInitialIndex, initialIndex);
43 }
44
CreateScrollController()45 RefPtr<ScrollControllerBase> ListModelImpl::CreateScrollController()
46 {
47 return AceType::MakeRefPtr<V2::ListPositionController>();
48 }
49
SetScroller(RefPtr<ScrollControllerBase> scroller,RefPtr<ScrollProxy> proxy)50 void ListModelImpl::SetScroller(RefPtr<ScrollControllerBase> scroller, RefPtr<ScrollProxy> proxy)
51 {
52 auto listScroller = AceType::DynamicCast<V2::ListPositionController>(scroller);
53 JSViewSetProperty(&V2::ListComponent::SetScrollController, listScroller);
54 auto scrollBarProxy = AceType::DynamicCast<ScrollBarProxy>(proxy);
55 JSViewSetProperty(&V2::ListComponent::SetScrollBarProxy, scrollBarProxy);
56 }
57
SetListDirection(Axis axis)58 void ListModelImpl::SetListDirection(Axis axis)
59 {
60 JSViewSetProperty(&V2::ListComponent::SetDirection, axis);
61 }
62
SetScrollBar(DisplayMode scrollBar)63 void ListModelImpl::SetScrollBar(DisplayMode scrollBar)
64 {
65 JSViewSetProperty(&V2::ListComponent::SetScrollBar, scrollBar);
66 }
67
SetEdgeEffect(EdgeEffect edgeEffect,bool alwaysEnabled,EffectEdge effectEdge)68 void ListModelImpl::SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge)
69 {
70 JSViewSetProperty(&V2::ListComponent::SetEdgeEffect, edgeEffect);
71 }
72
SetEditMode(bool editMode)73 void ListModelImpl::SetEditMode(bool editMode)
74 {
75 JSViewSetProperty(&V2::ListComponent::SetEditMode, editMode);
76 }
77
SetListItemAlign(V2::ListItemAlign listItemAlign)78 void ListModelImpl::SetListItemAlign(V2::ListItemAlign listItemAlign)
79 {
80 JSViewSetProperty(&V2::ListComponent::SetListItemAlign, listItemAlign);
81 }
82
SetDivider(const V2::ItemDivider & divider)83 void ListModelImpl::SetDivider(const V2::ItemDivider& divider)
84 {
85 auto dividerPtr = std::make_unique<V2::ItemDivider>(divider);
86 JSViewSetProperty(&V2::ListComponent::SetItemDivider, std::move(dividerPtr));
87 }
88
SetChainAnimation(bool enableChainAnimation)89 void ListModelImpl::SetChainAnimation(bool enableChainAnimation)
90 {
91 JSViewSetProperty(&V2::ListComponent::SetChainAnimation, enableChainAnimation);
92 }
93
SetLanes(int32_t lanes)94 void ListModelImpl::SetLanes(int32_t lanes)
95 {
96 JSViewSetProperty(&V2::ListComponent::SetLanes, lanes);
97 }
98
SetLaneConstrain(const Dimension & laneMinLength,const Dimension & laneMaxLength)99 void ListModelImpl::SetLaneConstrain(const Dimension& laneMinLength, const Dimension& laneMaxLength)
100 {
101 auto component = AceType::DynamicCast<V2::ListComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
102 if (!component) {
103 LOGW("Failed to get ListComponent in view stack");
104 return;
105 }
106 component->SetLaneConstrain(laneMinLength, laneMaxLength);
107 }
108
SetCachedCount(int32_t cachedCount,bool show)109 void ListModelImpl::SetCachedCount(int32_t cachedCount, bool show)
110 {
111 JSViewSetProperty(&V2::ListComponent::SetCachedCount, cachedCount);
112 }
113
SetMultiSelectable(bool selectable)114 void ListModelImpl::SetMultiSelectable(bool selectable)
115 {
116 JSViewSetProperty(&V2::ListComponent::SetMultiSelectable, selectable);
117 }
118
SetHasWidth(bool hasWidth)119 void ListModelImpl::SetHasWidth(bool hasWidth)
120 {
121 JSViewSetProperty(&V2::ListComponent::SetHasWidth, hasWidth);
122 }
123
SetHasHeight(bool hasHeight)124 void ListModelImpl::SetHasHeight(bool hasHeight)
125 {
126 JSViewSetProperty(&V2::ListComponent::SetHasHeight, hasHeight);
127 }
128
SetSticky(V2::StickyStyle stickyStyle)129 void ListModelImpl::SetSticky(V2::StickyStyle stickyStyle)
130 {
131 JSViewSetProperty(&V2::ListComponent::SetSticky, stickyStyle);
132 }
133
SetContentStartOffset(float startOffset)134 void ListModelImpl::SetContentStartOffset(float startOffset)
135 {
136 JSViewSetProperty(&V2::ListComponent::SetContentStartOffset, startOffset);
137 }
138
SetContentEndOffset(float endOffset)139 void ListModelImpl::SetContentEndOffset(float endOffset)
140 {
141 JSViewSetProperty(&V2::ListComponent::SetContentEndOffset, endOffset);
142 }
143
SetOnScroll(OnScrollEvent && onScroll)144 void ListModelImpl::SetOnScroll(OnScrollEvent&& onScroll)
145 {
146 JSViewSetProperty(&V2::ListComponent::SetOnScroll, std::move(onScroll));
147 }
148
SetOnScrollBegin(OnScrollBeginEvent && onScrollBegin)149 void ListModelImpl::SetOnScrollBegin(OnScrollBeginEvent&& onScrollBegin)
150 {
151 JSViewSetProperty(&V2::ListComponent::SetOnScrollBegin, std::move(onScrollBegin));
152 }
153
SetOnScrollFrameBegin(OnScrollFrameBeginEvent && onScrollFrameBegin)154 void ListModelImpl::SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& onScrollFrameBegin)
155 {
156 }
157
SetOnScrollStop(OnScrollStopEvent && onScrollStop)158 void ListModelImpl::SetOnScrollStop(OnScrollStopEvent&& onScrollStop)
159 {
160 JSViewSetProperty(&V2::ListComponent::SetOnScrollStop, std::move(onScrollStop));
161 }
162
SetOnScrollIndex(OnScrollIndexEvent && onScrollIndex)163 void ListModelImpl::SetOnScrollIndex(OnScrollIndexEvent&& onScrollIndex)
164 {
165 JSViewSetProperty(&V2::ListComponent::SetOnScrollIndex, std::move(onScrollIndex));
166 }
167
SetOnReachStart(OnReachEvent && onReachStart)168 void ListModelImpl::SetOnReachStart(OnReachEvent&& onReachStart)
169 {
170 JSViewSetProperty(&V2::ListComponent::SetOnReachStart, std::move(onReachStart));
171 }
172
SetOnReachEnd(OnReachEvent && onReachEnd)173 void ListModelImpl::SetOnReachEnd(OnReachEvent&& onReachEnd)
174 {
175 JSViewSetProperty(&V2::ListComponent::SetOnReachEnd, std::move(onReachEnd));
176 }
177
SetOnItemDelete(OnItemDeleteEvent && onItemDelete)178 void ListModelImpl::SetOnItemDelete(OnItemDeleteEvent&& onItemDelete)
179 {
180 JSViewSetProperty(&V2::ListComponent::SetOnItemDelete, std::move(onItemDelete));
181 }
182
SetOnItemMove(OnItemMoveEvent && onItemMove)183 void ListModelImpl::SetOnItemMove(OnItemMoveEvent&& onItemMove)
184 {
185 JSViewSetProperty(&V2::ListComponent::SetOnItemMove, std::move(onItemMove));
186 }
187
SetOnItemDragStart(OnItemDragStartFunc && onItemDragStart)188 void ListModelImpl::SetOnItemDragStart(OnItemDragStartFunc&& onItemDragStart)
189 {
190 JSViewSetProperty(&V2::ListComponent::SetOnItemDragStartId, std::move(onItemDragStart));
191 }
192
SetOnItemDragEnter(OnItemDragEnterFunc && onItemDragEnter)193 void ListModelImpl::SetOnItemDragEnter(OnItemDragEnterFunc&& onItemDragEnter)
194 {
195 JSViewSetProperty(&V2::ListComponent::SetOnItemDragEnterId, std::move(onItemDragEnter));
196 }
197
SetOnItemDragMove(OnItemDragMoveFunc && onItemDragMove)198 void ListModelImpl::SetOnItemDragMove(OnItemDragMoveFunc&& onItemDragMove)
199 {
200 JSViewSetProperty(&V2::ListComponent::SetOnItemDragMoveId, std::move(onItemDragMove));
201 }
202
SetOnItemDragLeave(OnItemDragLeaveFunc && onItemDragLeave)203 void ListModelImpl::SetOnItemDragLeave(OnItemDragLeaveFunc&& onItemDragLeave)
204 {
205 JSViewSetProperty(&V2::ListComponent::SetOnItemDragLeaveId, std::move(onItemDragLeave));
206 }
207
SetOnItemDrop(OnItemDropFunc && onItemDrop)208 void ListModelImpl::SetOnItemDrop(OnItemDropFunc&& onItemDrop)
209 {
210 JSViewSetProperty(&V2::ListComponent::SetOnItemDropId, std::move(onItemDrop));
211 }
212
213 } // namespace OHOS::Ace::Framework
214