• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H
18 
19 #include <map>
20 #include <optional>
21 
22 #include "base/geometry/axis.h"
23 #include "base/memory/referenced.h"
24 #include "core/components_ng/layout/layout_algorithm.h"
25 #include "core/components_ng/layout/layout_wrapper.h"
26 #include "core/components_ng/pattern/list/list_layout_property.h"
27 #include "core/components_ng/pattern/list/list_position_map.h"
28 #include "core/components_v2/list/list_component.h"
29 #include "core/components_v2/list/list_properties.h"
30 
31 namespace OHOS::Ace::NG {
32 class PipelineContext;
33 class ListPositionMap;
34 
35 struct ListItemGroupLayoutInfo {
36     bool atStart = false;
37     bool atEnd = false;
38     float averageHeight = -1;
39     float headerSize = 0.0f;
40     float footerSize = 0.0f;
41     float spaceWidth = 0.0f;
42 };
43 
44 struct ListItemInfo {
45     int32_t id;
46     float startPos;
47     float endPos;
48     bool isGroup;
49     bool isPressed = false;
50     float scale = 1.0f;
51     float offsetY = 0.0f;
52     std::optional<ListItemGroupLayoutInfo> groupInfo = std::nullopt;
53 };
54 
55 struct ListPredictLayoutParam {
56     std::list<int32_t> items;
57     LayoutConstraintF layoutConstraint;
58 };
59 
60 struct PredictLayoutItem {
61     int32_t index;
62     int32_t forwardCacheCount;
63     int32_t backwardCacheCount;
64 };
65 
66 struct ListPredictLayoutParamV2 {
67     std::list<PredictLayoutItem> items;
68     LayoutConstraintF layoutConstraint;
69     LayoutConstraintF groupLayoutConstraint;
70 };
71 
72 enum class ScrollAutoType {
73     NOT_CHANGE = 0,
74     START,
75     END,
76 };
77 
78 enum class LayoutDirection {
79     NONE = 0,
80     FORWARD,
81     BACKWARD,
82 };
83 
84 // TextLayoutAlgorithm acts as the underlying text layout.
85 class ACE_EXPORT ListLayoutAlgorithm : public LayoutAlgorithm {
86     DECLARE_ACE_TYPE(ListLayoutAlgorithm, LayoutAlgorithm);
87 
88 public:
89     using PositionMap = std::map<int32_t, ListItemInfo>;
90     static constexpr int32_t LAST_ITEM = -1;
91 
92     ListLayoutAlgorithm(int32_t itemStartIndex = 0)
itemStartIndex_(itemStartIndex)93         : itemStartIndex_(itemStartIndex)
94     {}
95 
96     ~ListLayoutAlgorithm() override = default;
97 
OnReset()98     void OnReset() override {}
99 
GetItemPosition()100     const PositionMap& GetItemPosition() const
101     {
102         return itemPosition_;
103     }
104 
SetItemsPosition(const PositionMap & itemPosition)105     void SetItemsPosition(const PositionMap& itemPosition)
106     {
107         itemPosition_ = itemPosition;
108     }
109 
GetRecycledItemPosition()110     const PositionMap& GetRecycledItemPosition() const
111     {
112         return recycledItemPosition_;
113     }
114 
GetCachedItemPosition()115     const PositionMap& GetCachedItemPosition() const
116     {
117         return cachedItemPosition_;
118     }
119 
120     void ClearAllItemPosition(LayoutWrapper* layoutWrapper);
121 
SetOverScrollFeature()122     void SetOverScrollFeature()
123     {
124         overScrollFeature_ = true;
125     }
126 
SetCanOverScroll(bool canOverScroll)127     void SetCanOverScroll(bool canOverScroll)
128     {
129         canOverScroll_ = canOverScroll;
130     }
131 
SetCanOverScrollStart(bool canOverScroll)132     void SetCanOverScrollStart(bool canOverScroll)
133     {
134         canOverScrollStart_ = canOverScroll;
135     }
136 
SetCanOverScrollEnd(bool canOverScroll)137     void SetCanOverScrollEnd(bool canOverScroll)
138     {
139         canOverScrollEnd_ = canOverScroll;
140     }
141 
SetIsSpringEffect(bool isSpringEffect)142     void SetIsSpringEffect(bool isSpringEffect)
143     {
144         isSpringEffect_ = isSpringEffect;
145     }
146 
SetIndex(int32_t index)147     void SetIndex(int32_t index)
148     {
149         jumpIndex_ = index;
150     }
151 
SetTargetIndex(int32_t index)152     void SetTargetIndex(int32_t index)
153     {
154         targetIndex_ = index;
155     }
156 
SetTargetIndexInGroup(int32_t targetIndexInGroup)157     void SetTargetIndexInGroup(int32_t targetIndexInGroup)
158     {
159         targetIndexInGroup_ = targetIndexInGroup;
160     }
161 
GetTargetIndex()162     std::optional<int32_t> GetTargetIndex() const
163     {
164         return targetIndexStaged_;
165     }
166 
SetPredictSnapOffset(float predictSnapOffset)167     void SetPredictSnapOffset(float predictSnapOffset)
168     {
169         predictSnapOffset_ = predictSnapOffset;
170     }
171 
GetPredictSnapOffset()172     std::optional<float> GetPredictSnapOffset() const
173     {
174         return predictSnapOffset_;
175     }
176 
SetPredictSnapEndPosition(float predictSnapEndPos)177     void SetPredictSnapEndPosition(float predictSnapEndPos)
178     {
179         predictSnapEndPos_ = predictSnapEndPos;
180     }
181 
GetPredictSnapEndPosition()182     std::optional<float> GetPredictSnapEndPosition()
183     {
184         return predictSnapEndPos_;
185     }
186 
SetScrollSnapVelocity(float velocity)187     void SetScrollSnapVelocity(float velocity)
188     {
189         scrollSnapVelocity_ = velocity;
190     }
191 
SetIndexInGroup(int32_t index)192     void SetIndexInGroup(int32_t index)
193     {
194         jumpIndexInGroup_ = index;
195     }
196 
SetIndexAlignment(ScrollAlign align)197     void SetIndexAlignment(ScrollAlign align)
198     {
199         scrollAlign_ = align;
200     }
201 
SetCurrentDelta(float offset)202     void SetCurrentDelta(float offset)
203     {
204         currentDelta_ = offset;
205         currentOffset_ = offset;
206     }
207 
GetCurrentOffset()208     float GetCurrentOffset() const
209     {
210         return currentOffset_ + adjustOffset_;
211     }
212 
SetIsNeedCheckOffset(bool isNeedCheckOffset)213     void SetIsNeedCheckOffset(bool isNeedCheckOffset)
214     {
215         isNeedCheckOffset_ = isNeedCheckOffset;
216     }
217 
SetTotalOffset(float totalOffset)218     void SetTotalOffset(float totalOffset)
219     {
220         totalOffset_ = totalOffset;
221     }
222 
GetContentMainSize()223     float GetContentMainSize() const
224     {
225         return contentMainSize_;
226     }
227 
SetPrevContentMainSize(float mainSize)228     void SetPrevContentMainSize(float mainSize)
229     {
230         prevContentMainSize_ = mainSize;
231     }
232 
GetStartIndex()233     int32_t GetStartIndex() const
234     {
235         return itemPosition_.empty() ? -1 : itemPosition_.begin()->first;
236     }
237 
GetEndIndex()238     int32_t GetEndIndex() const
239     {
240         return itemPosition_.empty() ? -1 : itemPosition_.rbegin()->first;
241     }
242 
243     int32_t GetMidIndex(LayoutWrapper* layoutWrapper, bool usePreContentMainSize = false);
244 
GetMaxListItemIndex()245     int32_t GetMaxListItemIndex() const
246     {
247         return totalItemCount_ - 1;
248     }
249 
SetSpaceWidth(float spaceWidth)250     void SetSpaceWidth(float spaceWidth)
251     {
252         spaceWidth_ = spaceWidth;
253     }
254 
GetSpaceWidth()255     float GetSpaceWidth() const
256     {
257         return spaceWidth_;
258     }
259 
NeedEstimateOffset()260     bool NeedEstimateOffset() const
261     {
262         return needEstimateOffset_;
263     }
264 
SetContentStartOffset(float startOffset)265     void SetContentStartOffset(float startOffset)
266     {
267         contentStartOffset_ = startOffset;
268     }
269 
SetContentEndOffset(float endOffset)270     void SetContentEndOffset(float endOffset)
271     {
272         contentEndOffset_ = endOffset;
273     }
274 
GetContentStartOffset()275     float GetContentStartOffset() const
276     {
277         return contentStartOffset_;
278     }
279 
GetContentEndOffset()280     float GetContentEndOffset() const
281     {
282         return contentEndOffset_;
283     }
284 
SetPrevContentStartOffset(float prevContentStartOffset)285     void SetPrevContentStartOffset(float prevContentStartOffset)
286     {
287         prevContentStartOffset_ = prevContentStartOffset;
288     }
289 
SetPrevContentEndOffset(float prevContentEndOffset)290     void SetPrevContentEndOffset(float prevContentEndOffset)
291     {
292         prevContentEndOffset_ = prevContentEndOffset;
293     }
294 
GetStartPosition()295     float GetStartPosition() const
296     {
297         if (itemPosition_.empty()) {
298             return 0.0f;
299         }
300         if (GetStartIndex() == 0) {
301             return itemPosition_.begin()->second.startPos;
302         }
303         return itemPosition_.begin()->second.startPos - spaceWidth_;
304     }
305 
GetEndPosition()306     float GetEndPosition() const
307     {
308         if (itemPosition_.empty()) {
309             return 0.0f;
310         }
311         if (GetEndIndex() == totalItemCount_ - 1) {
312             return itemPosition_.rbegin()->second.endPos;
313         }
314         return itemPosition_.rbegin()->second.endPos + spaceWidth_;
315     }
316 
317     float GetStartPositionWithChainOffset() const;
318 
SetChainOffsetCallback(std::function<float (int32_t)> func)319     void SetChainOffsetCallback(std::function<float(int32_t)> func)
320     {
321         chainOffsetFunc_ = std::move(func);
322     }
323 
GetChainOffset(int32_t index)324     float GetChainOffset(int32_t index) const
325     {
326         if (!chainOffsetFunc_) {
327             return 0.0f;
328         }
329         if (!isStackFromEnd_) {
330             return chainOffsetFunc_(index);
331         }
332         return -chainOffsetFunc_(totalItemCount_ - index - 1);
333     }
334 
SetTotalItemCount(int32_t totalItemCount)335     void SetTotalItemCount(int32_t totalItemCount)
336     {
337         totalItemCount_ = totalItemCount;
338     }
339 
SetFirstRepeatCount(int32_t firstRepeatCount)340     void SetFirstRepeatCount(int32_t firstRepeatCount)
341     {
342         firstRepeatCount_ = firstRepeatCount;
343     }
344 
SetChainInterval(float interval)345     void SetChainInterval(float interval)
346     {
347         chainInterval_ = interval;
348     }
349 
IsCrossMatchChild()350     bool IsCrossMatchChild() const
351     {
352         return crossMatchChild_;
353     }
354 
355     float GetChildMaxCrossSize(LayoutWrapper* layoutWrapper, Axis axis) const;
356 
357     void Measure(LayoutWrapper* layoutWrapper) override;
358 
359     void Layout(LayoutWrapper* layoutWrapper) override;
360     void UpdateOverlay(LayoutWrapper* layoutWrapper);
361 
362     void LayoutForward(LayoutWrapper* layoutWrapper, int32_t startIndex, float startPos);
363     void LayoutBackward(LayoutWrapper* layoutWrapper, int32_t endIndex, float endPos);
364 
365     void BeginLayoutForward(float startPos, LayoutWrapper* layoutWrapper);
366 
367     void BeginLayoutBackward(float startPos, LayoutWrapper* layoutWrapper);
368 
369     void HandleJumpAuto(LayoutWrapper* layoutWrapper, int32_t startIndex, int32_t endIndex);
370 
371     virtual void HandleJumpCenter(LayoutWrapper* layoutWrapper);
372 
373     void HandleJumpStart(LayoutWrapper* layoutWrapper);
374 
375     void HandleJumpEnd(LayoutWrapper* layoutWrapper);
376 
377     bool NoNeedJump(LayoutWrapper* layoutWrapper, float startPos, float endPos,
378         int32_t startIndex, int32_t endIndex, int32_t jumpIndex, float jumpIndexStartPos);
379 
380     bool CheckNoNeedJumpListItem(LayoutWrapper* layoutWrapper, float startPos, float endPos,
381         int32_t startIndex, int32_t endIndex, int32_t jumpIndex);
382 
383     bool CheckNoNeedJumpListItemGroup(LayoutWrapper* layoutWrapper, int32_t startIndex, int32_t endIndex,
384         int32_t jumpIndex, float jumpIndexStartPos);
385 
386     virtual float MeasureAndGetChildHeight(LayoutWrapper* layoutWrapper, int32_t childIndex,
387         bool groupLayoutAll = true);
388 
GetChildHeight(LayoutWrapper * layoutWrapper,int32_t childIndex)389     virtual float GetChildHeight(LayoutWrapper* layoutWrapper, int32_t childIndex)
390     {
391         return childrenSize_->GetChildSize(childIndex, isStackFromEnd_);
392     }
393 
GetLanes()394     virtual int32_t GetLanes() const
395     {
396         return 1;
397     }
398 
SetLaneGutter(float laneGutter)399     void SetLaneGutter(float laneGutter)
400     {
401         laneGutter_ = laneGutter;
402     }
403 
GetLaneGutter()404     float GetLaneGutter() const
405     {
406         return laneGutter_;
407     }
408 
409     void OffScreenLayoutDirection(LayoutWrapper* layoutWrapper);
410 
GetScrollAutoType()411     ScrollAutoType GetScrollAutoType() const
412     {
413         return scrollAutoType_;
414     }
415 
416     bool CheckJumpValid(LayoutWrapper* layoutWrapper);
417 
418     float GetListGroupItemHeight(const RefPtr<LayoutWrapper>& layoutWrapper, int32_t index);
419 
420     bool JudgeInOfScreenScrollAutoType(const RefPtr<LayoutWrapper>& layoutWrapper,
421         const RefPtr<ListLayoutProperty>& layoutProperty, float topPos, float bottomPos);
422 
423     void JudgeOutOfScreenScrollAutoType(const RefPtr<LayoutWrapper>& layoutWrapper, int32_t index,
424         const RefPtr<ListLayoutProperty>& layoutProperty, int32_t indexInGroup, int32_t judgeIndex,
425         int32_t startIndex, int32_t endIndex);
426 
GetGroupLayoutConstraint()427     virtual const LayoutConstraintF& GetGroupLayoutConstraint() const
428     {
429         return childLayoutConstraint_;
430     }
431 
SetListChildrenMainSize(const RefPtr<ListChildrenMainSize> & childrenMainSize)432     void SetListChildrenMainSize(const RefPtr<ListChildrenMainSize>& childrenMainSize)
433     {
434         childrenSize_ = childrenMainSize;
435     }
436 
SetListPositionMap(const RefPtr<ListPositionMap> & posMap)437     void SetListPositionMap(const RefPtr<ListPositionMap>& posMap)
438     {
439         posMap_ = posMap;
440     }
441 
442     void ResetLayoutItem(LayoutWrapper* layoutWrapper);
443 
444     void ResetUnLayoutedItems(LayoutWrapper* layoutWrapper, PositionMap& positionMap);
445 
446     void ResetUnLayoutedItem(const RefPtr<LayoutWrapper>& layoutWrapper, ListItemInfo& info);
447 
448     std::pair<int32_t, float> GetSnapStartIndexAndPos();
449 
450     std::pair<int32_t, float> GetSnapEndIndexAndPos();
451 
GetStackFromEnd()452     bool GetStackFromEnd() const
453     {
454         return isStackFromEnd_;
455     }
456 
457     void ReverseItemPosition(ListLayoutAlgorithm::PositionMap& itemPosition, int32_t totalItemCount, float mainSize);
458 
459     void ProcessStackFromEnd();
460 
GetLaneIdx4Divider()461     int32_t GetLaneIdx4Divider() const
462     {
463         return laneIdx4Divider_;
464     }
465 
466     void CalculateTotalCountByRepeat(LayoutWrapper* layoutWrapper);
467 
SetIsRoundingMode()468     void SetIsRoundingMode()
469     {
470         isRoundingMode_ = true;
471     }
472 
MeasureInNextFrame()473     bool MeasureInNextFrame() const override
474     {
475         return measureInNextFrame_;
476     }
477 
SetPrevMeasureBreak(bool value)478     void SetPrevMeasureBreak(bool value)
479     {
480         prevMeasureBreak_ = value;
481     }
482 
GetPrevMeasureBreak()483     bool GetPrevMeasureBreak() const
484     {
485         return prevMeasureBreak_;
486     }
487 
488     bool IsNeedSyncLoad(const RefPtr<ListLayoutProperty>& property) const;
489 
490     void CheckGroupMeasureBreak(const RefPtr<LayoutWrapper>& layoutWrapper);
491 
SetDraggingIndex(int32_t index)492     void SetDraggingIndex(int32_t index)
493     {
494         draggingIndex_ = index;
495     }
496 
497     void ExpandWithSafeAreaPadding(const RefPtr<LayoutWrapper>& layoutWrapper);
498 
499 protected:
500     virtual void UpdateListItemConstraint(
501         Axis axis, const OptionalSizeF& selfIdealSize, LayoutConstraintF& contentConstraint);
502     virtual int32_t LayoutALineForward(
503         LayoutWrapper* layoutWrapper, int32_t& currentIndex, float startPos, float& endPos);
504     virtual int32_t LayoutALineBackward(
505         LayoutWrapper* layoutWrapper, int32_t& currentIndex, float endPos, float& startPos);
506     virtual float CalculateLaneCrossOffset(float crossSize, float childCrossSize, bool isGroup);
CalculateLanes(const RefPtr<ListLayoutProperty> & layoutProperty,const LayoutConstraintF & layoutConstraint,std::optional<float> crossSizeOptional,Axis axis)507     virtual void CalculateLanes(const RefPtr<ListLayoutProperty>& layoutProperty,
508         const LayoutConstraintF& layoutConstraint, std::optional<float> crossSizeOptional, Axis axis) {};
GetLanesFloor(LayoutWrapper * layoutWrapper,int32_t index)509     virtual int32_t GetLanesFloor(LayoutWrapper* layoutWrapper, int32_t index)
510     {
511         return index;
512     }
GetLanesCeil(LayoutWrapper * layoutWrapper,int32_t index)513     virtual int32_t GetLanesCeil(LayoutWrapper* layoutWrapper, int32_t index)
514     {
515         return index;
516     }
517     virtual void SetCacheCount(LayoutWrapper* layoutWrapper, int32_t cacheCount);
518     virtual void SetActiveChildRange(LayoutWrapper* layoutWrapper, int32_t cacheStart, int32_t cacheEnd, bool show);
519 
520     void SetListItemGroupJumpIndex(const RefPtr<ListItemGroupLayoutAlgorithm>& itemGroup,
521         bool forwardLayout, int32_t index);
522     void SetListItemGroupParam(const RefPtr<LayoutWrapper>& layoutWrapper, int32_t index, float referencePos,
523         bool forwardLayout, const RefPtr<ListLayoutProperty>& layoutProperty, bool groupNeedAllLayout,
524         bool needAdjustRefPos = false);
525     static void SetListItemIndex(const RefPtr<LayoutWrapper>& layoutWrapper, int32_t index);
526     void ReMeasureListItemGroup(LayoutWrapper* layoutWrapper, bool forwardLayout);
527     void CheckListItemGroupRecycle(
528         LayoutWrapper* layoutWrapper, int32_t index, float referencePos, bool forwardLayout) const;
529     void AdjustPostionForListItemGroup(LayoutWrapper* layoutWrapper, Axis axis, int32_t index, bool forwardLayout);
SetItemInfo(int32_t index,ListItemInfo && info)530     void SetItemInfo(int32_t index, ListItemInfo&& info)
531     {
532         itemPosition_[index] = info;
533     }
SetCachedItemInfo(int32_t index,ListItemInfo && info)534     void SetCachedItemInfo(int32_t index, ListItemInfo&& info)
535     {
536         cachedItemPosition_[index] = info;
537     }
538     void LayoutItem(RefPtr<LayoutWrapper>& layoutWrapper, int32_t index, const ListItemInfo& pos,
539         int32_t& startIndex, float crossSize);
540     static void SyncGeometry(RefPtr<LayoutWrapper>& wrapper, bool isDirty = false);
541     ListItemInfo GetListItemGroupPosition(const RefPtr<LayoutWrapper>& layoutWrapper, int32_t index);
542     bool CheckNeedMeasure(const RefPtr<LayoutWrapper>& layoutWrapper) const;
543     bool CheckLayoutConstraintChanged(const RefPtr<LayoutWrapper>& layoutWrapper) const;
544     void ReviseSpace(const RefPtr<ListLayoutProperty>& listLayoutProperty);
545     CachedIndexInfo GetLayoutGroupCachedCount(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& wrapper,
546         int32_t forwardCache, int32_t backwardCache, int32_t index, bool outOfView);
547     void AdjustStartPosition(const RefPtr<LayoutWrapper>& layoutWrapper, float& startPos);
548     float GetLayoutCrossAxisSize(LayoutWrapper* layoutWrapper);
549     int32_t UpdateDefaultCachedCount(const int32_t oldCachedCount, const int32_t itemCount);
550     bool IsListLanesEqual(const RefPtr<LayoutWrapper>& wrapper) const;
551     void ReportGetChildError(const std::string& funcName, int32_t index) const;
552     void UpdateNoLayoutedItems();
553 
554     Axis axis_ = Axis::VERTICAL;
555     int32_t laneIdx4Divider_ = 0;
556     LayoutConstraintF childLayoutConstraint_;
557     RefPtr<ListChildrenMainSize> childrenSize_;
558     RefPtr<ListPositionMap> posMap_;
559     RefPtr<ListLayoutProperty> listLayoutProperty_;
560     std::optional<std::pair<int32_t, ListItemInfo>> firstItemInfo_;
561 
562     virtual void MeasureList(LayoutWrapper* layoutWrapper);
563     LayoutDirection LayoutDirectionForTargetIndex(LayoutWrapper* layoutWrapper, int startIndex);
564     void CheckJumpToIndex();
565 
566     void OnSurfaceChanged(LayoutWrapper* layoutWrapper);
567 
568     virtual void FixPredictSnapOffset(const RefPtr<ListLayoutProperty>& listLayoutProperty);
569     virtual void FixPredictSnapPos();
570     void FixPredictSnapOffsetAlignCenter();
571 
572     void ProcessCacheCount(LayoutWrapper* layoutWrapper, int32_t cacheCount, bool show);
573     virtual int32_t LayoutCachedForward(LayoutWrapper* layoutWrapper, int32_t cacheCount,
574         int32_t& cachedCount, int32_t curIndex, std::list<PredictLayoutItem>& predictList, bool show);
575     virtual int32_t LayoutCachedBackward(LayoutWrapper* layoutWrapper, int32_t cacheCount,
576         int32_t& cachedCount, int32_t curIndex, std::list<PredictLayoutItem>& predictList, bool show);
577     std::list<PredictLayoutItem> LayoutCachedItemV2(LayoutWrapper* layoutWrapper, int32_t cacheCount, bool show);
578     std::tuple<int32_t, int32_t, int32_t, int32_t> LayoutCachedItemInEdgeGroup(LayoutWrapper* layoutWrapper,
579         int32_t cacheCount, std::list<PredictLayoutItem>& predictList);
580     static bool PredictBuildGroup(RefPtr<LayoutWrapper> wrapper, const LayoutConstraintF& constraint, int64_t deadline,
581         int32_t forwardCached, int32_t backwardCached, const ListMainSizeValues& listMainSizeValues);
582     static void PostIdleTaskV2(RefPtr<FrameNode> frameNode, const ListPredictLayoutParamV2& param,
583         ListMainSizeValues listMainSizeValues, bool show);
584     static void PredictBuildV2(RefPtr<FrameNode> frameNode, int64_t deadline,
585         ListMainSizeValues listMainSizeValues, bool show);
586 
587     float GetStopOnScreenOffset(ScrollSnapAlign scrollSnapAlign) const;
588     void FindPredictSnapIndexInItemPositionsStart(float predictEndPos, int32_t& endIndex, int32_t& currIndex) const;
589     void FindPredictSnapIndexInItemPositionsCenter(float predictEndPos, int32_t& endIndex, int32_t& currIndex) const;
590     void FindPredictSnapIndexInItemPositionsEnd(float predictEndPos, int32_t& endIndex, int32_t& currIndex) const;
591     int32_t FindPredictSnapEndIndexInItemPositions(float predictEndPos, ScrollSnapAlign scrollSnapAlign);
592     bool IsUniformHeightProbably();
593     float CalculatePredictSnapEndPositionByIndex(int32_t index, ScrollSnapAlign scrollSnapAlign);
594     virtual void UpdateSnapCenterContentOffset(LayoutWrapper* layoutWrapper);
595     std::optional<ListItemGroupLayoutInfo> GetListItemGroupLayoutInfo(
596         const RefPtr<LayoutWrapper>& wrapper) const;
597     void GetStartIndexInfo(int32_t& index, float& pos, bool& isGroup);
598     void GetEndIndexInfo(int32_t& index, float& pos, bool& isGroup);
599     int32_t GetListItemGroupItemCount(const RefPtr<LayoutWrapper>& wrapper) const;
600 
601     RefPtr<LayoutWrapper> GetListItem(LayoutWrapper* layoutWrapper, int32_t index, bool addToRenderTree = true) const
602     {
603         index = !isStackFromEnd_ ? index : totalItemCount_ - index - 1;
604         return layoutWrapper->GetOrCreateChildByIndex(index + itemStartIndex_, addToRenderTree);
605     }
606     RefPtr<LayoutWrapper> GetChildByIndex(LayoutWrapper* layoutWrapper, uint32_t index, bool isCache = false) const
607     {
608         index =  !isStackFromEnd_ ? index : totalItemCount_ - index - 1;
609         return layoutWrapper->GetChildByIndex(index, isCache);
610     }
revertIndex(int32_t index)611     int32_t revertIndex(int32_t index) const
612     {
613         return !isStackFromEnd_ ? index : totalItemCount_ - index - 1;
614     }
GetLayoutFixOffset()615     virtual float GetLayoutFixOffset()
616     {
617         return 0.0f;
618     }
619 
620     void LostChildFocusToSelf(LayoutWrapper* layoutWrapper, int32_t start, int32_t end);
621 
MeasureHeader(LayoutWrapper * layoutWrapper)622     virtual void MeasureHeader(LayoutWrapper* layoutWrapper) {}
LayoutHeader(LayoutWrapper * layoutWrapper,const OffsetF & paddingOffset,float crossSize)623     virtual void LayoutHeader(LayoutWrapper* layoutWrapper, const OffsetF& paddingOffset, float crossSize) {}
624     virtual void CalcContentOffset(const RefPtr<ListLayoutProperty>& property);
625     virtual bool IsScrollSnapAlignCenter(LayoutWrapper* layoutWrapper);
FixItemLayoutOffset(LayoutWrapper * layoutWrapper)626     virtual void FixItemLayoutOffset(LayoutWrapper* layoutWrapper) {}
627 
628     std::optional<int32_t> jumpIndex_;
629     std::optional<int32_t> targetIndex_;
630     std::optional<int32_t> targetIndexInGroup_;
631     std::optional<int32_t> targetIndexStaged_;
632     std::optional<float> predictSnapOffset_;
633     std::optional<float> predictSnapEndPos_;
634     float scrollSnapVelocity_ = 0.0f;
635 
636     PositionMap itemPosition_;
637     PositionMap recycledItemPosition_;
638     PositionMap cachedItemPosition_;
639     PositionMap noLayoutedItems_;
640     int32_t preStartIndex_ = 0;
641     float currentOffset_ = 0.0f;
642     float adjustOffset_ = 0.0f;
643     float totalOffset_ = 0.0f;
644     float currentDelta_ = 0.0f;
645     float startMainPos_ = 0.0f;
646     float endMainPos_ = 0.0f;
647     std::optional<float> layoutEndMainPos_;
648     std::optional<float> layoutStartMainPos_;
649     float contentStartOffset_ = 0.0f;
650     float contentEndOffset_ = 0.0f;
651     float spaceWidth_ = 0.0f;
652     bool overScrollFeature_ = false;
653     bool canOverScrollStart_ = false;
654     bool canOverScrollEnd_ = false;
655     bool isSpringEffect_ = false;
656     bool expandSafeArea_ = false;
657 
658     int32_t totalItemCount_ = 0;
659     int32_t firstRepeatCount_ = 0;
660 
661     bool needEstimateOffset_ = false;
662 
663     bool mainSizeIsDefined_ = false;
664     bool crossMatchChild_ = false;
665     ScrollSnapAlign scrollSnapAlign_ = ScrollSnapAlign::NONE;
666     bool isReverse_ = false;
667     float contentMainSize_ = 0.0f;
668     float prevContentMainSize_ = 0.0f;
669     float paddingBeforeContent_ = 0.0f;
670     float paddingAfterContent_ = 0.0f;
671     float groupItemAverageHeight_ = 0.0f;
672     OffsetF paddingOffset_;
673     bool isLayouted_ = true;
674     std::function<float(int32_t)> chainOffsetFunc_;
675     bool isStackFromEnd_ = false;
676 
677     int32_t itemStartIndex_ = 0;
678 
679 private:
680     void RecycleGroupItem(LayoutWrapper* layoutWrapper) const;
681     void CheckAndMeasureStartItem(
682         LayoutWrapper* layoutWrapper, int32_t startIndex, float& startPos, bool isGroup, bool forwardLayout);
683 
684     std::pair<int32_t, float> RequestNewItemsForward(LayoutWrapper* layoutWrapper,
685         const LayoutConstraintF& layoutConstraint, int32_t startIndex, float startPos, Axis axis);
686 
687     std::pair<int32_t, float> RequestNewItemsBackward(LayoutWrapper* layoutWrapper,
688         const LayoutConstraintF& layoutConstraint, int32_t startIndex, float startPos, Axis axis);
689 
690     std::pair<int32_t, float> FindIndexAndDeltaInPosMap(float delta) const;
691     bool CanUseInfoInPosMap(int32_t index, float delta) const;
692 
693     void FixPredictSnapOffsetAlignStart();
694     void FixPredictSnapOffsetAlignEnd();
695 
696     std::optional<int32_t> jumpIndexInGroup_;
697     ScrollAlign scrollAlign_ = ScrollAlign::START;
698     ScrollAutoType scrollAutoType_ = ScrollAutoType::NOT_CHANGE;
699 
700     float prevContentStartOffset_ = 0.0f;
701     float prevContentEndOffset_ = 0.0f;
702     bool canOverScroll_ = false;
703     bool forwardFeature_ = false;
704     bool backwardFeature_ = false;
705     bool isNeedCheckOffset_ = false;
706     bool isRoundingMode_ = false;
707     bool measureInNextFrame_ = false;
708     bool syncLoad_ = false;
709     bool prevMeasureBreak_ = false;
710 
711     V2::ListItemAlign listItemAlign_ = V2::ListItemAlign::START;
712 
713     float laneGutter_ = 0.0f;
714 
715     V2::StickyStyle stickyStyle_ = V2::StickyStyle::NONE;
716 
717     float chainInterval_ = 0.0f;
718     int32_t draggingIndex_ = -1;
719 };
720 } // namespace OHOS::Ace::NG
721 
722 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H
723