1 /* 2 * Copyright (c) 2022-2023 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 <optional> 20 21 #include "base/geometry/axis.h" 22 #include "base/geometry/ng/offset_t.h" 23 #include "base/memory/referenced.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components/swiper/swiper_controller.h" 26 #include "core/components/swiper/swiper_indicator_theme.h" 27 #include "core/components_ng/event/event_hub.h" 28 #include "core/components_ng/event/input_event.h" 29 #include "core/components_ng/pattern/pattern.h" 30 #include "core/components_ng/pattern/swiper/swiper_accessibility_property.h" 31 #include "core/components_ng/pattern/swiper/swiper_event_hub.h" 32 #include "core/components_ng/pattern/swiper/swiper_layout_algorithm.h" 33 #include "core/components_ng/pattern/swiper/swiper_layout_property.h" 34 #include "core/components_ng/pattern/swiper/swiper_model.h" 35 #include "core/components_ng/pattern/swiper/swiper_paint_method.h" 36 #include "core/components_ng/pattern/swiper/swiper_paint_property.h" 37 #include "core/components_v2/inspector/utils.h" 38 39 namespace OHOS::Ace::NG { 40 class SwiperPattern : public Pattern { 41 DECLARE_ACE_TYPE(SwiperPattern, Pattern); 42 43 public: 44 SwiperPattern(); 45 ~SwiperPattern() override = default; 46 IsAtomicNode()47 bool IsAtomicNode() const override 48 { 49 return false; 50 } 51 UsResRegion()52 bool UsResRegion() override 53 { 54 return false; 55 } 56 CreateLayoutProperty()57 RefPtr<LayoutProperty> CreateLayoutProperty() override 58 { 59 return MakeRefPtr<SwiperLayoutProperty>(); 60 } 61 CreatePaintProperty()62 RefPtr<PaintProperty> CreatePaintProperty() override 63 { 64 return MakeRefPtr<SwiperPaintProperty>(); 65 } 66 CreateAccessibilityProperty()67 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 68 { 69 return MakeRefPtr<SwiperAccessibilityProperty>(); 70 } 71 72 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override; 73 CreateNodePaintMethod()74 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 75 { 76 auto layoutProperty = GetLayoutProperty<SwiperLayoutProperty>(); 77 CHECK_NULL_RETURN(layoutProperty, nullptr); 78 const auto& paddingProperty = layoutProperty->GetPaddingProperty(); 79 bool needClipPadding = paddingProperty != nullptr; 80 bool needPaintFade = !IsLoop() && GetEdgeEffect() == EdgeEffect::FADE && !NearZero(fadeOffset_); 81 auto paintMethod = MakeRefPtr<SwiperPaintMethod>(GetDirection(), fadeOffset_); 82 paintMethod->SetNeedPaintFade(needPaintFade); 83 paintMethod->SetNeedClipPadding(needClipPadding); 84 return paintMethod; 85 } 86 CreateEventHub()87 RefPtr<EventHub> CreateEventHub() override 88 { 89 return MakeRefPtr<SwiperEventHub>(); 90 } 91 ToJsonValue(std::unique_ptr<JsonValue> & json)92 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override 93 { 94 Pattern::ToJsonValue(json); 95 json->Put("currentIndex", currentIndex_); 96 json->Put("currentOffset", currentOffset_); 97 98 if (indicatorIsBoolean_) { 99 return; 100 } 101 102 auto indicatorType = GetIndicatorType(); 103 if (indicatorType == SwiperIndicatorType::DOT) { 104 json->Put("indicator", GetDotIndicatorStyle().c_str()); 105 } else { 106 json->Put("indicator", GetDigitIndicatorStyle().c_str()); 107 } 108 } 109 FromJson(const std::unique_ptr<JsonValue> & json)110 void FromJson(const std::unique_ptr<JsonValue>& json) override 111 { 112 currentIndex_ = json->GetInt("currentIndex"); 113 auto currentOffset = json->GetDouble("currentOffset"); 114 if (currentOffset != currentOffset_) { 115 auto delta = currentOffset - currentOffset_; 116 LOGD("UITree delta=%{public}f", delta); 117 UpdateCurrentOffset(delta); 118 } 119 Pattern::FromJson(json); 120 } 121 GetDotIndicatorStyle()122 std::string GetDotIndicatorStyle() const 123 { 124 auto swiperParameters = GetSwiperParameters(); 125 CHECK_NULL_RETURN(swiperParameters, ""); 126 auto jsonValue = JsonUtil::Create(true); 127 jsonValue->Put("left", swiperParameters_->dimLeft.value_or(0.0_vp).ToString().c_str()); 128 jsonValue->Put("top", swiperParameters_->dimTop.value_or(0.0_vp).ToString().c_str()); 129 jsonValue->Put("right", swiperParameters_->dimRight.value_or(0.0_vp).ToString().c_str()); 130 jsonValue->Put("bottom", swiperParameters_->dimBottom.value_or(0.0_vp).ToString().c_str()); 131 jsonValue->Put("itemWidth", swiperParameters_->itemWidth.value_or(6.0_vp).ToString().c_str()); 132 jsonValue->Put("itemHeight", swiperParameters_->itemHeight.value_or(6.0_vp).ToString().c_str()); 133 jsonValue->Put("selectedItemWidth", swiperParameters_->selectedItemWidth.value_or(6.0_vp).ToString().c_str()); 134 jsonValue->Put("selectedItemHeight", swiperParameters_->selectedItemHeight.value_or(6.0_vp).ToString().c_str()); 135 jsonValue->Put("selectedColor", 136 swiperParameters_->selectedColorVal.value_or(Color::FromString("#ff007dff")).ColorToString().c_str()); 137 jsonValue->Put( 138 "color", swiperParameters_->colorVal.value_or(Color::FromString("#19182431")).ColorToString().c_str()); 139 jsonValue->Put("mask", swiperParameters_->maskValue ? "true" : "false"); 140 return jsonValue->ToString(); 141 } 142 GetDigitIndicatorStyle()143 std::string GetDigitIndicatorStyle() const 144 { 145 auto swiperParameters = GetSwiperDigitalParameters(); 146 CHECK_NULL_RETURN(swiperParameters, ""); 147 auto jsonValue = JsonUtil::Create(true); 148 auto pipelineContext = PipelineBase::GetCurrentContext(); 149 CHECK_NULL_RETURN(pipelineContext, ""); 150 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>(); 151 CHECK_NULL_RETURN(swiperIndicatorTheme, ""); 152 jsonValue->Put("left", swiperDigitalParameters_->dimLeft.value_or(0.0_vp).ToString().c_str()); 153 jsonValue->Put("top", swiperDigitalParameters_->dimTop.value_or(0.0_vp).ToString().c_str()); 154 jsonValue->Put("right", swiperDigitalParameters_->dimRight.value_or(0.0_vp).ToString().c_str()); 155 jsonValue->Put("bottom", swiperDigitalParameters_->dimBottom.value_or(0.0_vp).ToString().c_str()); 156 jsonValue->Put("fontSize", swiperDigitalParameters_->fontSize 157 .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize()) 158 .ToString() 159 .c_str()); 160 jsonValue->Put("fontColor", swiperDigitalParameters_->fontColor 161 .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()) 162 .ColorToString() 163 .c_str()); 164 jsonValue->Put("fontWeight", 165 V2::ConvertWrapFontWeightToStirng(swiperDigitalParameters_->fontWeight.value_or(FontWeight::NORMAL)) 166 .c_str()); 167 jsonValue->Put( 168 "selectedFontSize", swiperDigitalParameters_->selectedFontSize 169 .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize()) 170 .ToString() 171 .c_str()); 172 jsonValue->Put( 173 "selectedFontColor", swiperDigitalParameters_->selectedFontColor 174 .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()) 175 .ColorToString() 176 .c_str()); 177 jsonValue->Put("selectedFontWeight", 178 V2::ConvertWrapFontWeightToStirng(swiperDigitalParameters_->selectedFontWeight.value_or(FontWeight::NORMAL)) 179 .c_str()); 180 return jsonValue->ToString(); 181 } 182 GetCurrentShownIndex()183 int32_t GetCurrentShownIndex() const 184 { 185 return IsLoop() ? currentIndex_ : GetLoopIndex(currentIndex_); 186 } 187 GetSwiperController()188 RefPtr<SwiperController> GetSwiperController() const 189 { 190 return swiperController_; 191 } 192 SetSwiperController(const RefPtr<SwiperController> & swiperController)193 void SetSwiperController(const RefPtr<SwiperController>& swiperController) 194 { 195 swiperController_ = swiperController; 196 } 197 GetCurrentFirstIndex()198 int32_t GetCurrentFirstIndex() const 199 { 200 return currentFirstIndex_; 201 } 202 GetCurrentIndex()203 int32_t GetCurrentIndex() 204 { 205 return GetLoopIndex(currentIndex_); 206 } 207 GetTurnPageRate()208 float GetTurnPageRate() const 209 { 210 return turnPageRate_; 211 } 212 IsIndicatorAnimatorRunning()213 bool IsIndicatorAnimatorRunning() const 214 { 215 return indicatorController_ ? indicatorController_->IsRunning() : false; 216 } 217 SetTurnPageRate(float turnPageRate)218 void SetTurnPageRate(float turnPageRate) 219 { 220 turnPageRate_ = turnPageRate; 221 } 222 GetTouchBottomRate()223 float GetTouchBottomRate() const 224 { 225 return touchBottomRate_; 226 } 227 SetTouchBottomRate(float touchBottomRate)228 void SetTouchBottomRate(float touchBottomRate) 229 { 230 touchBottomRate_ = touchBottomRate; 231 } 232 GetController()233 RefPtr<Animator> GetController() 234 { 235 return controller_; 236 } 237 SetIndicatorDoingAnimation(bool indicatorDoingAnimation)238 void SetIndicatorDoingAnimation(bool indicatorDoingAnimation) 239 { 240 indicatorDoingAnimation_ = indicatorDoingAnimation; 241 } 242 243 void UpdateCurrentOffset(float offset); 244 245 void CheckMarkDirtyNodeForRenderIndicator(float additionalOffset = 0.0f); 246 247 int32_t TotalCount() const; 248 249 Axis GetDirection() const; 250 GetFocusPattern()251 FocusPattern GetFocusPattern() const override 252 { 253 return { FocusType::SCOPE, true }; 254 } 255 GetScopeFocusAlgorithm()256 ScopeFocusAlgorithm GetScopeFocusAlgorithm() override 257 { 258 return ScopeFocusAlgorithm(direction_ != Axis::HORIZONTAL, true, ScopeType::OTHERS, 259 [wp = WeakClaim(this)]( 260 FocusStep step, const WeakPtr<FocusHub>& currFocusNode, WeakPtr<FocusHub>& nextFocusNode) { 261 auto swiper = wp.Upgrade(); 262 if (swiper) { 263 nextFocusNode = swiper->GetNextFocusNode(step, currFocusNode); 264 } 265 }); 266 } 267 UpdateChangeEvent(ChangeEvent && event)268 void UpdateChangeEvent(ChangeEvent&& event) 269 { 270 if (!changeEvent_) { 271 changeEvent_ = std::make_shared<ChangeEvent>(event); 272 auto eventHub = GetEventHub<SwiperEventHub>(); 273 CHECK_NULL_VOID(eventHub); 274 eventHub->AddOnChangeEvent(changeEvent_); 275 } else { 276 (*changeEvent_).swap(event); 277 } 278 } 279 UpdateOnChangeEvent(ChangeEvent && event)280 void UpdateOnChangeEvent(ChangeEvent&& event) 281 { 282 if (!onIndexChangeEvent_) { 283 onIndexChangeEvent_ = std::make_shared<ChangeEvent>(event); 284 auto eventHub = GetEventHub<SwiperEventHub>(); 285 CHECK_NULL_VOID(eventHub); 286 eventHub->AddOnChangeEvent(onIndexChangeEvent_); 287 } else { 288 (*onIndexChangeEvent_).swap(event); 289 } 290 } 291 SetSwiperParameters(const SwiperParameters & swiperParameters)292 void SetSwiperParameters(const SwiperParameters& swiperParameters) 293 { 294 swiperParameters_ = std::make_shared<SwiperParameters>(swiperParameters); 295 } 296 SetSwiperDigitalParameters(const SwiperDigitalParameters & swiperDigitalParameters)297 void SetSwiperDigitalParameters(const SwiperDigitalParameters& swiperDigitalParameters) 298 { 299 swiperDigitalParameters_ = std::make_shared<SwiperDigitalParameters>(swiperDigitalParameters); 300 } 301 302 void ShowNext(); 303 void ShowPrevious(); 304 void SwipeTo(int32_t index); 305 306 void OnVisibleChange(bool isVisible) override; 307 GetStartIndex()308 int32_t GetStartIndex() const 309 { 310 return startIndex_; 311 } 312 GetEndIndex()313 int32_t GetEndIndex() const 314 { 315 return endIndex_; 316 } 317 HasIndicatorNode()318 bool HasIndicatorNode() const 319 { 320 return indicatorId_.has_value(); 321 } 322 HasLeftButtonNode()323 bool HasLeftButtonNode() const 324 { 325 return leftButtonId_.has_value(); 326 } 327 HasRightButtonNode()328 bool HasRightButtonNode() const 329 { 330 return rightButtonId_.has_value(); 331 } 332 GetIndicatorId()333 int32_t GetIndicatorId() 334 { 335 if (!indicatorId_.has_value()) { 336 indicatorId_ = ElementRegister::GetInstance()->MakeUniqueId(); 337 } 338 return indicatorId_.value(); 339 } 340 GetLeftButtonId()341 int32_t GetLeftButtonId() 342 { 343 if (!leftButtonId_.has_value()) { 344 leftButtonId_ = ElementRegister::GetInstance()->MakeUniqueId(); 345 } 346 return leftButtonId_.value(); 347 } 348 GetRightButtonId()349 int32_t GetRightButtonId() 350 { 351 if (!rightButtonId_.has_value()) { 352 rightButtonId_ = ElementRegister::GetInstance()->MakeUniqueId(); 353 } 354 return rightButtonId_.value(); 355 } 356 RemoveIndicatorNode()357 void RemoveIndicatorNode() 358 { 359 CHECK_NULL_VOID_NOLOG(HasIndicatorNode()); 360 auto swiperNode = GetHost(); 361 CHECK_NULL_VOID(swiperNode); 362 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetIndicatorId())); 363 indicatorId_ = std::nullopt; 364 } 365 RemoveLeftButtonNode()366 void RemoveLeftButtonNode() 367 { 368 CHECK_NULL_VOID_NOLOG(HasLeftButtonNode()); 369 auto swiperNode = GetHost(); 370 CHECK_NULL_VOID(swiperNode); 371 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetLeftButtonId())); 372 leftButtonId_ = std::nullopt; 373 } 374 RemoveRightButtonNode()375 void RemoveRightButtonNode() 376 { 377 CHECK_NULL_VOID_NOLOG(HasRightButtonNode()); 378 auto swiperNode = GetHost(); 379 CHECK_NULL_VOID(swiperNode); 380 swiperNode->RemoveChildAtIndex(swiperNode->GetChildIndexById(GetRightButtonId())); 381 rightButtonId_ = std::nullopt; 382 } 383 384 SwiperIndicatorType GetIndicatorType() const; 385 IsIndicatorCustomSize()386 bool IsIndicatorCustomSize() const 387 { 388 return IsCustomSize_; 389 } 390 SetIsIndicatorCustomSize(bool IsCustomSize)391 void SetIsIndicatorCustomSize(bool IsCustomSize) 392 { 393 IsCustomSize_ = IsCustomSize; 394 } 395 SetIndicatorIsBoolean(bool isBoolean)396 void SetIndicatorIsBoolean(bool isBoolean) 397 { 398 indicatorIsBoolean_ = isBoolean; 399 } 400 GetIsAtHotRegion()401 bool GetIsAtHotRegion() const 402 { 403 return isAtHotRegion_; 404 } 405 HasSurfaceChangedCallback()406 bool HasSurfaceChangedCallback() 407 { 408 return surfaceChangedCallbackId_.has_value(); 409 } 410 UpdateSurfaceChangedCallbackId(int32_t id)411 void UpdateSurfaceChangedCallbackId(int32_t id) 412 { 413 surfaceChangedCallbackId_ = id; 414 } 415 SetIndicatorLongPress(bool isIndicatorLongPress)416 void SetIndicatorLongPress(bool isIndicatorLongPress) 417 { 418 isIndicatorLongPress_ = isIndicatorLongPress; 419 } 420 421 std::shared_ptr<SwiperParameters> GetSwiperParameters() const; 422 std::shared_ptr<SwiperDigitalParameters> GetSwiperDigitalParameters() const; 423 424 void ArrowHover(bool hoverFlag); 425 bool IsLoop() const; 426 bool IsEnabled() const; 427 void OnWindowShow() override; 428 void OnWindowHide() override; 429 std::string ProvideRestoreInfo() override; 430 void OnRestoreInfo(const std::string& restoreInfo) override; 431 bool IsAutoFill() const; 432 void OnTouchTestHit(SourceType hitTestType) override; 433 void SwipeToWithoutAnimation(int32_t index); 434 void StopAutoPlay(); 435 void StartAutoPlay(); 436 void StopTranslateAnimation(); 437 void StopSpringAnimation(); 438 private: 439 void OnModifyDone() override; 440 void OnAttachToFrameNode() override; 441 void OnDetachFromFrameNode(FrameNode* node) override; 442 void InitSurfaceChangedCallback(); 443 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 444 445 // Init pan recognizer to move items when drag update, play translate animation when drag end. 446 void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub); 447 448 // Init touch event, stop animation when touch down. 449 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 450 void InitHoverMouseEvent(); 451 // Init on key event 452 void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub); 453 bool OnKeyEvent(const KeyEvent& event); 454 void FlushFocus(const RefPtr<FrameNode>& curShowFrame); 455 WeakPtr<FocusHub> GetNextFocusNode(FocusStep step, const WeakPtr<FocusHub>& currentFocusNode); 456 457 // Init controller of swiper, controller support showNext, showPrevious and finishAnimation interface. 458 void InitSwiperController(); 459 460 // Init indicator 461 void InitIndicator(); 462 void InitArrow(); 463 464 void HandleDragStart(); 465 void HandleDragUpdate(const GestureEvent& info); 466 void HandleDragEnd(double dragVelocity); 467 468 void HandleTouchEvent(const TouchEventInfo& info); 469 void HandleTouchDown(); 470 void HandleTouchUp(); 471 472 void HandleMouseEvent(const MouseInfo& info); 473 void PlayTranslateAnimation( 474 float startPos, float endPos, int32_t nextIndex, bool restartAutoPlay = false, float velocity = 0.0f); 475 void PlaySpringAnimation(double dragVelocity); 476 void PlayFadeAnimation(); 477 478 // use property animation feature 479 void PlayPropertyTranslateAnimation(float translate, int32_t nextIndex, float velocity = 0.0f); 480 void StopPropertyTranslateAnimation(bool isBeforeCreateLayoutWrapper = false); 481 void UpdateOffsetAfterPropertyAnimation(float offset); 482 void OnPropertyTranslateAnimationFinish(const OffsetF& offset); 483 RefPtr<Curve> GetCurveIncludeMotion(float velocity = 0.0f) const; 484 void PlayIndicatorTranslateAnimation(float translate); 485 486 // Implement of swiper controller 487 488 void FinishAnimation(); 489 void StopFadeAnimation(); 490 491 bool IsOutOfBoundary(float mainOffset = 0.0f) const; 492 float GetRemainingOffset() const; 493 float MainSize() const; 494 float GetMainContentSize() const; 495 void FireChangeEvent() const; 496 void FireAnimationStartEvent(int32_t currentIndex, int32_t nextIndex, const AnimationCallbackInfo& info) const; 497 void FireAnimationEndEvent(int32_t currentIndex, const AnimationCallbackInfo& info) const; 498 void FireGestureSwipeEvent(int32_t currentIndex, const AnimationCallbackInfo& info) const; 499 500 float GetItemSpace() const; 501 float GetPrevMargin() const; 502 float GetNextMargin() const; 503 float CalculateVisibleSize() const; 504 int32_t GetLoopIndex(int32_t originalIndex) const; 505 int32_t CurrentIndex() const; 506 int32_t GetDisplayCount() const; 507 int32_t CalculateDisplayCount() const; 508 int32_t CalculateCount( 509 float contentWidth, float minSize, float margin, float gutter, float swiperPadding = 0.0f) const; 510 int32_t GetDuration() const; 511 int32_t GetInterval() const; 512 RefPtr<Curve> GetCurve() const; 513 EdgeEffect GetEdgeEffect() const; 514 bool IsAutoPlay() const; 515 bool IsDisableSwipe() const; 516 bool IsShowIndicator() const; 517 float GetTranslateLength() const; 518 std::pair<int32_t, SwiperItemInfo> GetFirstItemInfoInVisibleArea() const; 519 std::pair<int32_t, SwiperItemInfo> GetLastItemInfoInVisibleArea() const; 520 std::pair<int32_t, SwiperItemInfo> GetSecondItemInfoInVisibleArea() const; 521 void OnIndexChange() const; 522 bool IsOutOfHotRegion(const PointF& dragPoint) const; 523 void SaveDotIndicatorProperty(const RefPtr<FrameNode>& indicatorNode); 524 void SaveDigitIndicatorProperty(const RefPtr<FrameNode>& indicatorNode); 525 void PostTranslateTask(uint32_t delayTime); 526 void RegisterVisibleAreaChange(); 527 bool NeedAutoPlay() const; 528 void OnTranslateFinish(int32_t nextIndex, bool restartAutoPlay, bool forceStop = false); 529 bool IsShowArrow() const; 530 void SaveArrowProperty(const RefPtr<FrameNode>& arrowNode); 531 RefPtr<FocusHub> GetFocusHubChild(std::string childFrameName); 532 WeakPtr<FocusHub> PreviousFocus(const RefPtr<FocusHub>& curFocusNode); 533 WeakPtr<FocusHub> NextFocus(const RefPtr<FocusHub>& curFocusNode); 534 void SetAccessibilityAction(); 535 bool NeedStartAutoPlay() const; 536 void CheckAndSetArrowHoverState(const PointF& mousePoint); 537 RectF GetArrowFrameRect(const int32_t index) const; 538 float GetCustomPropertyOffset() const; 539 float GetCurrentFirstIndexStartPos() const; 540 void UpdateAnimationProperty(float velocity); 541 void TriggerAnimationEndOnForceStop(); 542 void TriggerAnimationEndOnSwipeToLeft(); 543 void TriggerAnimationEndOnSwipeToRight(); 544 void TriggerEventOnFinish(int32_t nextIndex); 545 bool IsVisibleChildrenSizeLessThanSwiper(); 546 void BeforeCreateLayoutWrapper() override; 547 548 void SetLazyLoadFeature(bool useLazyLoad) const; 549 void SetLazyLoadIsLoop() const; 550 int32_t ComputeNextIndexByVelocity(float velocity, bool onlyDistance = false) const; 551 void UpdateCurrentIndex(int32_t index); 552 void OnSpringAnimationStart(float velocity); 553 void OnSpringAndFadeAnimationFinish(); 554 void OnFadeAnimationStart(); 555 int32_t TotalDisPlayCount() const; 556 void StopAndResetSpringAnimation(); 557 void OnLoopChange(); 558 void StopSpringAnimationAndFlushImmediately(); 559 void UpdateItemRenderGroup(bool itemRenderGroup); 560 void ResetAndUpdateIndexOnAnimationEnd(int32_t nextIndex); 561 562 RefPtr<PanEvent> panEvent_; 563 RefPtr<TouchEventImpl> touchEvent_; 564 RefPtr<InputEvent> hoverEvent_; 565 566 // Control translate animation when drag end. 567 RefPtr<Animator> controller_; 568 569 // Control spring animation when drag beyond boundary and drag end. 570 RefPtr<Animator> springController_; 571 572 // Control fade animation when drag beyond boundary and drag end. 573 RefPtr<Animator> fadeController_; 574 575 // Control translate animation for indicator. 576 RefPtr<Animator> indicatorController_; 577 578 RefPtr<SwiperController> swiperController_; 579 RefPtr<InputEvent> mouseEvent_; 580 581 bool isLastIndicatorFocused_ = false; 582 int32_t startIndex_ = 0; 583 int32_t endIndex_ = 0; 584 int32_t currentIndex_ = 0; 585 int32_t oldIndex_ = 0; 586 587 PanDirection panDirection_; 588 589 float currentOffset_ = 0.0f; 590 float fadeOffset_ = 0.0f; 591 float turnPageRate_ = 0.0f; 592 float touchBottomRate_ = 1.0f; 593 float currentIndexOffset_ = 0.0f; 594 int32_t gestureSwipeIndex_ = 0; 595 int32_t currentFirstIndex_ = 0; 596 597 bool moveDirection_ = false; 598 bool indicatorDoingAnimation_ = false; 599 bool isInit_ = true; 600 bool hasVisibleChangeRegistered_ = false; 601 bool isVisible_ = true; 602 bool isVisibleArea_ = true; 603 bool isWindowShow_ = true; 604 bool IsCustomSize_ = false; 605 bool indicatorIsBoolean_ = true; 606 bool isAtHotRegion_ = false; 607 bool isDragging_ = false; 608 bool isTouchDown_ = false; 609 std::optional<bool> preLoop_; 610 611 Axis direction_ = Axis::HORIZONTAL; 612 613 ChangeEventPtr changeEvent_; 614 ChangeEventPtr onIndexChangeEvent_; 615 616 mutable std::shared_ptr<SwiperParameters> swiperParameters_; 617 mutable std::shared_ptr<SwiperDigitalParameters> swiperDigitalParameters_; 618 619 WeakPtr<FrameNode> lastWeakShowNode_; 620 621 CancelableCallback<void()> translateTask_; 622 623 std::optional<int32_t> indicatorId_; 624 std::optional<int32_t> leftButtonId_; 625 std::optional<int32_t> rightButtonId_; 626 std::optional<SwiperIndicatorType> lastSwiperIndicatorType_; 627 628 float startMainPos_ = 0.0f; 629 float endMainPos_ = 0.0f; 630 float contentMainSize_ = 0.0f; 631 float contentCrossSize_ = 0.0f; 632 633 std::optional<int32_t> jumpIndex_; 634 std::optional<int32_t> targetIndex_; 635 std::optional<int32_t> preTargetIndex_; 636 std::optional<int32_t> pauseTargetIndex_; 637 float currentDelta_ = 0.0f; 638 SwiperLayoutAlgorithm::PositionMap itemPosition_; 639 std::optional<float> velocity_; 640 bool isFinishAnimation_ = false; 641 bool mainSizeIsMeasured_ = false; 642 bool isNeedResetPrevMarginAndNextMargin_ = false; 643 bool usePropertyAnimation_ = false; 644 int32_t propertyAnimationIndex_ = -1; 645 bool isUserFinish_ = true; 646 bool isVoluntarilyClear_ = false; 647 bool isIndicatorLongPress_ = false; 648 bool stopIndicatorAnimation_ = true; 649 bool isTouchPad_ = false; 650 651 float mainDeltaSum_ = 0.0f; 652 653 std::optional<int32_t> surfaceChangedCallbackId_; 654 SwiperLayoutAlgorithm::PositionMap itemPositionInAnimation_; 655 }; 656 } // namespace OHOS::Ace::NG 657 658 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_SWIPER_PATTERN_H 659