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_LAYOUT_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_LAYOUT_MANAGER_H 18 19 #include <functional> 20 #include <vector> 21 22 #include "core/animation/bilateral_spring_adapter.h" 23 #include "core/animation/simple_spring_chain.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components/list/layout_manager.h" 26 #include "core/components/list/render_list.h" 27 #include "core/components/scroll/scrollable.h" 28 29 namespace OHOS::Ace { 30 31 class ListLayoutManager : public LayoutManager { 32 DECLARE_ACE_TYPE(ListLayoutManager, LayoutManager); 33 34 public: 35 explicit ListLayoutManager(RenderList& renderList); 36 37 ~ListLayoutManager() override = default; 38 39 void Update() override; 40 41 void PerformLayout() override; 42 43 void RefreshLayout() override; 44 45 void MoveItemToViewPort(double position) override; 46 47 void MoveItemGroupToViewPort(double position, double size) override; 48 49 int32_t focusMove(KeyDirection direction) override; 50 51 void CalculateFocusIndexPosition() override; 52 53 void LayoutToItem(int32_t toIndex) override; 54 55 void LayoutToPosition(double position) override; 56 57 void LayoutMore(double incDistance) override; 58 59 void NotifyNeedRefresh() override; 60 AdjustLayoutSize(double size)61 virtual double AdjustLayoutSize(double size) 62 { 63 return size; 64 } 65 66 double FlushChainAnimation() override; 67 68 double GetItemAnimationValue(int32_t index) const override; 69 70 protected: 71 virtual void SetChildPosition(const RefPtr<RenderNode>& child, int32_t index, double mainSize); 72 RenderList& renderList_; 73 74 LayoutParam MakeInnerLayoutParam(FlexAlign selfAlign) const; 75 LayoutParam AdjustLayoutParam(const RefPtr<RenderNode> child, LayoutParam param); 76 void RequestMoreItemsIfNeeded(int32_t viewBegin, int32_t viewEnd) override; 77 void UpdateItemGroupAttr(RefPtr<RenderNode>& itemChild); 78 void ShowItemFocusAnimation(); 79 void AnimationForItemUpdate(); 80 81 private: 82 void CalculateCachedRange(int32_t viewBegin, int32_t viewEnd, int32_t cachedCount, int32_t& cachedBegin, 83 int32_t& cachedEnd) override; 84 bool CalculateStartPosition(double& start); 85 bool CheckNeedAnimation(); 86 void InitChainAnimation(int32_t nodeCount); 87 double GetChainDelta(int32_t index) const; 88 void UpdateItemPosition(void); 89 void UpdateMaxEndOffset(int32_t index, double curMainSize); 90 91 int32_t maxEndIndex_ = LIST_PARAM_INVAID; 92 double maxEndOffset_ = 0.0; 93 94 int32_t cachedCount_ = 1; 95 int32_t maxCount_ = 0; 96 double mainOffset_ = -1.0; 97 double controlValue_ = 0.0; 98 bool chainOverScroll_ = false; 99 double chainOffset_ = 0.0; 100 RefPtr<BilateralSpringAdapter> chainAdapter_; 101 RefPtr<SimpleSpringChain> chain_; 102 }; 103 104 } // namespace OHOS::Ace 105 106 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_LAYOUT_MANAGER_H 107