• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_LIST_LIST_ITEM_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_COMPONENT_H
18 
19 #include "base/utils/macros.h"
20 #include "core/animation/animation_pub.h"
21 #include "core/pipeline/base/constants.h"
22 #include "core/pipeline/base/element.h"
23 #include "core/pipeline/base/render_node.h"
24 #include "core/pipeline/base/sole_child_component.h"
25 
26 namespace OHOS::Ace {
27 
28 inline const Dimension DIVIDER_DEFAULT_HEIGHT = 1.0_vp;
29 inline constexpr int32_t LIST_ITEM_FLAG_FROM_CHILD = 2;
30 inline constexpr int32_t LIST_ITEM_FLAG_IN_RANGE = 4;
31 inline constexpr int32_t LIST_ITEM_FLAG_DYNAMIC = 8;
32 inline constexpr int32_t LIST_ITEM_OP_NONE = 0;
33 inline constexpr int32_t LIST_ITEM_OP_ADD = 1;
34 inline constexpr int32_t LIST_ITEM_OP_REMOVE = 2;
35 
36 enum class StickyMode {
37     NONE,
38     NORMAL,
39     OPACITY,
40 };
41 
42 class ACE_EXPORT ListItemComponent : public SoleChildComponent {
43     DECLARE_ACE_TYPE(ListItemComponent, SoleChildComponent);
44 
45 public:
46     ListItemComponent(const std::string& type, const RefPtr<Component>& child);
47     ~ListItemComponent() override = default;
48 
49     RefPtr<Element> CreateElement() override;
50     RefPtr<RenderNode> CreateRenderNode() override;
51 
GetType()52     const std::string& GetType() const
53     {
54         return type_;
55     }
56 
SetType(const std::string & type)57     void SetType(const std::string& type)
58     {
59         type_ = type;
60     }
61 
SetIndex(int32_t index)62     void SetIndex(int32_t index)
63     {
64         index_ = index;
65     }
66 
GetIndex()67     int32_t GetIndex() const
68     {
69         return index_;
70     }
71 
SetFlags(uint32_t flags)72     void SetFlags(uint32_t flags)
73     {
74         flags_ = flags;
75     }
76 
GetFlags()77     uint32_t GetFlags() const
78     {
79         return flags_;
80     }
81 
AddFlag(uint32_t flag)82     void AddFlag(uint32_t flag)
83     {
84         flags_ |= flag;
85     }
86 
RemoveFlag(uint32_t flag)87     void RemoveFlag(uint32_t flag)
88     {
89         flags_ &= ~flag;
90     }
91 
TestFlag(uint32_t flag)92     bool TestFlag(uint32_t flag) const
93     {
94         return (flags_ & flag);
95     }
96 
SetFocusAnimationColor(const Color & color)97     void SetFocusAnimationColor(const Color& color)
98     {
99         focusAnimationColor_ = color;
100     }
101 
GetFocusAnimationColor()102     const Color& GetFocusAnimationColor() const
103     {
104         return focusAnimationColor_;
105     }
106 
SetTopLeftRadius(const Radius & topLeftRadius)107     void SetTopLeftRadius(const Radius& topLeftRadius)
108     {
109         if (!topLeftRadius.IsValid()) {
110             LOGD("Invalid radius x:%{public}lf, y:%{public}lf", topLeftRadius.GetX().Value(),
111                 topLeftRadius.GetY().Value());
112             return;
113         }
114         topLeftRadius_ = topLeftRadius;
115         LOGD("[Focus] SetTopLeftRadius, radius: %{public}lf", topLeftRadius_.GetX().Value());
116     }
117 
SetTopRightRadius(const Radius & topRightRadius)118     void SetTopRightRadius(const Radius& topRightRadius)
119     {
120         if (!topRightRadius.IsValid()) {
121             LOGD("Invalid radius x:%{public}lf, y:%{public}lf", topRightRadius.GetX().Value(),
122                 topRightRadius.GetY().Value());
123             return;
124         }
125         topRightRadius_ = topRightRadius;
126     }
127 
SetBottomLeftRadius(const Radius & bottomLeftRadius)128     void SetBottomLeftRadius(const Radius& bottomLeftRadius)
129     {
130         if (!bottomLeftRadius.IsValid()) {
131             LOGD("Invalid radius x:%{public}f, y:%{public}f", bottomLeftRadius.GetX().Value(),
132                 bottomLeftRadius.GetY().Value());
133             return;
134         }
135         bottomLeftRadius_ = bottomLeftRadius;
136     }
137 
SetBottomRightRadius(const Radius & bottomRightRadius)138     void SetBottomRightRadius(const Radius& bottomRightRadius)
139     {
140         if (!bottomRightRadius.IsValid()) {
141             LOGD("Invalid radius x:%{public}f, y:%{public}f", bottomRightRadius.GetX().Value(),
142                 bottomRightRadius.GetY().Value());
143             return;
144         }
145         bottomRightRadius_ = bottomRightRadius;
146     }
147 
GetTopLeftRadius()148     const Radius& GetTopLeftRadius() const
149     {
150         return topLeftRadius_;
151     }
152 
GetTopRightRadius()153     const Radius& GetTopRightRadius() const
154     {
155         return topRightRadius_;
156     }
157 
GetBottomLeftRadius()158     const Radius& GetBottomLeftRadius() const
159     {
160         return bottomLeftRadius_;
161     }
162 
GetBottomRightRadius()163     const Radius& GetBottomRightRadius() const
164     {
165         return bottomRightRadius_;
166     }
167 
SetColumnSpan(int32_t columnSpan)168     void SetColumnSpan(int32_t columnSpan)
169     {
170         if (columnSpan <= 0) {
171             return;
172         }
173         columnSpan_ = columnSpan;
174     }
175 
GetColumnSpan()176     int32_t GetColumnSpan() const
177     {
178         return columnSpan_;
179     }
180 
SetClickEventId(const EventMarker & clickEventId)181     void SetClickEventId(const EventMarker& clickEventId)
182     {
183         clickEventId_ = clickEventId;
184     }
185 
GetClickEventId()186     const EventMarker& GetClickEventId() const
187     {
188         return clickEventId_;
189     }
190 
SetStickyEventId(const EventMarker & stickyEventId)191     void SetStickyEventId(const EventMarker& stickyEventId)
192     {
193         stickyEventId_ = stickyEventId;
194     }
195 
GetStickyEventId()196     const EventMarker& GetStickyEventId() const
197     {
198         return stickyEventId_;
199     }
200 
201     static RefPtr<ListItemComponent> GetListItem(const RefPtr<Component>& component);
202 
SetOperation(int32_t op)203     void SetOperation(int32_t op)
204     {
205         op_ = op;
206     }
207 
GetOperation()208     int32_t GetOperation() const
209     {
210         return op_;
211     }
212 
GetIndexKey()213     const std::string& GetIndexKey() const
214     {
215         return indexKey_;
216     }
217 
SetIndexKey(const std::string & indexKey)218     void SetIndexKey(const std::string& indexKey)
219     {
220         indexKey_ = indexKey;
221     }
222 
GetSticky()223     bool GetSticky() const
224     {
225         return sticky_;
226     }
227 
SetSticky(bool sticky)228     void SetSticky(bool sticky)
229     {
230         sticky_ = sticky;
231     }
232 
GetStickyMode()233     StickyMode GetStickyMode() const
234     {
235         return stickyMode_;
236     }
237 
SetStickyMode(StickyMode mode)238     void SetStickyMode(StickyMode mode)
239     {
240         stickyMode_ = mode;
241     }
242 
NeedVibrate()243     bool NeedVibrate() const
244     {
245         return needVibrate_;
246     }
247 
MarkNeedVibrate(bool needVibrate)248     void MarkNeedVibrate(bool needVibrate)
249     {
250         needVibrate_ = needVibrate;
251     }
252 
IsRotationVibrate()253     bool IsRotationVibrate() const
254     {
255         return rotationVibrate_;
256     }
257 
MarkNeedRotationVibrate(bool needVibrate)258     void MarkNeedRotationVibrate(bool needVibrate)
259     {
260         rotationVibrate_ = needVibrate;
261     }
262 
IsTitle()263     bool IsTitle() const
264     {
265         return isTitle_;
266     }
267 
MarkTitle(bool isTitle)268     void MarkTitle(bool isTitle)
269     {
270         isTitle_ = isTitle;
271     }
272 
GetSupportClick()273     bool GetSupportClick() const
274     {
275         return supportClick_;
276     }
277 
SetSupportClick(bool isClick)278     void SetSupportClick(bool isClick)
279     {
280         supportClick_ = isClick;
281     }
282 
GetSupportScale()283     bool GetSupportScale() const
284     {
285         return supportScale_;
286     }
287 
SetSupportScale(bool isScale)288     void SetSupportScale(bool isScale)
289     {
290         supportScale_ = isScale;
291     }
292 
GetSupportOpacity()293     bool GetSupportOpacity() const
294     {
295         return supportOpacity_;
296     }
297 
SetSupportOpacity(bool isOpacity)298     void SetSupportOpacity(bool isOpacity)
299     {
300         supportOpacity_ = isOpacity;
301     }
302 
GetPrimary()303     bool GetPrimary() const
304     {
305         return primary_;
306     }
307 
SetPrimary(bool primary)308     void SetPrimary(bool primary)
309     {
310         primary_ = primary;
311     }
312 
GetStickyRadius()313     const Dimension& GetStickyRadius() const
314     {
315         return stickyRadius_;
316     }
317 
SetStickyRadius(const Dimension & stickyRadius)318     void SetStickyRadius(const Dimension& stickyRadius)
319     {
320         stickyRadius_ = stickyRadius;
321     }
322 
NeedDivider()323     bool NeedDivider() const
324     {
325         return needDivider_;
326     }
327 
MarkNeedDivider(bool needDivider)328     void MarkNeedDivider(bool needDivider)
329     {
330         needDivider_ = needDivider;
331     }
332 
GetDividerOrigin()333     const Dimension& GetDividerOrigin() const
334     {
335         return dividerOrigin_;
336     }
337 
SetDividerOrigin(const Dimension & origin)338     void SetDividerOrigin(const Dimension& origin)
339     {
340         dividerOrigin_ = origin;
341     }
342 
GetDividerLength()343     const Dimension& GetDividerLength() const
344     {
345         return dividerLength_;
346     }
347 
SetDividerLength(const Dimension & length)348     void SetDividerLength(const Dimension& length)
349     {
350         dividerLength_ = length;
351     }
352 
GetDividerColor()353     const Color& GetDividerColor() const
354     {
355         return dividerColor_;
356     }
357 
SetDividerColor(const Color & color)358     void SetDividerColor(const Color& color)
359     {
360         dividerColor_ = color;
361     }
362 
GetDividerHeight()363     const Dimension& GetDividerHeight() const
364     {
365         return dividerHeight_;
366     }
367 
SetDividerHeight(const Dimension & dividerHeight)368     void SetDividerHeight(const Dimension& dividerHeight)
369     {
370         dividerHeight_ = dividerHeight;
371     }
372 
IsActive()373     bool IsActive() const
374     {
375         return isActive_;
376     }
377 
SetIsActive(bool isActive)378     void SetIsActive(bool isActive)
379     {
380         isActive_ = isActive;
381     }
382 
SetTransitionEffect(TransitionEffect transitionEffect)383     void SetTransitionEffect(TransitionEffect transitionEffect)
384     {
385         transitionEffect_ = transitionEffect;
386     }
387 
GetTransitionEffect()388     TransitionEffect GetTransitionEffect() const
389     {
390         return transitionEffect_;
391     }
392 
GetAlignSelf()393     FlexAlign GetAlignSelf() const
394     {
395         return alignSelf_;
396     }
397 
SetAlignSelf(FlexAlign alignSelf)398     void SetAlignSelf(FlexAlign alignSelf)
399     {
400         alignSelf_ = alignSelf;
401     }
402 
GetClickColor()403     const Color& GetClickColor() const
404     {
405         return clickColor_;
406     }
SetClickColor(const Color & clickColor)407     void SetClickColor(const Color& clickColor)
408     {
409         clickColor_ = clickColor;
410     }
411 
GetKey()412     int32_t GetKey() const
413     {
414         return key_;
415     }
416 
SetKey(int32_t key)417     void SetKey(int32_t key)
418     {
419         key_ = key;
420     }
421 
422 private:
423     int32_t index_ = -1; // invalid index
424     int32_t columnSpan_ = DEFAULT_COLUMN_SPAN;
425     uint32_t flags_ = 0;
426     int32_t op_ = LIST_ITEM_OP_NONE;
427     FlexAlign alignSelf_ = FlexAlign::AUTO;
428 
429     std::string type_;
430     Color focusAnimationColor_ = Color::WHITE;
431     Radius topLeftRadius_;
432     Radius topRightRadius_;
433     Radius bottomLeftRadius_;
434     Radius bottomRightRadius_;
435     std::string indexKey_;
436     int32_t key_ = -1;
437     bool needVibrate_ = true;
438     bool rotationVibrate_ = false;
439     bool supportScale_ = true;
440     bool supportOpacity_ = false;
441     bool supportClick_ = true;
442     bool sticky_ = false;
443     bool isTitle_ = false;
444     StickyMode stickyMode_ = StickyMode::NONE;
445     Dimension stickyRadius_;
446     bool primary_ = false;
447     bool needDivider_ = false;
448     bool isActive_ = false;
449     Dimension dividerOrigin_;
450     Dimension dividerLength_;
451     Dimension dividerHeight_ = DIVIDER_DEFAULT_HEIGHT;
452     Color dividerColor_;
453     Color clickColor_ = Color::TRANSPARENT;
454 
455     EventMarker clickEventId_;
456     EventMarker stickyEventId_;
457 
458     TransitionEffect transitionEffect_ = TransitionEffect::NONE;
459 };
460 
461 } // namespace OHOS::Ace
462 
463 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_COMPONENT_H
464