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_RENDER_LIST_ITEM_GROUP_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_RENDER_LIST_ITEM_GROUP_H 18 19 #include "base/utils/system_properties.h" 20 #include "core/animation/animator.h" 21 #include "core/components/box/render_box.h" 22 #include "core/components/image/image_component.h" 23 #include "core/components/image/render_image.h" 24 #include "core/components/list/render_list.h" 25 #include "core/components/list/render_list_item.h" 26 #include "core/pipeline/base/render_node.h" 27 28 namespace OHOS::Ace { 29 30 using GroupEventFunc = std::function<void(const std::string&)>; 31 using RebuildFunc = std::function<void()>; 32 33 class RenderListItemGroup : public RenderListItem { 34 DECLARE_ACE_TYPE(RenderListItemGroup, RenderListItem); 35 36 public: 37 static RefPtr<RenderNode> Create(); 38 void LayoutExpandableList(double mainSize); 39 void SetAnimationStop(); 40 void ChangeDirection(FlexDirection direction); 41 void HandleClicked(); 42 void UpdateExpandStatusInList(); 43 void ResetLayout(); 44 45 RefPtr<RenderList> GetRenderList(); 46 void ShowFocusAnimation(); 47 int32_t GetNextFocusIndex(int32_t lastFocusIndex, bool vertical, bool reverse); OnTouchTestHit(const Offset & coordinateOffset,const TouchRestrict & touchRestrict,TouchTestResult & result)48 void OnTouchTestHit( 49 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override {} 50 void ItemPrimaryChange(int32_t index); 51 RegisterRebuildCallback(const RebuildFunc & rebuild)52 void RegisterRebuildCallback(const RebuildFunc& rebuild) 53 { 54 rebuild_ = rebuild; 55 } 56 SetExpand(bool expand)57 void SetExpand(bool expand) 58 { 59 if (expand_ != expand) { 60 expand_ = expand; 61 FireExpandEvent(); 62 UpdateGroupComponentStatus(expand); 63 } 64 } 65 GetExpand()66 bool GetExpand() const 67 { 68 return expand_; 69 } 70 SetRightToLeft(bool rightToLeft)71 void SetRightToLeft(bool rightToLeft) 72 { 73 rightToLeft_ = rightToLeft; 74 } 75 GetMainSize(const Size & size)76 double GetMainSize(const Size& size) const 77 { 78 return (direction_ == FlexDirection::ROW || direction_ == FlexDirection::ROW_REVERSE) ? size.Width() 79 : size.Height(); 80 } 81 82 bool IsExpanded(); 83 84 protected: 85 bool expand_ = false; 86 GroupEventFunc onClicked_; 87 GroupEventFunc onCollapse_; 88 GroupEventFunc onExpand_; 89 std::string groupId_; 90 91 private: 92 template<typename T> MakeValue(double mainValue,double crossValue)93 T MakeValue(double mainValue, double crossValue) const 94 { 95 return (direction_ == FlexDirection::ROW || direction_ == FlexDirection::ROW_REVERSE) 96 ? T(mainValue, crossValue) 97 : T(crossValue, mainValue); 98 } 99 GetCrossSize(const Size & size)100 double GetCrossSize(const Size& size) const 101 { 102 return (direction_ == FlexDirection::ROW || direction_ == FlexDirection::ROW_REVERSE) ? size.Height() 103 : size.Width(); 104 } 105 106 void PerformLayout() override; 107 void Update(const RefPtr<Component>& component) override; 108 LayoutParam MakeInnerLayoutParam() const; 109 void GetPrimaryItem(); 110 bool NeedRebuild() const; 111 std::string MakeEventParam(const std::string& command); 112 113 void AddArrowImage(double mainSize); 114 void InitialImage(); 115 void AnimationPerformLayout(double crossSize, double startPosition, double endPosition); 116 RefPtr<KeyframeAnimation<double>> createPositionAnimation( 117 double crossSize, double startPosition, double endPosition); 118 RefPtr<KeyframeAnimation<int32_t>> CreateOpacityAnimation(); 119 void SetChildOpacity(int32_t opacity); 120 void SetChildStretch(bool isStretch); 121 RefPtr<RenderBox> GetRenderBox(const RefPtr<RenderNode>& renderNode); 122 RefPtr<KeyframeAnimation<double>> CreateRotateAnimation(); 123 void RotateArrow(double angle); 124 void ResetChildVisibleState(); 125 void UpdateGroupComponentStatus(bool expand); 126 void FireExpandEvent(); 127 double GetRotateAngle(bool expand); 128 void InitAccessibilityEventListener(); 129 130 RebuildFunc rebuild_; 131 FlexDirection direction_ = FlexDirection::COLUMN; 132 RefPtr<RenderNode> primary_; 133 RefPtr<Animator> animator_; 134 bool animating_ = false; 135 bool rightToLeft_ = false; 136 137 bool initialUpdate_ = true; 138 bool isDefaultPrimary_ = false; 139 Dimension imageSize_; 140 RefPtr<RenderImage> arrowImage_; 141 RefPtr<Component> itemGroup_; 142 }; 143 144 } // namespace OHOS::Ace 145 146 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_RENDER_LIST_ITEM_GROUP_H 147