1 /* 2 * Copyright (c) 2022-2024 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_SWIPER_SWIPER_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_SWIPER_PATTERN_H 18 19 #include <functional> 20 #include <optional> 21 #include <vector> 22 23 #include "base/geometry/axis.h" 24 #include "base/geometry/ng/offset_t.h" 25 #include "base/memory/referenced.h" 26 #include "core/components/common/layout/constants.h" 27 #include "core/components/swiper/swiper_controller.h" 28 #include "core/components/swiper/swiper_indicator_theme.h" 29 #include "core/components_ng/base/frame_node.h" 30 #include "core/components_ng/base/frame_scene_status.h" 31 #include "core/components_ng/base/inspector_filter.h" 32 #include "core/components_ng/event/event_hub.h" 33 #include "core/components_ng/event/input_event.h" 34 #include "core/components_ng/pattern/pattern.h" 35 #include "core/components_ng/pattern/scrollable/nestable_scroll_container.h" 36 #include "core/components_ng/pattern/swiper/swiper_accessibility_property.h" 37 #include "core/components_ng/pattern/swiper/swiper_event_hub.h" 38 #include "core/components_ng/pattern/swiper/swiper_layout_algorithm.h" 39 #include "core/components_ng/pattern/swiper/swiper_layout_property.h" 40 #include "core/components_ng/pattern/swiper/swiper_model.h" 41 #include "core/components_ng/pattern/swiper/swiper_paint_property.h" 42 #include "core/components_ng/pattern/swiper/swiper_utils.h" 43 #include "core/components_ng/pattern/tabs/tab_content_transition_proxy.h" 44 #include "core/components_v2/inspector/utils.h" 45 46 namespace OHOS::Ace::NG { 47 enum class PageFlipMode { 48 CONTINUOUS = 0, 49 SINGLE, 50 }; 51 52 using SwiperHoverFlag = uint32_t; 53 constexpr SwiperHoverFlag HOVER_NONE = 0; 54 constexpr SwiperHoverFlag HOVER_SWIPER = 1; 55 constexpr SwiperHoverFlag HOVER_INDICATOR = 1 << 1; 56 constexpr SwiperHoverFlag HOVER_ARROW = 1 << 2; 57 58 class SwiperPattern : public NestableScrollContainer { 59 DECLARE_ACE_TYPE(SwiperPattern, NestableScrollContainer); 60 61 public: 62 using CustomContentTransitionPtr = std::shared_ptr<std::function<TabContentAnimatedTransition(int32_t, int32_t)>>; 63 64 SwiperPattern(); 65 ~SwiperPattern() override = default; 66 IsAtomicNode()67 bool IsAtomicNode() const override 68 { 69 return false; 70 } 71 IsNeedPercent()72 bool IsNeedPercent() const override 73 { 74 return true; 75 } 76 ShouldDelayChildPressedState()77 bool ShouldDelayChildPressedState() const override 78 { 79 return true; 80 } 81 82 void RegisterScrollingListener(const RefPtr<ScrollingListener> listener) override; 83 void FireAndCleanScrollingListener() override; 84 void CleanScrollingListener() override; 85 UsResRegion()86 bool UsResRegion() override 87 { 88 return false; 89 } 90 CreateLayoutProperty()91 RefPtr<LayoutProperty> CreateLayoutProperty() override 92 { 93 return MakeRefPtr<SwiperLayoutProperty>(); 94 } 95 CreatePaintProperty()96 RefPtr<PaintProperty> CreatePaintProperty() override 97 { 98 return MakeRefPtr<SwiperPaintProperty>(); 99 } 100 CreateAccessibilityProperty()101 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 102 { 103 return MakeRefPtr<SwiperAccessibilityProperty>(); 104 } 105 106 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override; 107 108 RefPtr<NodePaintMethod> CreateNodePaintMethod() override; 109 CreateEventHub()110 RefPtr<EventHub> CreateEventHub() override 111 { 112 return MakeRefPtr<SwiperEventHub>(); 113 } 114 115 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 116 void FromJson(const std::unique_ptr<JsonValue>& json) override; 117 GetCurrentShownIndex()118 int32_t GetCurrentShownIndex() const 119 { 120 return IsLoop() ? currentIndex_ : GetLoopIndex(currentIndex_); 121 } 122 GetSwiperController()123 RefPtr<SwiperController> GetSwiperController() const 124 { 125 return swiperController_; 126 } 127 128 void SetSwiperController(const RefPtr<SwiperController>& controller); 129 GetCurrentFirstIndex()130 int32_t GetCurrentFirstIndex() const 131 { 132 return currentFirstIndex_; 133 } 134 GetCurrentIndex()135 int32_t GetCurrentIndex() 136 { 137 return GetLoopIndex(currentIndex_); 138 } 139 GetTurnPageRate()140 float GetTurnPageRate() const 141 { 142 return turnPageRate_; 143 } 144 145 GestureState GetGestureState(); 146 GetTouchBottomTypeLoop()147 TouchBottomTypeLoop GetTouchBottomTypeLoop() const 148 { 149 return touchBottomType_; 150 } 151 IsIndicatorAnimatorRunning()152 bool IsIndicatorAnimatorRunning() const 153 { 154 return indicatorAnimationIsRunning_; 155 } 156 SetTurnPageRate(float turnPageRate)157 void SetTurnPageRate(float turnPageRate) 158 { 159 turnPageRate_ = turnPageRate; 160 } 161 GetTouchBottomRate()162 float GetTouchBottomRate() const 163 { 164 return touchBottomRate_; 165 } 166 SetTouchBottomRate(float touchBottomRate)167 void SetTouchBottomRate(float touchBottomRate) 168 { 169 touchBottomRate_ = touchBottomRate; 170 } 171 GetController()172 RefPtr<Animator> GetController() 173 { 174 return controller_; 175 } 176 SetIndicatorDoingAnimation(bool indicatorDoingAnimation)177 void SetIndicatorDoingAnimation(bool indicatorDoingAnimation) 178 { 179 indicatorDoingAnimation_ = indicatorDoingAnimation; 180 } 181 182 void UpdateCurrentOffset(float offset); 183 /** 184 * @brief Checks if the given offset exceeds the bounds of the swiper container and triggers overScroll. 185 * 186 * @param offset The offset to check. 187 * @return True if overScroll is triggered, false otherwise. 188 */ 189 bool CheckOverScroll(float offset); 190 191 /** 192 * @brief Applies spring effect to the over-scrolling of the swiper. 193 * 194 * @param offset The offset of the swiper. 195 * @return true if the spring effect is applied successfully, false otherwise. 196 */ 197 bool SpringOverScroll(float offset); 198 199 void CheckMarkDirtyNodeForRenderIndicator( 200 float additionalOffset = 0.0f, std::optional<int32_t> nextIndex = std::nullopt); 201 202 int32_t TotalCount() const; 203 204 Axis GetDirection() const; 205 GetFocusPattern()206 FocusPattern GetFocusPattern() const override 207 { 208 return { FocusType::SCOPE, true }; 209 } 210 GetScopeFocusAlgorithm()211 ScopeFocusAlgorithm GetScopeFocusAlgorithm() override 212 { 213 return ScopeFocusAlgorithm(direction_ != Axis::HORIZONTAL, true, ScopeType::OTHERS, 214 [wp = WeakClaim(this)]( 215 FocusStep step, const WeakPtr<FocusHub>& currFocusNode, WeakPtr<FocusHub>& nextFocusNode) -> bool { 216 auto swiper = wp.Upgrade(); 217 if (swiper) { 218 nextFocusNode = swiper->GetNextFocusNode(step, currFocusNode); 219 } 220 return nextFocusNode.Upgrade() != currFocusNode.Upgrade(); 221 }); 222 } 223 UpdateChangeEvent(ChangeEvent && event)224 void UpdateChangeEvent(ChangeEvent&& event) 225 { 226 if (!changeEvent_) { 227 changeEvent_ = std::make_shared<ChangeEvent>(event); 228 auto eventHub = GetEventHub<SwiperEventHub>(); 229 CHECK_NULL_VOID(eventHub); 230 eventHub->AddOnChangeEvent(changeEvent_); 231 } else { 232 (*changeEvent_).swap(event); 233 } 234 } 235 UpdateOnChangeEvent(ChangeEvent && event)236 void UpdateOnChangeEvent(ChangeEvent&& event) 237 { 238 if (!onIndexChangeEvent_) { 239 onIndexChangeEvent_ = std::make_shared<ChangeEvent>(event); 240 auto eventHub = GetEventHub<SwiperEventHub>(); 241 CHECK_NULL_VOID(eventHub); 242 eventHub->AddOnChangeEvent(onIndexChangeEvent_); 243 } else { 244 (*onIndexChangeEvent_).swap(event); 245 } 246 } 247 UpdateAnimationStartEvent(AnimationStartEvent && event)248 void UpdateAnimationStartEvent(AnimationStartEvent&& event) 249 { 250 if (!animationStartEvent_) { 251 animationStartEvent_ = std::make_shared<AnimationStartEvent>(event); 252 auto eventHub = GetEventHub<SwiperEventHub>(); 253 CHECK_NULL_VOID(eventHub); 254 eventHub->AddAnimationStartEvent(animationStartEvent_); 255 } else { 256 (*animationStartEvent_).swap(event); 257 } 258 } 259 UpdateAnimationEndEvent(AnimationEndEvent && event)260 void UpdateAnimationEndEvent(AnimationEndEvent&& event) 261 { 262 if (!animationEndEvent_) { 263 animationEndEvent_ = std::make_shared<AnimationEndEvent>(event); 264 auto eventHub = GetEventHub<SwiperEventHub>(); 265 CHECK_NULL_VOID(eventHub); 266 eventHub->AddAnimationEndEvent(animationEndEvent_); 267 } else { 268 (*animationEndEvent_).swap(event); 269 } 270 } 271 SetSwiperParameters(const SwiperParameters & swiperParameters)272 void SetSwiperParameters(const SwiperParameters& swiperParameters) 273 { 274 swiperParameters_ = std::make_shared<SwiperParameters>(swiperParameters); 275 } 276 SetSwiperDigitalParameters(const SwiperDigitalParameters & swiperDigitalParameters)277 void SetSwiperDigitalParameters(const SwiperDigitalParameters& swiperDigitalParameters) 278 { 279 swiperDigitalParameters_ = std::make_shared<SwiperDigitalParameters>(swiperDigitalParameters); 280 } 281 282 void ShowNext(bool needCheckWillScroll = false); 283 void ShowPrevious(bool needCheckWillScroll = false); 284 void SwipeTo(int32_t index); 285 void ChangeIndex(int32_t index, bool useAnimation); 286 void ChangeIndex(int32_t index, SwiperAnimationMode mode); 287 288 void OnVisibleChange(bool isVisible) override; 289 GetStartIndex()290 int32_t GetStartIndex() const 291 { 292 return startIndex_; 293 } 294 GetEndIndex()295 int32_t GetEndIndex() const 296 { 297 return endIndex_; 298 } 299 HasIndicatorNode()300 bool HasIndicatorNode() const 301 { 302 return indicatorId_.has_value() || GetIndicatorNode() != nullptr; 303 } 304 HasLeftButtonNode()305 bool HasLeftButtonNode() const 306 { 307 return leftButtonId_.has_value(); 308 } 309 HasRightButtonNode()310 bool HasRightButtonNode() const 311 { 312 return rightButtonId_.has_value(); 313 } 314 GetIndicatorId()315 int32_t GetIndicatorId() 316 { 317 if (!indicatorId_.has_value()) { 318 indicatorId_ = ElementRegister::GetInstance()->MakeUniqueId(); 319 } 320 return indicatorId_.value(); 321 } 322 GetLeftButtonId()323 int32_t GetLeftButtonId() 324 { 325 if (!leftButtonId_.has_value()) { 326 leftButtonId_ = ElementRegister::GetInstance()->MakeUniqueId(); 327 } 328 return leftButtonId_.value(); 329 } 330 GetRightButtonId()331 int32_t GetRightButtonId() 332 { 333 if (!rightButtonId_.has_value()) { 334 rightButtonId_ = ElementRegister::GetInstance()->MakeUniqueId(); 335 } 336 return rightButtonId_.value(); 337 } 338 RemoveIndicatorNode()339 void RemoveIndicatorNode() 340 { 341 CHECK_NULL_VOID(HasIndicatorNode()); 342 auto swiperNode = GetHost(); 343 CHECK_NULL_VOID(swiperNode); 344 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetIndicatorId())); 345 indicatorId_ = std::nullopt; 346 } 347 RemoveLeftButtonNode()348 void RemoveLeftButtonNode() 349 { 350 CHECK_NULL_VOID(HasLeftButtonNode()); 351 auto swiperNode = GetHost(); 352 CHECK_NULL_VOID(swiperNode); 353 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetLeftButtonId())); 354 leftButtonId_ = std::nullopt; 355 } 356 RemoveRightButtonNode()357 void RemoveRightButtonNode() 358 { 359 CHECK_NULL_VOID(HasRightButtonNode()); 360 auto swiperNode = GetHost(); 361 CHECK_NULL_VOID(swiperNode); 362 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetRightButtonId())); 363 rightButtonId_ = std::nullopt; 364 } 365 366 SwiperIndicatorType GetIndicatorType() const; 367 IsIndicatorCustomSize()368 bool IsIndicatorCustomSize() const 369 { 370 return isCustomSize_; 371 } 372 SetIsIndicatorCustomSize(bool isCustomSize)373 void SetIsIndicatorCustomSize(bool isCustomSize) 374 { 375 isCustomSize_ = isCustomSize; 376 } 377 SetIndicatorIsBoolean(bool isBoolean)378 void SetIndicatorIsBoolean(bool isBoolean) 379 { 380 indicatorIsBoolean_ = isBoolean; 381 } 382 GetIsAtHotRegion()383 bool GetIsAtHotRegion() const 384 { 385 return isAtHotRegion_; 386 } 387 HasSurfaceChangedCallback()388 bool HasSurfaceChangedCallback() 389 { 390 return surfaceChangedCallbackId_.has_value(); 391 } 392 UpdateSurfaceChangedCallbackId(int32_t id)393 void UpdateSurfaceChangedCallbackId(int32_t id) 394 { 395 surfaceChangedCallbackId_ = id; 396 } 397 SetIndicatorLongPress(bool isIndicatorLongPress)398 void SetIndicatorLongPress(bool isIndicatorLongPress) 399 { 400 isIndicatorLongPress_ = isIndicatorLongPress; 401 } SetCachedCount(int32_t cachedCount)402 void SetCachedCount(int32_t cachedCount) 403 { 404 if (cachedCount_.has_value() && cachedCount_.value() != cachedCount) { 405 SetLazyLoadFeature(true); 406 } 407 cachedCount_ = cachedCount; 408 } 409 SetFinishCallbackType(FinishCallbackType finishCallbackType)410 void SetFinishCallbackType(FinishCallbackType finishCallbackType) 411 { 412 finishCallbackType_ = finishCallbackType; 413 } 414 GetFinishCallbackType()415 FinishCallbackType GetFinishCallbackType() const 416 { 417 return finishCallbackType_; 418 } 419 SetStopIndicatorAnimationCb(const std::function<void (bool)> & stopCallback)420 void SetStopIndicatorAnimationCb(const std::function<void(bool)>& stopCallback) 421 { 422 stopIndicatorAnimationFunc_ = std::move(stopCallback); 423 } 424 425 std::shared_ptr<SwiperParameters> GetSwiperParameters() const; 426 std::shared_ptr<SwiperDigitalParameters> GetSwiperDigitalParameters() const; 427 428 void ArrowHover(bool isHover, SwiperHoverFlag flag); IsHoverNone()429 bool IsHoverNone() 430 { 431 return hoverFlag_ == HOVER_NONE; 432 } 433 bool IsLoop() const; 434 bool IsEnabled() const; 435 void OnWindowShow() override; 436 void OnWindowHide() override; 437 std::string ProvideRestoreInfo() override; 438 void OnRestoreInfo(const std::string& restoreInfo) override; 439 bool IsAutoFill() const; 440 void SwipeToWithoutAnimation(int32_t index); 441 void StopAutoPlay(); 442 void StartAutoPlay(); 443 void StopTranslateAnimation(); 444 void StopSpringAnimationImmediately(); 445 void StopSpringAnimation(); 446 void DumpAdvanceInfo() override; 447 int32_t GetLoopIndex(int32_t originalIndex) const; 448 int32_t GetDuration() const; 449 void UpdateDragFRCSceneInfo(float speed, SceneStatus sceneStatus); 450 void AdjustCurrentIndexOnSwipePage(int32_t index); 451 void OnCustomContentTransition(int32_t toIndex); 452 void OnCustomAnimationFinish(int32_t fromIndex, int32_t toIndex, bool hasOnChanged); 453 void OnSwiperCustomAnimationFinish(CancelableCallback<void()>& task, int32_t index, bool isFinishAnimation); 454 SetCustomAnimationToIndex(int32_t toIndex)455 void SetCustomAnimationToIndex(int32_t toIndex) 456 { 457 customAnimationToIndex_ = toIndex; 458 } 459 GetCustomAnimationToIndex()460 std::optional<int32_t> GetCustomAnimationToIndex() const 461 { 462 return customAnimationToIndex_; 463 } 464 SetTabsCustomContentTransition(std::function<TabContentAnimatedTransition (int32_t,int32_t)> && event)465 void SetTabsCustomContentTransition(std::function<TabContentAnimatedTransition(int32_t, int32_t)>&& event) 466 { 467 onTabsCustomContentTransition_ = 468 std::make_shared<std::function<TabContentAnimatedTransition(int32_t, int32_t)>>(event); 469 } 470 GetTabsCustomContentTransition()471 CustomContentTransitionPtr GetTabsCustomContentTransition() const 472 { 473 return onTabsCustomContentTransition_; 474 } 475 SetSwiperCustomContentTransition(SwiperContentAnimatedTransition & transition)476 void SetSwiperCustomContentTransition(SwiperContentAnimatedTransition& transition) 477 { 478 onSwiperCustomContentTransition_ = std::make_shared<SwiperContentAnimatedTransition>(transition); 479 } 480 GetSwiperCustomContentTransition()481 std::shared_ptr<SwiperContentAnimatedTransition> GetSwiperCustomContentTransition() const 482 { 483 return onSwiperCustomContentTransition_; 484 } 485 SetOnContentDidScroll(ContentDidScrollEvent && onContentDidScroll)486 void SetOnContentDidScroll(ContentDidScrollEvent&& onContentDidScroll) 487 { 488 onContentDidScroll_ = std::make_shared<ContentDidScrollEvent>(onContentDidScroll); 489 } 490 SetOnContentWillScroll(ContentWillScrollEvent && onContentWillScroll)491 void SetOnContentWillScroll(ContentWillScrollEvent&& onContentWillScroll) 492 { 493 onContentWillScroll_ = std::make_shared<ContentWillScrollEvent>(onContentWillScroll); 494 } 495 HasOnContentWillScroll()496 bool HasOnContentWillScroll() const 497 { 498 return onContentWillScroll_ && *onContentWillScroll_; 499 } 500 GetOnContentDidScroll()501 std::shared_ptr<ContentDidScrollEvent> GetOnContentDidScroll() const 502 { 503 return onContentDidScroll_; 504 } 505 506 void SetSwiperEventCallback(bool disableSwipe); 507 void UpdateSwiperPanEvent(bool disableSwipe); 508 bool IsUseCustomAnimation() const; 509 SetTabsPaddingAndBorder(const PaddingPropertyF & tabsPaddingAndBorder)510 void SetTabsPaddingAndBorder(const PaddingPropertyF& tabsPaddingAndBorder) 511 { 512 tabsPaddingAndBorder_ = tabsPaddingAndBorder; 513 } 514 515 RefPtr<Curve> GetCurveIncludeMotion(); GetMotionVelocity()516 float GetMotionVelocity() 517 { 518 return motionVelocity_; 519 } 520 521 int32_t RealTotalCount() const; 522 bool IsSwipeByGroup() const; 523 int32_t GetDisplayCount() const; 524 int32_t GetCachedCount() const; 525 bool ContentWillChange(int32_t comingIndex); 526 bool ContentWillChange(int32_t currentIndex, int32_t comingIndex); 527 bool CheckSwiperPanEvent(float mainDeltaOrVelocity); InitIndexCanChangeMap()528 void InitIndexCanChangeMap() 529 { 530 indexCanChangeMap_.clear(); 531 } 532 GetNextValidIndex()533 int32_t GetNextValidIndex() const 534 { 535 return nextValidIndex_; 536 } 537 void UpdateNextValidIndex(); 538 void CheckMarkForIndicatorBoundary(); 539 bool IsHorizontalAndRightToLeft() const; 540 TextDirection GetNonAutoLayoutDirection() const; 541 void FireWillHideEvent(int32_t willHideIndex) const; 542 void FireWillShowEvent(int32_t willShowIndex) const; 543 void SetOnHiddenChangeForParent(); 544 void RemoveOnHiddenChange(); 545 SetHasTabsAncestor(bool hasTabsAncestor)546 void SetHasTabsAncestor(bool hasTabsAncestor) 547 { 548 hasTabsAncestor_ = hasTabsAncestor; 549 } 550 SetIndicatorInteractive(bool isInteractive)551 void SetIndicatorInteractive(bool isInteractive) 552 { 553 isIndicatorInteractive_ = isInteractive; 554 } 555 556 bool IsAtStart() const; 557 bool IsAtEnd() const; 558 IsIndicatorInteractive()559 bool IsIndicatorInteractive() const 560 { 561 return isIndicatorInteractive_; 562 } 563 SetNextMarginIgnoreBlank(bool nextMarginIgnoreBlank)564 void SetNextMarginIgnoreBlank(bool nextMarginIgnoreBlank) 565 { 566 nextMarginIgnoreBlank_ = nextMarginIgnoreBlank; 567 } 568 SetPrevMarginIgnoreBlank(bool prevMarginIgnoreBlank)569 void SetPrevMarginIgnoreBlank(bool prevMarginIgnoreBlank) 570 { 571 prevMarginIgnoreBlank_ = prevMarginIgnoreBlank; 572 } 573 SetFrameRateRange(const RefPtr<FrameRateRange> & rateRange,SwiperDynamicSyncSceneType type)574 void SetFrameRateRange(const RefPtr<FrameRateRange>& rateRange, SwiperDynamicSyncSceneType type) override 575 { 576 frameRateRange_[type] = rateRange; 577 } 578 void UpdateNodeRate(); 579 int32_t GetMaxDisplayCount() const; 580 GetPrevMarginIgnoreBlank()581 bool GetPrevMarginIgnoreBlank() 582 { 583 return prevMarginIgnoreBlank_; 584 } 585 GetNextMarginIgnoreBlank()586 bool GetNextMarginIgnoreBlank() 587 { 588 return nextMarginIgnoreBlank_; 589 } 590 GetCachedItems()591 const std::set<int32_t>& GetCachedItems() const 592 { 593 return cachedItems_; 594 } 595 SetCachedItems(const std::set<int32_t> & cachedItems)596 void SetCachedItems(const std::set<int32_t>& cachedItems) 597 { 598 cachedItems_ = cachedItems; 599 } 600 GetLayoutConstraint()601 LayoutConstraintF GetLayoutConstraint() const 602 { 603 return layoutConstraint_; 604 } 605 SetLayoutConstraint(const LayoutConstraintF & layoutConstraint)606 void SetLayoutConstraint(const LayoutConstraintF& layoutConstraint) 607 { 608 layoutConstraint_ = layoutConstraint; 609 } 610 GetRequestLongPredict()611 bool GetRequestLongPredict() const 612 { 613 return requestLongPredict_; 614 } 615 IsPropertyAnimationRunning()616 bool IsPropertyAnimationRunning() const 617 { 618 return usePropertyAnimation_; 619 } 620 IsTranslateAnimationRunning()621 bool IsTranslateAnimationRunning() const 622 { 623 return translateAnimationIsRunning_; 624 } 625 IsTouchDown()626 bool IsTouchDown() const 627 { 628 return isTouchDown_; 629 } 630 IsTouchDownOnOverlong()631 bool IsTouchDownOnOverlong() const 632 { 633 return isTouchDownOnOverlong_; 634 } IsBindIndicator()635 bool IsBindIndicator() const 636 { 637 return isBindIndicator_; 638 } 639 SetBindIndicator(bool bind)640 void SetBindIndicator(bool bind) 641 { 642 isBindIndicator_ = bind; 643 } 644 645 void SetIndicatorNode(const WeakPtr<NG::UINode>& indicatorNode); 646 GetIndicatorNode()647 RefPtr<FrameNode> GetIndicatorNode() const 648 { 649 auto refUINode = indicatorNode_.Upgrade(); 650 CHECK_NULL_RETURN(refUINode, nullptr); 651 auto frameNode = DynamicCast<FrameNode>(refUINode); 652 CHECK_NULL_RETURN(frameNode, nullptr); 653 return frameNode; 654 } 655 656 bool IsFocusNodeInItemPosition(const RefPtr<FrameNode>& focusNode); 657 658 void SetPageFlipMode(int32_t pageFlipMode); 659 GetPageFlipMode()660 int32_t GetPageFlipMode() const 661 { 662 return static_cast<int32_t>(pageFlipMode_); 663 } 664 SetJumpAnimationMode(TabAnimateMode tabAnimationMode)665 void SetJumpAnimationMode(TabAnimateMode tabAnimationMode) 666 { 667 tabAnimationMode_ = tabAnimationMode; 668 } 669 670 bool NeedFastAnimation() const; 671 bool IsInFastAnimation() const; 672 673 private: 674 void OnModifyDone() override; 675 void OnAfterModifyDone() override; 676 void OnAttachToFrameNode() override; 677 void OnDetachFromFrameNode(FrameNode* node) override; 678 void OnAttachToMainTree() override; 679 void OnDetachFromMainTree() override; 680 void InitSurfaceChangedCallback(); 681 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 682 683 // Init pan recognizer to move items when drag update, play translate animation when drag end. 684 void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub); 685 void AddPanEvent(const RefPtr<GestureEventHub>& gestureHub, GestureEventFunc&& actionStart, 686 GestureEventFunc&& actionUpdate, GestureEventFunc&& actionEnd, GestureEventNoParameter&& actionCancel); 687 688 // Init touch event, stop animation when touch down. 689 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 690 void InitHoverMouseEvent(); 691 // Init on key event 692 void InitOnFocusInternal(const RefPtr<FocusHub>& focusHub); 693 void HandleFocusInternal(); 694 void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub); 695 bool OnKeyEvent(const KeyEvent& event); 696 bool IsFocusNodeInItemPosition(const RefPtr<FocusHub>& targetFocusHub); 697 void FlushFocus(const RefPtr<FrameNode>& curShowFrame); 698 WeakPtr<FocusHub> GetNextFocusNode(FocusStep step, const WeakPtr<FocusHub>& currentFocusNode); 699 700 // Init indicator 701 void InitIndicator(); 702 void InitArrow(); 703 704 void HandleDragStart(const GestureEvent& info); 705 void HandleDragUpdate(const GestureEvent& info); 706 void HandleDragEnd(double dragVelocity, float mainDelta = 0.0f); 707 708 bool InsideIndicatorRegion(const TouchLocationInfo& locationInfo); 709 void HandleTouchEvent(const TouchEventInfo& info); 710 void HandleTouchDown(const TouchLocationInfo& locationInfo); 711 void HandleTouchUp(); 712 713 void HandleMouseEvent(const MouseInfo& info); 714 void PlayTranslateAnimation( 715 float startPos, float endPos, int32_t nextIndex, bool restartAutoPlay = false, float velocity = 0.0f); 716 void OnTranslateAnimationFinish(); 717 void PlaySpringAnimation(double dragVelocity); 718 void PlayFadeAnimation(); 719 720 // use property animation feature 721 void PlayPropertyTranslateAnimation( 722 float translate, int32_t nextIndex, float velocity = 0.0f, bool stopAutoPlay = false); 723 void StopPropertyTranslateAnimation( 724 bool isFinishAnimation, bool isBeforeCreateLayoutWrapper = false, bool isInterrupt = false); 725 void UpdateOffsetAfterPropertyAnimation(float offset); 726 void OnPropertyTranslateAnimationFinish(const OffsetF& offset); 727 void PlayIndicatorTranslateAnimation(float translate, std::optional<int32_t> nextIndex = std::nullopt); 728 729 // Implement of swiper controller 730 731 void FinishAnimation(); 732 void StopFadeAnimation(); 733 734 bool IsOutOfBoundary(float mainOffset = 0.0f) const; 735 bool IsOutOfStart(float mainOffset = 0.0f) const; 736 bool IsOutOfEnd(float mainOffset = 0.0f) const; 737 bool AutoLinearIsOutOfBoundary(float mainOffset) const; 738 float GetDistanceToEdge() const; 739 float MainSize() const; 740 float GetMainContentSize() const; 741 void FireChangeEvent(int32_t preIndex, int32_t currentIndex) const; 742 void FireAnimationStartEvent(int32_t currentIndex, int32_t nextIndex, const AnimationCallbackInfo& info) const; 743 void FireAnimationEndEvent(int32_t currentIndex, const AnimationCallbackInfo& info, bool isInterrupt = false) const; 744 void FireGestureSwipeEvent(int32_t currentIndex, const AnimationCallbackInfo& info) const; 745 void FireSwiperCustomAnimationEvent(); 746 void FireContentDidScrollEvent(); 747 void HandleSwiperCustomAnimation(float offset); 748 void CalculateAndUpdateItemInfo(float offset); 749 void UpdateItemInfoInCustomAnimation(int32_t index, float startPos, float endPos); 750 void UpdateTabBarAnimationDuration(int32_t index); 751 752 float GetItemSpace() const; 753 float GetPrevMargin() const; 754 float GetNextMargin() const; GetPrevMarginWithItemSpace()755 float GetPrevMarginWithItemSpace() const 756 { 757 return Positive(GetPrevMargin()) ? GetPrevMargin() + GetItemSpace() : 0.0f; 758 } GetNextMarginWithItemSpace()759 float GetNextMarginWithItemSpace() const 760 { 761 return Positive(GetNextMargin()) ? GetNextMargin() + GetItemSpace() : 0.0f; 762 } CalculateVisibleSize()763 float CalculateVisibleSize() const 764 { 765 return contentMainSize_ - GetPrevMarginWithItemSpace() - GetNextMarginWithItemSpace(); 766 } 767 int32_t CurrentIndex() const; 768 int32_t CalculateDisplayCount() const; 769 int32_t CalculateCount( 770 float contentWidth, float minSize, float margin, float gutter, float swiperPadding = 0.0f) const; 771 int32_t GetInterval() const; 772 RefPtr<Curve> GetCurve() const; 773 EdgeEffect GetEdgeEffect() const; 774 bool IsAutoPlay() const; 775 bool IsDisableSwipe() const; 776 bool IsShowIndicator() const; 777 std::pair<int32_t, SwiperItemInfo> GetFirstItemInfoInVisibleArea() const; 778 std::pair<int32_t, SwiperItemInfo> GetLastItemInfoInVisibleArea() const; 779 std::pair<int32_t, SwiperItemInfo> GetSecondItemInfoInVisibleArea() const; 780 void OnIndexChange(); 781 bool IsOutOfHotRegion(const PointF& dragPoint) const; 782 void SetDigitStartAndEndProperty(const RefPtr<FrameNode>& indicatorNode); 783 void UpdatePaintProperty(const RefPtr<FrameNode>& indicatorNode); 784 void PostTranslateTask(uint32_t delayTime); 785 void HandleVisibleChange(bool visible); 786 void RegisterVisibleAreaChange(); 787 bool NeedAutoPlay() const; 788 void OnTranslateFinish(int32_t nextIndex, bool restartAutoPlay, bool isFinishAnimation, bool forceStop = false, 789 bool isInterrupt = false); 790 bool IsShowArrow() const; 791 void SaveArrowProperty(const RefPtr<FrameNode>& arrowNode); 792 RefPtr<FocusHub> GetFocusHubChild(std::string childFrameName); 793 WeakPtr<FocusHub> PreviousFocus(const RefPtr<FocusHub>& curFocusNode); 794 WeakPtr<FocusHub> NextFocus(const RefPtr<FocusHub>& curFocusNode); 795 void SetAccessibilityAction(); 796 bool NeedStartAutoPlay() const; 797 void CheckAndSetArrowHoverState(const PointF& mousePoint); 798 RectF GetArrowFrameRect(const int32_t index) const; 799 float GetCustomPropertyOffset() const; 800 float GetCustomPropertyTargetOffset() const; 801 void UpdateAnimationProperty(float velocity); 802 void TriggerAnimationEndOnForceStop(bool isInterrupt = false); 803 void TriggerAnimationEndOnSwipeToLeft(); 804 void TriggerAnimationEndOnSwipeToRight(); 805 void TriggerEventOnFinish(int32_t nextIndex); 806 bool IsVisibleChildrenSizeLessThanSwiper() const; 807 void BeforeCreateLayoutWrapper() override; 808 int32_t CheckUserSetIndex(int32_t index); 809 810 void SetLazyLoadFeature(bool useLazyLoad); 811 void SetLazyForEachLongPredict(bool useLazyLoad) const; 812 void SetLazyLoadIsLoop() const; 813 int32_t ComputeNextIndexByVelocity(float velocity, bool onlyDistance = false) const; 814 void UpdateCurrentIndex(int32_t index); 815 void OnSpringAnimationStart(float velocity); 816 void OnSpringAnimationFinish(); 817 void OnSpringAndFadeAnimationFinish(); 818 void OnFadeAnimationStart(); 819 int32_t TotalDisPlayCount() const; 820 void StopAndResetSpringAnimation(); 821 void OnLoopChange(); 822 void StopSpringAnimationAndFlushImmediately(); 823 void UpdateItemRenderGroup(bool itemRenderGroup); 824 void MarkDirtyNodeSelf(); 825 void ResetAndUpdateIndexOnAnimationEnd(int32_t nextIndex); 826 int32_t GetLoopIndex(int32_t index, int32_t childrenSize) const; 827 bool IsAutoLinear() const; 828 bool AutoLinearAnimationNeedReset(float translate) const; 829 void OnAnimationTranslateZero(int32_t nextIndex, bool stopAutoPlay); 830 void TriggerCustomContentTransitionEvent(int32_t fromIndex, int32_t toIndex); 831 /** 832 * @brief Preprocess drag delta when received from DragUpdate event. 833 * 834 * Drag offset in Swiper can't go beyond a full page. Apply the restriction through this function. 835 * 836 * @param delta 837 * @param mainSize content length along the main axis. 838 * @param deltaSum accumulated delta in the current drag event. 839 */ 840 static void ProcessDelta(float& delta, float mainSize, float deltaSum); 841 842 /** 843 * @brief Stops animations when the scroll starts. 844 * 845 * @param flushImmediately Whether to flush layout immediately. 846 */ 847 void StopAnimationOnScrollStart(bool flushImmediately); 848 /** 849 * @return true if any translate animation (switching page / spring) is running, false otherwise. 850 */ 851 inline bool DuringTranslateAnimation() const; 852 /** 853 * @return true if any translate animation (switching page / spring) is running, ignore animation pause etc. 854 */ 855 inline bool RunningTranslateAnimation() const; 856 /** 857 * @return true if fade animation is running, false otherwise. 858 */ 859 inline bool DuringFadeAnimation() const; 860 861 /** 862 * NestableScrollContainer implementations 863 * ============================================================ 864 */ GetAxis()865 Axis GetAxis() const override 866 { 867 return GetDirection(); 868 } 869 870 /** 871 * @brief Closes gap to the edge, called before Swiper transfers extra offset to parent/child to ensure that Swiper 872 * actually reaches the edge. 873 * 874 * @param offset The scroll offset from DragUpdate. 875 */ 876 void CloseTheGap(float& offset); 877 878 ScrollResult HandleOutBoundary(float offset, int32_t source, float velocity); 879 880 ScrollResult HandleScroll( 881 float offset, int32_t source, NestedState state = NestedState::GESTURE, float velocity = 0.f) override; 882 883 ScrollResult HandleScrollSelfFirst(float offset, int32_t source, NestedState state, float velocity = 0.f); 884 885 ScrollResult HandleScrollParentFirst(float offset, int32_t source, NestedState state, float velocity = 0.f); 886 NestedScrollOutOfBoundary()887 bool NestedScrollOutOfBoundary() override 888 { 889 return IsOutOfBoundary(); 890 } 891 892 bool HandleScrollVelocity(float velocity, const RefPtr<NestableScrollContainer>& child = nullptr) override; 893 894 void OnScrollStartRecursive(WeakPtr<NestableScrollContainer> child, float position, float velocity) override; 895 void OnScrollEndRecursive(const std::optional<float>& velocity) override; 896 void OnScrollDragEndRecursive() override; 897 898 /** 899 * @brief Notifies the parent component that the scroll has started at the specified position. 900 * 901 * @param position The position where the scroll has started. 902 */ 903 void NotifyParentScrollStart(WeakPtr<NestableScrollContainer> child, float position); 904 /** 905 * @brief Notifies the parent NestableScrollContainer that the scroll has ended. 906 */ 907 void NotifyParentScrollEnd(); 908 909 inline bool ChildFirst(NestedState state); 910 RefPtr<FrameNode> GetCurrentFrameNode(int32_t currentIndex) const; 911 bool FadeOverScroll(float offset); 912 int32_t ComputeSwipePageNextIndex(float velocity, bool onlyDistance = false) const; 913 int32_t ComputeNextIndexInSinglePage(float velocity, bool onlyDistance) const; 914 int32_t ComputePageIndex(int32_t index) const; 915 void UpdateIndexOnAnimationStop(); 916 void UpdateIndexOnSwipePageStop(int32_t pauseTargetIndex); 917 void AdjustCurrentFocusIndex(); 918 bool IsContentFocused(); 919 920 int32_t CheckTargetIndex(int32_t targetIndex, bool isForceBackward = false); 921 922 void HandleTouchBottomLoop(); 923 void HandleTouchBottomLoopOnRTL(); 924 void CalculateGestureStateOnRTL(float additionalOffset, float currentTurnPageRate, int32_t preFirstIndex); 925 void CalculateGestureState(float additionalOffset, float currentTurnPageRate, int32_t preFirstIndex); 926 std::pair<float, float> CalcCurrentPageStatus(float additionalOffset) const; 927 std::pair<float, float> CalcCurrentPageStatusOnRTL(float additionalOffset) const; 928 void StopIndicatorAnimation(bool ifImmediately = false); 929 930 void PreloadItems(const std::set<int32_t>& indexSet); 931 void DoTabsPreloadItems(const std::set<int32_t>& indexSet); 932 void DoSwiperPreloadItems(const std::set<int32_t>& indexSet); 933 void FirePreloadFinishEvent(int32_t errorCode, std::string message = ""); 934 // capture node start 935 void InitCapture(); GetLeftCaptureId()936 int32_t GetLeftCaptureId() 937 { 938 if (!leftCaptureId_.has_value()) { 939 leftCaptureId_ = ElementRegister::GetInstance()->MakeUniqueId(); 940 } 941 return leftCaptureId_.value(); 942 } GetRightCaptureId()943 int32_t GetRightCaptureId() 944 { 945 if (!rightCaptureId_.has_value()) { 946 rightCaptureId_ = ElementRegister::GetInstance()->MakeUniqueId(); 947 } 948 return rightCaptureId_.value(); 949 } RemoveAllCaptureNode()950 void RemoveAllCaptureNode() 951 { 952 auto swiperNode = GetHost(); 953 CHECK_NULL_VOID(swiperNode); 954 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetLeftCaptureId())); 955 leftCaptureId_ = std::nullopt; 956 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetRightCaptureId())); 957 rightCaptureId_ = std::nullopt; 958 } GetLeftCaptureNode()959 RefPtr<FrameNode> GetLeftCaptureNode() 960 { 961 auto swiperNode = GetHost(); 962 CHECK_NULL_RETURN(swiperNode, nullptr); 963 return DynamicCast<FrameNode>(swiperNode->GetChildAtIndex(swiperNode->GetChildIndexById(GetLeftCaptureId()))); 964 } GetRightCaptureNode()965 RefPtr<FrameNode> GetRightCaptureNode() 966 { 967 auto swiperNode = GetHost(); 968 CHECK_NULL_RETURN(swiperNode, nullptr); 969 return DynamicCast<FrameNode>(swiperNode->GetChildAtIndex(swiperNode->GetChildIndexById(GetRightCaptureId()))); 970 } IsCaptureNodeValid()971 bool IsCaptureNodeValid() 972 { 973 return hasCachedCapture_ && GetLeftCaptureNode() && GetRightCaptureNode(); 974 } 975 void UpdateTargetCapture(bool forceUpdate); 976 void CreateCaptureCallback(int32_t targetIndex, int32_t captureId, bool forceUpdate); 977 void UpdateCaptureSource(std::shared_ptr<Media::PixelMap> pixelMap, int32_t captureId, int32_t targetIndex); 978 SupportSwiperCustomAnimation()979 bool SupportSwiperCustomAnimation() 980 { 981 auto swiperLayoutProperty = GetLayoutProperty<SwiperLayoutProperty>(); 982 return (onSwiperCustomContentTransition_ || onContentDidScroll_) && !hasCachedCapture_ && 983 SwiperUtils::IsStretch(swiperLayoutProperty); 984 } 985 986 bool NeedStartNewAnimation(const OffsetF& offset) const; 987 void ResetOnForceMeasure(); 988 void UpdateTabBarIndicatorCurve(); 989 bool CheckDragOutOfBoundary(double dragVelocity); 990 void UpdateCurrentFocus(); 991 992 void CreateSpringProperty(); 993 994 std::optional<RefPtr<UINode>> FindLazyForEachNode(RefPtr<UINode> baseNode, bool isSelfNode = true) const; 995 bool NeedForceMeasure() const; 996 void SetIndicatorChangeIndexStatus(bool withAnimation, std::optional<int32_t> startIndex = std::nullopt); 997 void SetIndicatorJumpIndex(std::optional<int32_t> jumpIndex); 998 bool ParseTabsIsRtl(); 999 1000 void PostIdleTask(const RefPtr<FrameNode>& frameNode); 1001 1002 float AdjustIgnoreBlankOverScrollOffSet(bool isStartOverScroll) const; 1003 void UpdateIgnoreBlankOffsetWithIndex(); 1004 // overSrollDirection is true means over start boundary, false means over end boundary. 1005 void UpdateIgnoreBlankOffsetWithDrag(bool overSrollDirection); 1006 void UpdateIgnoreBlankOffsetInMap(float lastIgnoreBlankOffset); 1007 1008 std::set<int32_t> CalcVisibleIndex(float offset = 0.0f) const; 1009 1010 bool IsItemOverlay() const; 1011 void UpdateIndicatorOnChildChange(); 1012 1013 void CheckSpecialItemCount() const; 1014 bool IsCachedShow() const; 1015 void MarkDirtyBindIndicatorNode() const; 1016 RefPtr<FrameNode> GetCommonIndicatorNode(); IsIndicator(const std::string & tag)1017 bool IsIndicator(const std::string& tag) const 1018 { 1019 return tag == V2::SWIPER_INDICATOR_ETS_TAG || tag == V2::INDICATOR_ETS_TAG; 1020 } 1021 bool ContentWillScroll(int32_t currentIndex, int32_t comingIndex, float offset); 1022 bool CheckContentWillScroll(float checkValue, float mainDelta); 1023 float CalcWillScrollOffset(int32_t comingIndex); 1024 std::optional<bool> OnContentWillScroll(int32_t currentIndex, int32_t comingIndex, float offset) const; 1025 std::pair<int32_t, SwiperItemInfo> CalcFirstItemWithoutItemSpace() const; 1026 int32_t CalcComingIndex(float mainDelta) const; 1027 void TriggerAddTabBarEvent() const; NeedEnableIgnoreBlankOffset()1028 bool NeedEnableIgnoreBlankOffset() const 1029 { 1030 return !IsLoop() && (prevMarginIgnoreBlank_ || nextMarginIgnoreBlank_) && TotalCount() > GetDisplayCount(); 1031 } 1032 1033 bool ComputeTargetIndex(int32_t index, int32_t& targetIndex) const; 1034 void FastAnimation(int32_t targetIndex); 1035 1036 friend class SwiperHelper; 1037 1038 RefPtr<PanEvent> panEvent_; 1039 RefPtr<TouchEventImpl> touchEvent_; 1040 RefPtr<InputEvent> hoverEvent_; 1041 1042 // Control translate animation when drag end. 1043 RefPtr<Animator> controller_; 1044 1045 // Control spring animation when drag beyond boundary and drag end. 1046 std::shared_ptr<AnimationUtils::Animation> springAnimation_; 1047 1048 // Control fade animation when drag beyond boundary and drag end. 1049 std::shared_ptr<AnimationUtils::Animation> fadeAnimation_; 1050 1051 // Control translate animation for indicator. 1052 std::shared_ptr<AnimationUtils::Animation> indicatorAnimation_; 1053 1054 std::shared_ptr<AnimationUtils::Animation> translateAnimation_; 1055 1056 bool indicatorAnimationIsRunning_ = false; 1057 bool translateAnimationIsRunning_ = false; 1058 1059 // stop indicator animation callback 1060 std::function<void(bool)> stopIndicatorAnimationFunc_; 1061 1062 RefPtr<SwiperController> swiperController_; 1063 RefPtr<InputEvent> mouseEvent_; 1064 1065 bool isLastIndicatorFocused_ = false; 1066 int32_t startIndex_ = 0; 1067 int32_t endIndex_ = 0; 1068 int32_t currentIndex_ = 0; 1069 int32_t oldIndex_ = 0; 1070 int32_t nextIndex_ = 0; 1071 1072 PanDirection panDirection_; 1073 1074 float currentOffset_ = 0.0f; 1075 float fadeOffset_ = 0.0f; 1076 float turnPageRate_ = 0.0f; 1077 float translateAnimationEndPos_ = 0.0f; 1078 GestureState gestureState_ = GestureState::GESTURE_STATE_INIT; 1079 TouchBottomTypeLoop touchBottomType_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_NONE; 1080 float touchBottomRate_ = 1.0f; 1081 float currentIndexOffset_ = 0.0f; 1082 int32_t gestureSwipeIndex_ = 0; 1083 int32_t currentFirstIndex_ = 0; 1084 int32_t nextValidIndex_ = 0; 1085 int32_t currentFocusIndex_ = 0; 1086 1087 bool moveDirection_ = false; 1088 bool indicatorDoingAnimation_ = false; 1089 bool isInit_ = true; 1090 bool hasVisibleChangeRegistered_ = false; 1091 bool isVisible_ = true; 1092 bool isVisibleArea_ = false; 1093 bool isWindowShow_ = true; 1094 bool isCustomSize_ = false; 1095 bool indicatorIsBoolean_ = true; 1096 bool isAtHotRegion_ = false; 1097 bool isDragging_ = false; 1098 bool needTurn_ = false; 1099 bool isParentHiddenChange_ = false; 1100 /** 1101 * @brief Indicates whether the child NestableScrollContainer is currently scrolling and affecting Swiper. 1102 */ 1103 bool childScrolling_ = false; 1104 bool isTouchDown_ = false; 1105 bool isTouchDownOnOverlong_ = false; 1106 std::optional<bool> preLoop_; 1107 1108 Axis direction_ = Axis::HORIZONTAL; 1109 1110 ChangeEventPtr changeEvent_; 1111 ChangeEventPtr onIndexChangeEvent_; 1112 AnimationStartEventPtr animationStartEvent_; 1113 AnimationEndEventPtr animationEndEvent_; 1114 1115 mutable std::shared_ptr<SwiperParameters> swiperParameters_; 1116 mutable std::shared_ptr<SwiperDigitalParameters> swiperDigitalParameters_; 1117 1118 WeakPtr<FrameNode> lastWeakShowNode_; 1119 1120 CancelableCallback<void()> translateTask_; 1121 CancelableCallback<void()> resetLayoutTask_; 1122 1123 std::optional<int32_t> indicatorId_; 1124 std::optional<int32_t> leftButtonId_; 1125 std::optional<int32_t> rightButtonId_; 1126 std::optional<int32_t> leftCaptureId_; 1127 std::optional<int32_t> rightCaptureId_; 1128 std::optional<SwiperIndicatorType> lastSwiperIndicatorType_; 1129 1130 float startMainPos_ = 0.0f; 1131 float endMainPos_ = 0.0f; 1132 float contentMainSize_ = 0.0f; 1133 float oldContentMainSize_ = 0.0f; 1134 float contentCrossSize_ = 0.0f; 1135 bool crossMatchChild_ = false; 1136 1137 std::optional<int32_t> uiCastJumpIndex_; 1138 std::optional<int32_t> jumpIndex_; 1139 std::optional<int32_t> targetIndex_; 1140 std::optional<int32_t> preTargetIndex_; 1141 std::optional<int32_t> pauseTargetIndex_; 1142 std::optional<int32_t> oldChildrenSize_; 1143 std::optional<float> placeItemWidth_; 1144 float currentDelta_ = 0.0f; 1145 // cumulated delta in a single drag event 1146 float mainDeltaSum_ = 0.0f; 1147 SwiperLayoutAlgorithm::PositionMap itemPosition_; 1148 std::optional<float> velocity_; 1149 float motionVelocity_ = 0.0f; 1150 bool isFinishAnimation_ = false; 1151 bool mainSizeIsMeasured_ = false; 1152 bool usePropertyAnimation_ = false; 1153 bool springAnimationIsRunning_ = false; 1154 bool isTouchDownSpringAnimation_ = false; 1155 bool isTouchDownFadeAnimation_ = false; 1156 int32_t propertyAnimationIndex_ = -1; 1157 bool isUserFinish_ = true; 1158 bool isVoluntarilyClear_ = false; 1159 bool isIndicatorLongPress_ = false; 1160 bool stopIndicatorAnimation_ = true; 1161 bool isTouchPad_ = false; 1162 bool fadeAnimationIsRunning_ = false; 1163 bool autoLinearReachBoundary = false; 1164 bool needAdjustIndex_ = false; 1165 bool hasTabsAncestor_ = false; 1166 bool isIndicatorInteractive_ = true; 1167 bool nextMarginIgnoreBlank_ = false; 1168 bool prevMarginIgnoreBlank_ = false; 1169 float ignoreBlankOffset_ = 0.0f; 1170 1171 std::optional<int32_t> cachedCount_; 1172 1173 std::optional<int32_t> surfaceChangedCallbackId_; 1174 SwiperLayoutAlgorithm::PositionMap itemPositionInAnimation_; 1175 SwiperLayoutAlgorithm::PositionMap itemPositionWillInvisible_; 1176 1177 WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; 1178 std::vector<RefPtr<ScrollingListener>> scrollingListener_; 1179 FinishCallbackType finishCallbackType_ = FinishCallbackType::REMOVED; 1180 1181 CustomContentTransitionPtr onTabsCustomContentTransition_; 1182 std::shared_ptr<SwiperContentAnimatedTransition> onSwiperCustomContentTransition_; 1183 std::shared_ptr<ContentDidScrollEvent> onContentDidScroll_; 1184 std::shared_ptr<ContentWillScrollEvent> onContentWillScroll_; 1185 std::set<int32_t> indexsInAnimation_; 1186 std::set<int32_t> needUnmountIndexs_; 1187 std::optional<int32_t> customAnimationToIndex_; 1188 RefPtr<TabContentTransitionProxy> currentProxyInAnimation_; 1189 PaddingPropertyF tabsPaddingAndBorder_; 1190 std::map<int32_t, bool> indexCanChangeMap_; 1191 std::unordered_map<SwiperDynamicSyncSceneType, RefPtr<FrameRateRange>> frameRateRange_; 1192 // capture 1193 std::optional<int32_t> leftCaptureIndex_; 1194 std::optional<int32_t> rightCaptureIndex_; 1195 bool hasCachedCapture_ = false; 1196 bool isCaptureReverse_ = false; 1197 OffsetF captureFinalOffset_; 1198 bool isInAutoPlay_ = false; 1199 bool needResetCurrentIndex_ = false; 1200 1201 bool needFireCustomAnimationEvent_ = true; 1202 std::optional<bool> isSwipeByGroup_; 1203 std::set<WeakPtr<FrameNode>> groupedItems_; 1204 1205 std::set<int32_t> cachedItems_; 1206 LayoutConstraintF layoutConstraint_; 1207 bool requestLongPredict_ = false; 1208 WeakPtr<NG::UINode> indicatorNode_; 1209 bool isBindIndicator_ = false; 1210 1211 PageFlipMode pageFlipMode_ = PageFlipMode::CONTINUOUS; 1212 bool jumpOnChange_ = false; 1213 TabAnimateMode tabAnimationMode_ = TabAnimateMode::NO_ANIMATION; 1214 bool isFirstAxisAction_ = true; 1215 SwiperHoverFlag hoverFlag_ = HOVER_NONE; 1216 }; 1217 } // namespace OHOS::Ace::NG 1218 1219 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_SWIPER_PATTERN_H 1220