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_PATTERNS_LIST_LIST_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_PATTERN_H 18 19 #include <tuple> 20 #include "core/animation/chain_animation.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components_ng/pattern/list/list_accessibility_property.h" 23 #include "core/components_ng/pattern/list/list_children_main_size.h" 24 #include "core/components_ng/pattern/list/list_content_modifier.h" 25 #include "core/components_ng/pattern/list/list_event_hub.h" 26 #include "core/components_ng/pattern/list/list_item_pattern.h" 27 #include "core/components_ng/pattern/list/list_layout_algorithm.h" 28 #include "core/components_ng/pattern/list/list_layout_property.h" 29 #include "core/components_ng/pattern/list/list_paint_method.h" 30 #include "core/components_ng/pattern/list/list_position_map.h" 31 #include "core/components_ng/pattern/scroll/inner/scroll_bar.h" 32 #include "core/components_ng/pattern/scroll_bar/proxy/scroll_bar_proxy.h" 33 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h" 34 #include "core/components_ng/render/render_context.h" 35 #include "core/pipeline_ng/pipeline_context.h" 36 37 namespace OHOS::Ace::NG { 38 class InspectorFilter; 39 40 struct ListItemGroupPara { 41 int32_t lanes = -1; 42 int32_t itemEndIndex = -1; 43 int32_t displayStartIndex = -1; 44 int32_t displayEndIndex = -1; 45 bool hasHeader = false; 46 bool hasFooter = false; 47 }; 48 49 struct ListScrollTarget { 50 int32_t index = -1; 51 float extraOffset = 0.0f; 52 ScrollAlign align = ScrollAlign::START; 53 float targetOffset; 54 }; 55 56 class ListPattern : public ScrollablePattern { 57 DECLARE_ACE_TYPE(ListPattern, ScrollablePattern); 58 59 public: ListPattern()60 ListPattern() : ScrollablePattern(EdgeEffect::SPRING, false) {} 61 ~ListPattern() override = default; 62 63 RefPtr<NodePaintMethod> CreateNodePaintMethod() override; 64 CreateLayoutProperty()65 RefPtr<LayoutProperty> CreateLayoutProperty() override 66 { 67 return MakeRefPtr<ListLayoutProperty>(); 68 } 69 CreateEventHub()70 RefPtr<EventHub> CreateEventHub() override 71 { 72 return MakeRefPtr<ListEventHub>(); 73 } 74 CreateAccessibilityProperty()75 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 76 { 77 return MakeRefPtr<ListAccessibilityProperty>(); 78 } 79 UsResRegion()80 bool UsResRegion() override 81 { 82 return false; 83 } 84 85 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override; 86 87 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 88 89 void FromJson(const std::unique_ptr<JsonValue>& json) override; 90 91 bool UpdateCurrentOffset(float offset, int32_t source) override; 92 93 DisplayMode GetDefaultScrollBarDisplayMode() const override; 94 95 int32_t GetFocusNodeIndex(const RefPtr<FocusHub>& focusNode) override; 96 97 void ScrollToFocusNodeIndex(int32_t index) override; 98 GetStartIndex()99 int32_t GetStartIndex() const 100 { 101 return startIndex_; 102 } 103 GetEndIndex()104 int32_t GetEndIndex() const 105 { 106 return endIndex_; 107 } 108 GetMaxListItemIndex()109 int32_t GetMaxListItemIndex() const 110 { 111 return maxListItemIndex_; 112 } 113 GetMaxIndexByRepeat()114 int32_t GetMaxIndexByRepeat() const 115 { 116 return maxListItemIndex_ + repeatDifference_; 117 } 118 GetStartIndexInItemPosition()119 int32_t GetStartIndexInItemPosition() const 120 { 121 return itemPosition_.empty() ? -1 : itemPosition_.begin()->first; 122 } 123 GetEndIndexInItemPosition()124 int32_t GetEndIndexInItemPosition() const 125 { 126 return itemPosition_.empty() ? -1 : itemPosition_.rbegin()->first; 127 } 128 IsScrollable()129 bool IsScrollable() const override 130 { 131 return isScrollable_; 132 } 133 SetMaintainVisibleContentPosition(bool enabled)134 void SetMaintainVisibleContentPosition(bool enabled) 135 { 136 maintainVisibleContentPosition_ = enabled; 137 } 138 GetMaintainVisibleContentPosition()139 bool GetMaintainVisibleContentPosition() 140 { 141 return maintainVisibleContentPosition_; 142 } 143 MarkNeedReEstimateOffset()144 void MarkNeedReEstimateOffset() 145 { 146 needReEstimateOffset_ = true; 147 } 148 149 void NotifyDataChange(int32_t index, int32_t count) override; 150 151 bool IsAtTop() const override; 152 bool IsAtBottom(bool considerRepeat = false) const override; 153 void OnTouchDown(const TouchEventInfo& info) override; 154 OverScrollOffset GetOutBoundaryOffset(float delta, bool useChainDelta = true) const; 155 OverScrollOffset GetOverScrollOffset(double delta) const override; 156 float GetOffsetWithLimit(float offset) const override; 157 bool GetIsInViewInGroup(int32_t groupIndex, int32_t index); 158 static bool IsForwardStep(FocusStep step, bool isVertical, bool isDefault); 159 static bool IsBackwardStep(FocusStep step, bool isVertical, bool isDefault); 160 virtual void HandleScrollBarOutBoundary(); 161 GetFocusPattern()162 FocusPattern GetFocusPattern() const override 163 { 164 return { FocusType::SCOPE, true }; 165 } 166 167 ScopeFocusAlgorithm GetScopeFocusAlgorithm() override; 168 169 bool LayoutItemInGroupForFocus(int32_t indexInList, int32_t nextIndexInGroup, int32_t curIndexInGroup, 170 const ListItemGroupPara& listItemGroupPara, int32_t maxListItemIndex); 171 172 ScrollOffsetAbility GetScrollOffsetAbility() override; 173 174 std::function<bool(int32_t)> GetScrollIndexAbility() override; 175 176 bool ScrollToNode(const RefPtr<FrameNode>& focusFrameNode) override; 177 GetItemPosition()178 const ListLayoutAlgorithm::PositionMap& GetItemPosition() const 179 { 180 return itemPosition_; 181 } 182 GetTotalOffset()183 double GetTotalOffset() const override 184 { 185 return currentOffset_; 186 } 187 GetContentStartOffset()188 float GetContentStartOffset() const override 189 { 190 return contentStartOffset_; 191 } 192 GetPositionController()193 RefPtr<ScrollControllerBase> GetPositionController() const 194 { 195 return positionController_; 196 } 197 198 int32_t ProcessAreaVertical(double& x, double& y, Rect& groupRect, int32_t& index, 199 RefPtr<ListItemGroupPattern> groupItemPattern) const; 200 int32_t ProcessAreaHorizontal(double& x, double& y, Rect& groupRect, int32_t& index, 201 RefPtr<ListItemGroupPattern> groupItemPattern) const; 202 void TriggerModifyDone(); 203 204 float GetTotalHeight() const override; 205 206 // scroller 207 void ScrollTo(float position) override; 208 void ScrollToIndex(int32_t index, bool smooth = false, ScrollAlign align = ScrollAlign::START, 209 std::optional<float> extraOffset = std::nullopt) override; 210 void ScrollToItemInGroup(int32_t index, int32_t indexInGroup, bool smooth = false, 211 ScrollAlign align = ScrollAlign::START); 212 bool CheckTargetValid(int32_t index, int32_t indexInGroup); 213 void ScrollPage(bool reverse, bool smooth = false, 214 AccessibilityScrollType scrollType = AccessibilityScrollType::SCROLL_FULL) override; 215 void ScrollBy(float offset); 216 bool AnimateToTarget(int32_t index, std::optional<int32_t> indexInGroup, ScrollAlign align); 217 Offset GetCurrentOffset() const; 218 Rect GetItemRect(int32_t index) const override; 219 int32_t GetItemIndex(double x, double y) const override; 220 Rect GetItemRectInGroup(int32_t index, int32_t indexInGroup) const; 221 ListItemIndex GetItemIndexInGroup(double x, double y) const; 222 bool GetGroupItemIndex(double x, double y, RefPtr<FrameNode> itemFrameNode, int32_t& index, 223 ListItemIndex& itemIndex) const; 224 void OnAnimateStop() override; GetMainContentSize()225 float GetMainContentSize() const override 226 { 227 return contentMainSize_; 228 } GetLanes()229 int32_t GetLanes() const 230 { 231 return lanes_; 232 } 233 234 void CalculateCurrentOffset(float delta, const ListLayoutAlgorithm::PositionMap& recycledItemPosition); 235 void UpdatePosMap(const ListLayoutAlgorithm::PositionMap& itemPos); 236 void UpdateScrollBarOffset() override; IsNeedAddContentOffset(bool isContentLessThanSize)237 virtual bool IsNeedAddContentOffset(bool isContentLessThanSize) 238 { 239 return !IsScrollSnapAlignCenter() || childrenSize_; 240 } 241 // chain animation 242 void SetChainAnimation(); 243 void SetChainAnimationOptions(const ChainAnimationOptions& options); 244 void SetFocusWrapMode(FocusWrapMode focusWrapMode); 245 FocusWrapMode GetFocusWrapMode() const; 246 float FlushChainAnimation(float dragOffset); 247 void ProcessDragStart(float startPosition); 248 void ProcessDragUpdate(float dragOffset, int32_t source); 249 float GetChainDelta(int32_t index) const; 250 251 // multiSelectable SetMultiSelectable(bool multiSelectable)252 void SetMultiSelectable(bool multiSelectable) 253 { 254 multiSelectable_ = multiSelectable; 255 } 256 257 void SetSwiperItem(WeakPtr<ListItemPattern> swiperItem); GetSwiperItem()258 WeakPtr<ListItemPattern> GetSwiperItem() 259 { 260 if (!swiperItem_.Upgrade()) { 261 return nullptr; 262 } 263 return swiperItem_; 264 } SetSwiperItemEnd(WeakPtr<ListItemPattern> swiperItem)265 void SetSwiperItemEnd(WeakPtr<ListItemPattern> swiperItem) 266 { 267 if (swiperItem == swiperItem_) { 268 canReplaceSwiperItem_ = true; 269 } 270 } IsCurrentSwiperItem(WeakPtr<ListItemPattern> swiperItem)271 bool IsCurrentSwiperItem(WeakPtr<ListItemPattern> swiperItem) 272 { 273 if (!swiperItem_.Upgrade()) { 274 return true; 275 } 276 return swiperItem == swiperItem_; 277 } CanReplaceSwiperItem()278 bool CanReplaceSwiperItem() 279 { 280 auto listItemPattern = swiperItem_.Upgrade(); 281 if (!listItemPattern) { 282 canReplaceSwiperItem_ = true; 283 return canReplaceSwiperItem_; 284 } 285 auto host = listItemPattern->GetHost(); 286 if (!host || !host->IsOnMainTree()) { 287 canReplaceSwiperItem_ = true; 288 return canReplaceSwiperItem_; 289 } 290 return canReplaceSwiperItem_; 291 } 292 SetPredictSnapOffset(float predictSnapOffset)293 void SetPredictSnapOffset(float predictSnapOffset) 294 { 295 predictSnapOffset_ = predictSnapOffset; 296 } 297 298 bool StartSnapAnimation(SnapAnimationOptions snapAnimationOptions) override; 299 300 bool ScrollToSnapIndex(SnapDirection snapDirection, ScrollSnapAlign scrollSnapAlign); 301 302 int32_t GetEndIndexExcludeEndOffset(); 303 304 int32_t GetStartIndexExcludeStartOffset(); 305 306 void StartListSnapAnimation(float scrollSnapDelta, float scrollSnapVelocity); 307 GetSnapType()308 SnapType GetSnapType() override 309 { 310 auto snapAlign = GetScrollSnapAlign(); 311 return snapAlign != ScrollSnapAlign::NONE ? SnapType::LIST_SNAP : SnapType::NONE_SNAP; 312 } 313 314 ScrollSnapAlign GetScrollSnapAlign() const; 315 SetLastSnapTargetIndex(int32_t lastSnapTargetIndex)316 void SetLastSnapTargetIndex(int32_t lastSnapTargetIndex) override 317 { 318 lastSnapTargetIndex_ = lastSnapTargetIndex; 319 } 320 GetLastSnapTargetIndex()321 std::optional<int32_t> GetLastSnapTargetIndex() override 322 { 323 return lastSnapTargetIndex_; 324 } 325 ResetLastSnapTargetIndex()326 void ResetLastSnapTargetIndex() override 327 { 328 lastSnapTargetIndex_.reset(); 329 } 330 331 int32_t GetItemIndexByPosition(float xOffset, float yOffset); 332 SetPredictLayoutParamV2(std::optional<ListPredictLayoutParamV2> param)333 void SetPredictLayoutParamV2(std::optional<ListPredictLayoutParamV2> param) 334 { 335 predictLayoutParamV2_ = param; 336 } 337 GetPredictLayoutParamV2()338 std::optional<ListPredictLayoutParamV2> GetPredictLayoutParamV2() const 339 { 340 return predictLayoutParamV2_; 341 } 342 343 void CloseAllSwipeActions(OnFinishFunc&&); 344 345 std::string ProvideRestoreInfo() override; 346 void OnRestoreInfo(const std::string& restoreInfo) override; 347 void DumpAdvanceInfo() override; 348 void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override; 349 void GetEventDumpInfo() override; 350 void GetEventDumpInfo(std::unique_ptr<JsonValue>& json) override; 351 SetNeedToUpdateListDirectionInCardStyle(bool isNeedToUpdateListDirection)352 void SetNeedToUpdateListDirectionInCardStyle(bool isNeedToUpdateListDirection) 353 { 354 isNeedToUpdateListDirection_ = isNeedToUpdateListDirection; 355 } 356 IsNeedToUpdateListDirectionInCardStyle()357 bool IsNeedToUpdateListDirectionInCardStyle() const 358 { 359 return isNeedToUpdateListDirection_; 360 } 361 362 std::vector<RefPtr<FrameNode>> GetVisibleSelectedItems() override; 363 SetItemPressed(bool isPressed,int32_t id)364 void SetItemPressed(bool isPressed, int32_t id) 365 { 366 if (isPressed) { 367 pressedItem_.emplace(id); 368 } else { 369 pressedItem_.erase(id); 370 } 371 } 372 373 RefPtr<ListChildrenMainSize> GetOrCreateListChildrenMainSize(); 374 void SetListChildrenMainSize(float defaultSize, const std::vector<float>& mainSize); 375 virtual void OnChildrenSizeChanged(std::tuple<int32_t, int32_t, int32_t> change, ListChangeFlag flag); 376 void ResetChildrenSize(); ListChildrenSizeExist()377 bool ListChildrenSizeExist() 378 { 379 return static_cast<bool>(childrenSize_); 380 } 381 void UpdateChildPosInfo(int32_t index, float delta, float sizeChange); 382 383 SizeF GetChildrenExpandedSize() override; 384 GetItemStartIndex()385 inline int32_t GetItemStartIndex() 386 { 387 return itemStartIndex_; 388 } 389 ResetFocusIndex()390 void ResetFocusIndex() 391 { 392 focusIndex_.reset(); 393 } 394 SetFocusIndex(int32_t index)395 void SetFocusIndex(int32_t index) 396 { 397 focusIndex_ = index; 398 } 399 ResetGroupFocusIndex()400 void ResetGroupFocusIndex() 401 { 402 focusGroupIndex_.reset(); 403 } 404 SetGroupFocusIndex(int32_t index)405 void SetGroupFocusIndex(int32_t index) 406 { 407 focusGroupIndex_ = index; 408 } 409 GetFocusIndex()410 std::optional<int32_t> GetFocusIndex() const 411 { 412 return focusIndex_; 413 } 414 415 void UpdateGroupFocusIndexForDataChange(int32_t groupIndexInList, int32_t indexInGroup, int32_t count); 416 bool CheckFocusOnHeaderOrFooter(const RefPtr<FocusHub>& childFocusHub); 417 void AdjustFocusGroupIndex(int32_t index, int32_t& indexInGroup); 418 419 void FireFocusInListItemGroup(int32_t groupIndexInList); 420 ResetGroupIndexChanged()421 void ResetGroupIndexChanged() 422 { 423 groupIndexChanged_ = false; 424 } 425 SetGroupIndexChanged(bool groupIndexChanged)426 void SetGroupIndexChanged(bool groupIndexChanged) 427 { 428 groupIndexChanged_ = groupIndexChanged; 429 } ResetGroupIndexInView()430 void ResetGroupIndexInView() 431 { 432 groupIndexInView_ = true; 433 } 434 SetGroupIndexInView(bool groupIndexInView)435 void SetGroupIndexInView(bool groupIndexInView) 436 { 437 groupIndexInView_ = groupIndexInView; 438 } 439 SetIsNeedDividerAnimation(bool isNeedDividerAnimation)440 void SetIsNeedDividerAnimation(bool isNeedDividerAnimation) 441 { 442 isNeedDividerAnimation_ = isNeedDividerAnimation; 443 } 444 IsStackFromEnd()445 bool IsStackFromEnd() const 446 { 447 return isStackFromEnd_; 448 } 449 SetRepeatDifference(int32_t repeatDifference)450 void SetRepeatDifference(int32_t repeatDifference) 451 { 452 repeatDifference_ = repeatDifference; 453 } 454 455 bool IsOutOfBoundary(bool useCurrentDelta = true) override; 456 void OnColorModeChange(uint32_t colorMode) override; 457 void UpdateDefaultColor(); 458 SetDraggingIndex(int32_t index)459 void SetDraggingIndex(int32_t index) 460 { 461 draggingIndex_ = index; 462 } 463 bool LayoutListForFocus(int32_t nextIndex, std::optional<int32_t> indexInGroup); 464 465 protected: 466 void OnModifyDone() override; 467 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 468 virtual bool ScrollListForFocus(int32_t nextIndex, int32_t curIndex, int32_t nextIndexInGroup); 469 virtual void AdjustScrollPosition(int32_t nextIndex, int32_t curIndex); 470 void MarkDirtyNodeSelf(); 471 472 bool OnScrollCallback(float offset, int32_t source) override; 473 void SetEdgeEffectCallback(const RefPtr<ScrollEdgeEffect>& scrollEffect) override; 474 void SetChainAnimationToPosMap(); 475 void SetChainAnimationLayoutAlgorithm( 476 RefPtr<ListLayoutAlgorithm> listLayoutAlgorithm, const RefPtr<ListLayoutProperty>& listLayoutProperty); 477 478 virtual void OnScrollVisibleContentChange(const RefPtr<ListEventHub>& listEventHub, bool indexChanged); 479 virtual float GetScrollUpdateFriction(float overScroll); GetScrollToNodeAlign()480 virtual ScrollAlign GetScrollToNodeAlign() 481 { 482 return ScrollAlign::AUTO; 483 } 484 virtual void OnMidIndexChanged(); 485 virtual float GetStartOverScrollOffset(float offset, float startMainPos) const; 486 virtual float GetEndOverScrollOffset(float offset, float endMainPos, float startMainPos) const; 487 void SetLayoutAlgorithmParams( 488 const RefPtr<ListLayoutAlgorithm>& listLayoutAlgorithm, const RefPtr<ListLayoutProperty>& listLayoutProperty); 489 bool GetFadingEdge(RefPtr<ScrollablePaintProperty>& paintProperty); 490 491 bool isFadingEdge_ = false; 492 int32_t maxListItemIndex_ = 0; 493 int32_t startIndex_ = -1; 494 int32_t endIndex_ = -1; 495 int32_t centerIndex_ = -1; 496 float startMainPos_ = 0.0f; 497 float endMainPos_ = 0.0f; 498 float spaceWidth_ = 0.0f; 499 float contentMainSize_ = 0.0f; 500 float contentStartOffset_ = 0.0f; 501 float contentEndOffset_ = 0.0f; 502 503 float currentDelta_ = 0.0f; 504 bool smooth_ = false; 505 506 std::optional<int32_t> jumpIndex_; 507 std::optional<int32_t> targetIndex_; 508 std::optional<float> predictSnapOffset_; 509 std::optional<float> predictSnapEndPos_; 510 ScrollAlign scrollAlign_ = ScrollAlign::START; 511 bool isNeedCheckOffset_ = false; 512 bool isScrollable_ = true; 513 514 ListLayoutAlgorithm::PositionMap itemPosition_; 515 RefPtr<ListPositionMap> posMap_; 516 RefPtr<ListChildrenMainSize> childrenSize_; 517 518 RefPtr<ChainAnimation> chainAnimation_; 519 520 RefPtr<Scrollable> scrollable_; 521 KeyEvent keyEvent_; 522 523 int32_t itemStartIndex_ = 0; 524 float scrollSnapVelocity_ = 0.0f; 525 bool isStackFromEnd_ = true; 526 FocusWrapMode focusWrapMode_ = FocusWrapMode::DEFAULT; 527 private: 528 void CheckAndUpdateAnimateTo(float relativeOffset, float prevOffset); 529 void ResetScrollToIndexParams(); 530 void OnScrollEndCallback() override; 531 void FireOnReachStart(const OnReachEvent& onReachStart, const OnReachEvent& onJSFrameNodeReachStart) override; 532 void FireOnReachEnd(const OnReachEvent& onReachEnd, const OnReachEvent& onJSFrameNodeReachEnd) override; 533 void FireOnScrollIndex(bool indexChanged, const OnScrollIndexEvent& onScrollIndex); 534 void ChangeAxis(RefPtr<UINode> node); 535 bool HandleTargetIndex(bool isJump); 536 float CalculateTargetPos(float startPos, float endPos); 537 bool CheckDataChangeOutOfStart(int32_t index, int32_t count, int32_t startIndex, int32_t endIndex); 538 bool JudgeCanOverScrollStart(); 539 bool JudgeCanOverScrollEnd(); 540 541 void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub); 542 bool OnKeyEvent(const KeyEvent& event); 543 bool HandleDirectionKey(const KeyEvent& event); 544 WeakPtr<FocusHub> GetNextFocusNode(FocusStep step, const WeakPtr<FocusHub>& currentFocusNode); 545 WeakPtr<FocusHub> GetChildFocusNodeByIndex(int32_t tarMainIndex, int32_t tarGroupIndex); 546 WeakPtr<FocusHub> ScrollAndFindFocusNode(int32_t nextIndex, int32_t curIndex, int32_t& nextIndexInGroup, 547 int32_t curIndexInGroup, int32_t moveStep, FocusStep step); 548 bool HandleDisplayedChildFocus(int32_t nextIndex, int32_t curIndex); 549 bool ScrollListItemGroupForFocus(int32_t nextIndex, int32_t curIndex, int32_t& nextIndexInGroup, 550 int32_t curIndexInGroup, int32_t moveStep, FocusStep step, bool isScrollIndex); 551 ScrollAlign CalcAlignForFocusToGroupItem(int32_t moveStep, FocusStep step) const; 552 int32_t CalcNextIndexInGroup(int32_t nextIndex, int32_t curIndex, int32_t curIndexInGroup, int32_t moveStep, 553 ListItemGroupPara& nextListItemGroupPara) const; 554 void VerifyFocusIndex(int32_t& nextIndex, int32_t& nextIndexInGroup, const ListItemGroupPara& param); 555 int32_t GetNextLineFocusIndex(int32_t currIndex); 556 557 SizeF GetContentSize() const; 558 void ProcessEvent(bool indexChanged, float finalOffset, bool isJump); 559 void FireOnScrollWithVersionCheck(float finalOffset, OnScrollEvent& onScroll); 560 void CheckScrollable(); 561 void HandleScrollEffect(float offset); 562 void StartDefaultOrCustomSpringMotion(float start, float end, const RefPtr<InterpolatingSpring>& curve); 563 bool IsScrollSnapAlignCenter() const; 564 void SetLayoutAlgorithmJumpAlign( 565 const RefPtr<ListLayoutAlgorithm>& listLayoutAlgorithm, const RefPtr<ListLayoutProperty>& listLayoutProperty); 566 void SetLayoutAlgorithmSnapParam(const RefPtr<ListLayoutAlgorithm>& listLayoutAlgorithm); 567 void SetChainAnimationCallback(); 568 bool NeedScrollSnapAlignEffect() const; 569 ScrollAlign GetInitialScrollAlign() const; 570 bool GetListItemAnimatePos(float startPos, float endPos, ScrollAlign align, float& targetPos); 571 bool GetListItemGroupAnimatePosWithoutIndexInGroup(int32_t index, float startPos, float endPos, 572 ScrollAlign align, float& targetPos); 573 bool GetListItemGroupAnimatePosWithIndexInGroup(int32_t index, int32_t indexInGroup, float startPos, 574 ScrollAlign align, float& targetPos); 575 576 // multiSelectable 577 void ClearMultiSelect() override; 578 bool IsItemSelected(float offsetX, float offsetY) override; 579 void MultiSelectWithoutKeyboard(const RectF& selectedZone) override; 580 void HandleCardModeSelectedEvent( 581 const RectF& selectedZone, const RefPtr<FrameNode>& itemGroupNode, const OffsetF& groupOffset); 582 583 // focus 584 bool IsLayout(int32_t index, std::optional<int32_t> indexInGroup, ScrollAlign align); 585 int32_t GetNextMoveStepForMultiLanes(int32_t curIndex, FocusStep focuseStep, bool isVertical, int32_t& nextIndex); 586 WeakPtr<FocusHub> GetNextFocusNodeInList(FocusStep step, const WeakPtr<FocusHub>& currentFocusNode); 587 bool IsListItemGroupByIndex(int32_t index); 588 WeakPtr<FocusHub> FindChildFocusNodeByIndex(int32_t tarMainIndex, const FocusStep& step, int32_t curFocusIndex); 589 void DetermineSingleLaneStep( 590 FocusStep step, bool isVertical, int32_t curIndex, int32_t& moveStep, int32_t& nextIndex); 591 void DetermineMultiLaneStep( 592 FocusStep step, bool isVertical, int32_t curIndex, int32_t& moveStep, int32_t& nextIndex); 593 int32_t GetCurrentFocusIndex(const RefPtr<Pattern>& curPattern); 594 void AdjustFocusStepForRtl(FocusStep& step, bool isVertical); 595 int32_t GetCrossAxisNextIndex(int32_t curIndex, bool isVertical, int32_t moveStep, FocusStep step); 596 const ListItemInfo* GetPosition(int32_t index) const; 597 bool NextPositionBlocksMove(const ListItemInfo* curPos, const ListItemInfo* nextPos, bool isVertical) const; 598 int32_t AdjustNextIndexForEdgeRow(int32_t nextIndex, int32_t moveStep, int32_t curIndex); 599 bool IsListItem(const WeakPtr<FocusHub>& focusNode); 600 void HandleIndexToBounds(int32_t& nextIndex, bool& loopFlag); 601 602 void DrivenRender(const RefPtr<LayoutWrapper>& layoutWrapper); 603 ListItemGroupPara GetListItemGroupParameter(const RefPtr<FrameNode>& node); 604 bool IsListItemGroup(int32_t listIndex, RefPtr<FrameNode>& node); 605 void GetListItemGroupEdge(bool& groupAtStart, bool& groupAtEnd) const; 606 void RefreshLanesItemRange(); 607 void UpdateListDirectionInCardStyle(); 608 bool UpdateStartListItemIndex(); 609 bool UpdateEndListItemIndex(); 610 bool CalculateJumpOffset(); 611 float UpdateTotalOffset(const RefPtr<ListLayoutAlgorithm>& listLayoutAlgorithm, bool isJump); 612 RefPtr<ListContentModifier> listContentModifier_; 613 void CreatePositionInfo(std::unique_ptr<JsonValue>& json); 614 void ReportOnItemListEvent(const std::string& event); 615 void ReportOnItemListScrollEvent(const std::string& event, int32_t startindex, int32_t endindex); 616 int32_t OnInjectionEvent(const std::string& command) override; 617 bool ScrollToLastFocusIndex(const KeyEvent& event); 618 bool UpdateStartIndex(int32_t index, int32_t indexInGroup = -1); 619 bool IsInViewport(int32_t index) const; 620 void HandleFocusParentCheck(const RefPtr<FocusHub>& childFocusHub, const RefPtr<FocusHub>& focusHub); 621 void FireFocus(); 622 bool CheckValidInList(int32_t index); 623 void ProcessFocusEvent(bool indexChanged); 624 void RequestFocusForItem(int32_t index, int32_t indexInGroup); 625 RefPtr<FocusHub> GetChildFocusHubInGroup(int32_t indexInList, int32_t indexInListItemGroup) const; 626 void ResetForExtScroll() override; 627 628 std::optional<int32_t> focusIndex_; 629 std::optional<int32_t> focusGroupIndex_; 630 float prevStartOffset_ = 0.f; 631 float prevEndOffset_ = 0.f; 632 double currentOffset_ = 0.0f; 633 bool maintainVisibleContentPosition_ = false; 634 std::optional<int32_t> lastSnapTargetIndex_; 635 636 bool crossMatchChild_ = false; 637 bool snapTrigOnScrollStart_ = false; 638 bool snapTrigByScrollBar_ = false; 639 bool groupIndexChanged_ = false; 640 bool groupIndexInView_ = true; 641 642 std::optional<int32_t> jumpIndexInGroup_; 643 std::optional<int32_t> targetIndexInGroup_; 644 std::optional<bool> isLayoutListForFocus_; // Flag for only do Layout. 645 std::optional<ListScrollTarget> scrollTarget_; 646 bool paintStateFlag_ = false; 647 bool isFramePaintStateValid_ = false; 648 649 ListLayoutAlgorithm::PositionMap cachedItemPosition_; 650 float listTotalHeight_ = 0.0f; 651 652 std::map<int32_t, int32_t> lanesItemRange_; 653 std::set<int32_t> pressedItem_; 654 int32_t lanes_ = 1; 655 int32_t laneIdx4Divider_ = 0; 656 float laneGutter_ = 0.0f; 657 bool dragFromSpring_ = false; 658 RefPtr<SpringProperty> springProperty_; 659 std::optional<ChainAnimationOptions> chainAnimationOptions_; 660 661 bool isOritationListenerRegisted_ = false; 662 663 // ListItem swiperAction 664 WeakPtr<ListItemPattern> swiperItem_; 665 bool canReplaceSwiperItem_ = true; 666 667 RefPtr<SpringMotion> scrollToIndexMotion_; 668 RefPtr<SpringMotion> scrollSnapMotion_; 669 670 bool isScrollEnd_ = false; 671 bool needReEstimateOffset_ = false; 672 std::optional<ListPredictLayoutParamV2> predictLayoutParamV2_; 673 674 bool isNeedToUpdateListDirection_ = false; 675 bool startIndexChanged_ = false; 676 bool endIndexChanged_ = false; 677 678 ListItemIndex startInfo_ = {-1, -1, -1}; 679 ListItemIndex endInfo_ = {-1, -1, -1}; 680 bool isNeedDividerAnimation_ = true; 681 int32_t repeatDifference_ = 0; 682 683 bool prevMeasureBreak_ = false; 684 int32_t draggingIndex_ = -1; 685 bool heightEstimated_ = false; 686 }; 687 } // namespace OHOS::Ace::NG 688 689 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_PATTERN_H 690