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