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 return; 111 } 112 topLeftRadius_ = topLeftRadius; 113 } 114 SetTopRightRadius(const Radius & topRightRadius)115 void SetTopRightRadius(const Radius& topRightRadius) 116 { 117 if (!topRightRadius.IsValid()) { 118 return; 119 } 120 topRightRadius_ = topRightRadius; 121 } 122 SetBottomLeftRadius(const Radius & bottomLeftRadius)123 void SetBottomLeftRadius(const Radius& bottomLeftRadius) 124 { 125 if (!bottomLeftRadius.IsValid()) { 126 return; 127 } 128 bottomLeftRadius_ = bottomLeftRadius; 129 } 130 SetBottomRightRadius(const Radius & bottomRightRadius)131 void SetBottomRightRadius(const Radius& bottomRightRadius) 132 { 133 if (!bottomRightRadius.IsValid()) { 134 return; 135 } 136 bottomRightRadius_ = bottomRightRadius; 137 } 138 GetTopLeftRadius()139 const Radius& GetTopLeftRadius() const 140 { 141 return topLeftRadius_; 142 } 143 GetTopRightRadius()144 const Radius& GetTopRightRadius() const 145 { 146 return topRightRadius_; 147 } 148 GetBottomLeftRadius()149 const Radius& GetBottomLeftRadius() const 150 { 151 return bottomLeftRadius_; 152 } 153 GetBottomRightRadius()154 const Radius& GetBottomRightRadius() const 155 { 156 return bottomRightRadius_; 157 } 158 SetColumnSpan(int32_t columnSpan)159 void SetColumnSpan(int32_t columnSpan) 160 { 161 if (columnSpan <= 0) { 162 return; 163 } 164 columnSpan_ = columnSpan; 165 } 166 GetColumnSpan()167 int32_t GetColumnSpan() const 168 { 169 return columnSpan_; 170 } 171 SetClickEventId(const EventMarker & clickEventId)172 void SetClickEventId(const EventMarker& clickEventId) 173 { 174 clickEventId_ = clickEventId; 175 } 176 GetClickEventId()177 const EventMarker& GetClickEventId() const 178 { 179 return clickEventId_; 180 } 181 SetStickyEventId(const EventMarker & stickyEventId)182 void SetStickyEventId(const EventMarker& stickyEventId) 183 { 184 stickyEventId_ = stickyEventId; 185 } 186 GetStickyEventId()187 const EventMarker& GetStickyEventId() const 188 { 189 return stickyEventId_; 190 } 191 192 static RefPtr<ListItemComponent> GetListItem(const RefPtr<Component>& component); 193 SetOperation(int32_t op)194 void SetOperation(int32_t op) 195 { 196 op_ = op; 197 } 198 GetOperation()199 int32_t GetOperation() const 200 { 201 return op_; 202 } 203 GetIndexKey()204 const std::string& GetIndexKey() const 205 { 206 return indexKey_; 207 } 208 SetIndexKey(const std::string & indexKey)209 void SetIndexKey(const std::string& indexKey) 210 { 211 indexKey_ = indexKey; 212 } 213 GetSticky()214 bool GetSticky() const 215 { 216 return sticky_; 217 } 218 SetSticky(bool sticky)219 void SetSticky(bool sticky) 220 { 221 sticky_ = sticky; 222 } 223 GetStickyMode()224 StickyMode GetStickyMode() const 225 { 226 return stickyMode_; 227 } 228 SetStickyMode(StickyMode mode)229 void SetStickyMode(StickyMode mode) 230 { 231 stickyMode_ = mode; 232 } 233 NeedVibrate()234 bool NeedVibrate() const 235 { 236 return needVibrate_; 237 } 238 MarkNeedVibrate(bool needVibrate)239 void MarkNeedVibrate(bool needVibrate) 240 { 241 needVibrate_ = needVibrate; 242 } 243 IsRotationVibrate()244 bool IsRotationVibrate() const 245 { 246 return rotationVibrate_; 247 } 248 MarkNeedRotationVibrate(bool needVibrate)249 void MarkNeedRotationVibrate(bool needVibrate) 250 { 251 rotationVibrate_ = needVibrate; 252 } 253 IsTitle()254 bool IsTitle() const 255 { 256 return isTitle_; 257 } 258 MarkTitle(bool isTitle)259 void MarkTitle(bool isTitle) 260 { 261 isTitle_ = isTitle; 262 } 263 GetSupportClick()264 bool GetSupportClick() const 265 { 266 return supportClick_; 267 } 268 SetSupportClick(bool isClick)269 void SetSupportClick(bool isClick) 270 { 271 supportClick_ = isClick; 272 } 273 GetSupportScale()274 bool GetSupportScale() const 275 { 276 return supportScale_; 277 } 278 SetSupportScale(bool isScale)279 void SetSupportScale(bool isScale) 280 { 281 supportScale_ = isScale; 282 } 283 GetSupportOpacity()284 bool GetSupportOpacity() const 285 { 286 return supportOpacity_; 287 } 288 SetSupportOpacity(bool isOpacity)289 void SetSupportOpacity(bool isOpacity) 290 { 291 supportOpacity_ = isOpacity; 292 } 293 GetPrimary()294 bool GetPrimary() const 295 { 296 return primary_; 297 } 298 SetPrimary(bool primary)299 void SetPrimary(bool primary) 300 { 301 primary_ = primary; 302 } 303 GetStickyRadius()304 const Dimension& GetStickyRadius() const 305 { 306 return stickyRadius_; 307 } 308 SetStickyRadius(const Dimension & stickyRadius)309 void SetStickyRadius(const Dimension& stickyRadius) 310 { 311 stickyRadius_ = stickyRadius; 312 } 313 NeedDivider()314 bool NeedDivider() const 315 { 316 return needDivider_; 317 } 318 MarkNeedDivider(bool needDivider)319 void MarkNeedDivider(bool needDivider) 320 { 321 needDivider_ = needDivider; 322 } 323 GetDividerOrigin()324 const Dimension& GetDividerOrigin() const 325 { 326 return dividerOrigin_; 327 } 328 SetDividerOrigin(const Dimension & origin)329 void SetDividerOrigin(const Dimension& origin) 330 { 331 dividerOrigin_ = origin; 332 } 333 GetDividerLength()334 const Dimension& GetDividerLength() const 335 { 336 return dividerLength_; 337 } 338 SetDividerLength(const Dimension & length)339 void SetDividerLength(const Dimension& length) 340 { 341 dividerLength_ = length; 342 } 343 GetDividerColor()344 const Color& GetDividerColor() const 345 { 346 return dividerColor_; 347 } 348 SetDividerColor(const Color & color)349 void SetDividerColor(const Color& color) 350 { 351 dividerColor_ = color; 352 } 353 GetDividerHeight()354 const Dimension& GetDividerHeight() const 355 { 356 return dividerHeight_; 357 } 358 SetDividerHeight(const Dimension & dividerHeight)359 void SetDividerHeight(const Dimension& dividerHeight) 360 { 361 dividerHeight_ = dividerHeight; 362 } 363 IsActive()364 bool IsActive() const 365 { 366 return isActive_; 367 } 368 SetIsActive(bool isActive)369 void SetIsActive(bool isActive) 370 { 371 isActive_ = isActive; 372 } 373 SetTransitionEffect(TransitionEffect transitionEffect)374 void SetTransitionEffect(TransitionEffect transitionEffect) 375 { 376 transitionEffect_ = transitionEffect; 377 } 378 GetTransitionEffect()379 TransitionEffect GetTransitionEffect() const 380 { 381 return transitionEffect_; 382 } 383 GetAlignSelf()384 FlexAlign GetAlignSelf() const 385 { 386 return alignSelf_; 387 } 388 SetAlignSelf(FlexAlign alignSelf)389 void SetAlignSelf(FlexAlign alignSelf) 390 { 391 alignSelf_ = alignSelf; 392 } 393 GetClickColor()394 const Color& GetClickColor() const 395 { 396 return clickColor_; 397 } SetClickColor(const Color & clickColor)398 void SetClickColor(const Color& clickColor) 399 { 400 clickColor_ = clickColor; 401 } 402 GetKey()403 int32_t GetKey() const 404 { 405 return key_; 406 } 407 SetKey(int32_t key)408 void SetKey(int32_t key) 409 { 410 key_ = key; 411 } 412 413 private: 414 int32_t index_ = -1; // invalid index 415 int32_t columnSpan_ = DEFAULT_COLUMN_SPAN; 416 uint32_t flags_ = 0; 417 int32_t op_ = LIST_ITEM_OP_NONE; 418 FlexAlign alignSelf_ = FlexAlign::AUTO; 419 420 std::string type_; 421 Color focusAnimationColor_ = Color::WHITE; 422 Radius topLeftRadius_; 423 Radius topRightRadius_; 424 Radius bottomLeftRadius_; 425 Radius bottomRightRadius_; 426 std::string indexKey_; 427 int32_t key_ = -1; 428 bool needVibrate_ = true; 429 bool rotationVibrate_ = false; 430 bool supportScale_ = true; 431 bool supportOpacity_ = false; 432 bool supportClick_ = true; 433 bool sticky_ = false; 434 bool isTitle_ = false; 435 StickyMode stickyMode_ = StickyMode::NONE; 436 Dimension stickyRadius_; 437 bool primary_ = false; 438 bool needDivider_ = false; 439 bool isActive_ = false; 440 Dimension dividerOrigin_; 441 Dimension dividerLength_; 442 Dimension dividerHeight_ = DIVIDER_DEFAULT_HEIGHT; 443 Color dividerColor_; 444 Color clickColor_ = Color::TRANSPARENT; 445 446 EventMarker clickEventId_; 447 EventMarker stickyEventId_; 448 449 TransitionEffect transitionEffect_ = TransitionEffect::NONE; 450 }; 451 452 } // namespace OHOS::Ace 453 454 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_COMPONENT_H 455