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_V2_LIST_LIST_ITEM_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_LIST_LIST_ITEM_COMPONENT_H 18 19 #include <string> 20 21 #include "base/utils/macros.h" 22 #include "base/utils/noncopyable.h" 23 #include "core/components_v2/common/common_def.h" 24 #include "core/components_v2/list/list_properties.h" 25 #include "core/pipeline/base/sole_child_component.h" 26 27 namespace OHOS::Ace::V2 { 28 29 30 using DeepRenderFunc = std::function<RefPtr<Component>()>; 31 32 class ACE_EXPORT ListItemComponent : public SoleChildComponent { 33 DECLARE_ACE_TYPE(V2::ListItemComponent, SoleChildComponent); 34 35 public: 36 ListItemComponent() = default; 37 ~ListItemComponent() override = default; 38 39 RefPtr<Element> CreateElement() override; 40 RefPtr<RenderNode> CreateRenderNode() override; 41 42 ACE_DEFINE_COMPONENT_PROP(Type, std::string); 43 ACE_DEFINE_COMPONENT_PROP(Sticky, StickyMode, StickyMode::NONE); 44 ACE_DEFINE_COMPONENT_PROP(EditMode, uint32_t, EditMode::NONE); 45 ACE_DEFINE_COMPONENT_PROP(BorderRadius, Dimension, 0.0_vp); 46 ACE_DEFINE_COMPONENT_PROP(EdgeEffect, SwipeEdgeEffect, SwipeEdgeEffect::Spring); 47 ACE_DEFINE_COMPONENT_PROP(StartDeleteAreaDistance, Dimension, 0.0_vp); 48 ACE_DEFINE_COMPONENT_PROP(UseStartDefaultDeleteAnimation, bool, true); 49 ACE_DEFINE_COMPONENT_PROP(UseEndDefaultDeleteAnimation, bool, true); 50 ACE_DEFINE_COMPONENT_EVENT(OnStartDelete, void()); 51 ACE_DEFINE_COMPONENT_EVENT(OnEnterStartDeleteArea, void()); 52 ACE_DEFINE_COMPONENT_EVENT(OnExitStartDeleteArea, void()); 53 ACE_DEFINE_COMPONENT_PROP(EndDeleteAreaDistance, Dimension, 0.0_vp); 54 ACE_DEFINE_COMPONENT_EVENT(OnEndDelete, void()); 55 ACE_DEFINE_COMPONENT_EVENT(OnEnterEndDeleteArea, void()); 56 ACE_DEFINE_COMPONENT_EVENT(OnExitEndDeleteArea, void()); 57 58 uint32_t Compare(const RefPtr<Component>& component) const override; 59 GetSelectable()60 bool GetSelectable() const 61 { 62 return selectable_; 63 } 64 SetSelectable(bool selectable)65 void SetSelectable(bool selectable) 66 { 67 selectable_ = selectable; 68 } 69 SetSwiperStartComponent(RefPtr<Component> component)70 void SetSwiperStartComponent(RefPtr<Component> component) 71 { 72 swiperStartComponent_ = component; 73 } 74 GetSwiperStartComponent()75 RefPtr<Component> GetSwiperStartComponent() 76 { 77 return swiperStartComponent_; 78 } 79 SetSwiperEndComponent(RefPtr<Component> component)80 void SetSwiperEndComponent(RefPtr<Component> component) 81 { 82 swiperEndComponent_ = component; 83 } 84 GetSwiperEndComponent()85 RefPtr<Component> GetSwiperEndComponent() 86 { 87 return swiperEndComponent_; 88 } 89 GetOnSelectId()90 OnSelectFunc GetOnSelectId() const 91 { 92 return onSelectId_; 93 } 94 SetOnSelectId(const OnSelectFunc & onSelectId)95 void SetOnSelectId(const OnSelectFunc& onSelectId) 96 { 97 onSelectId_ = onSelectId; 98 } 99 100 // transfer ownershop of deepRenderFunc_ to provided ListItemComponent MoveDeepRenderFunc(RefPtr<ListItemComponent> & component)101 void MoveDeepRenderFunc(RefPtr<ListItemComponent>& component) 102 { 103 component->deepRenderFunc_ = std::move(deepRenderFunc_); 104 ACE_DCHECK(deepRenderFunc_ == nullptr); 105 } 106 SetDeepRenderFunc(const DeepRenderFunc & deepRenderFunc)107 void SetDeepRenderFunc(const DeepRenderFunc& deepRenderFunc) 108 { 109 deepRenderFunc_ = deepRenderFunc; 110 } 111 ExecDeepRender()112 RefPtr<Component> ExecDeepRender() const 113 { 114 return (deepRenderFunc_) ? deepRenderFunc_() : nullptr; 115 } 116 SetIsLazyCreating(const bool isLazy)117 void SetIsLazyCreating(const bool isLazy) 118 { 119 isLazyCreating_ = isLazy; 120 } 121 GetIsLazyCreating()122 bool GetIsLazyCreating() const 123 { 124 return isLazyCreating_; 125 } 126 IsDragStart()127 bool IsDragStart() const 128 { 129 return isDragStart_; 130 } 131 MarkIsDragStart(bool isDragStart)132 void MarkIsDragStart(bool isDragStart) 133 { 134 isDragStart_ = isDragStart; 135 } 136 137 private: 138 OnSelectFunc onSelectId_; 139 DeepRenderFunc deepRenderFunc_ = nullptr; 140 bool isLazyCreating_ = false; 141 bool selectable_ = true; 142 bool isDragStart_ = false; 143 RefPtr<Component> swiperStartComponent_; 144 RefPtr<Component> swiperEndComponent_; 145 ACE_DISALLOW_COPY_AND_MOVE(ListItemComponent); 146 }; 147 148 } // namespace OHOS::Ace::V2 149 150 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_LIST_LIST_ITEM_COMPONENT_H 151