1 /* 2 * Copyright (c) 2023-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_SCROLL_SCROLLABLE_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLLABLE_NG_H 18 19 #include <functional> 20 21 #include "base/geometry/dimension.h" 22 #include "base/utils/system_properties.h" 23 #include "core/animation/animator.h" 24 #include "core/animation/friction_motion.h" 25 #include "core/animation/scroll_motion.h" 26 #include "core/components_ng/base/frame_scene_status.h" 27 #include "core/components_ng/gestures/recognizers/pan_recognizer.h" 28 #include "core/components_ng/pattern/scrollable/axis/axis_animator.h" 29 #include "core/components_ng/pattern/scrollable/scrollable_properties.h" 30 #include "core/components_ng/render/animation_utils.h" 31 #include "core/event/axis_event.h" 32 #include "core/event/touch_event.h" 33 #include "core/gestures/raw_recognizer.h" 34 #include "core/gestures/timeout_recognizer.h" 35 36 #ifdef SUPPORT_DIGITAL_CROWN 37 #include "core/event/crown_event.h" 38 #include "core/common/vibrator/vibrator_utils.h" 39 #endif 40 41 namespace OHOS::Ace::NG { 42 enum class NestedState { 43 GESTURE = 0, 44 CHILD_SCROLL, 45 CHILD_OVER_SCROLL, 46 CHILD_CHECK_OVER_SCROLL, 47 }; 48 49 struct OverScrollOffset { 50 double start; 51 double end; 52 }; 53 54 struct ScrollResult { 55 double remain; 56 bool reachEdge; 57 }; 58 59 struct SlidInfo { 60 double gestureVelocity {0.0}; 61 double velocityScale {0.0}; 62 double gain {0.0}; 63 double maxFlingVelocity {0.0}; 64 double slipFactor {0.0}; 65 double friction {0.0}; 66 }; 67 68 using ScrollEventCallback = std::function<void()>; 69 using OutBoundaryCallback = std::function<bool()>; 70 using ScrollOverCallback = std::function<void(double velocity)>; 71 using WatchFixCallback = std::function<double(double final, double current)>; 72 using ScrollBeginCallback = std::function<ScrollInfo(Dimension, Dimension)>; 73 using ScrollFrameBeginCallback = std::function<ScrollFrameResult(Dimension, ScrollState)>; 74 using DragEndForRefreshCallback = std::function<void()>; 75 using DragCancelRefreshCallback = std::function<void()>; 76 using MouseLeftButtonScroll = std::function<bool()>; 77 using ContinuousSlidingCallback = std::function<double()>; 78 using StartSnapAnimationCallback = std::function<bool(SnapAnimationOptions)>; 79 using NeedScrollSnapToSideCallback = std::function<bool(float delta)>; 80 using NestableScrollCallback = std::function<ScrollResult(float, int32_t, NestedState)>; 81 using DragFRCSceneCallback = std::function<void(double velocity, NG::SceneStatus sceneStatus)>; 82 using IsReverseCallback = std::function<bool()>; 83 using RemainVelocityCallback = std::function<bool(float)>; 84 using GetSnapTypeCallback = std::function<SnapType()>; 85 using FixScrollParamCallback = std::function<void(float mainPos, float& correctVelocity, float& finalPos)>; 86 using OnWillStopDraggingCallback = std::function<void(float velocity)>; 87 88 class FrameNode; 89 class PipelineContext; 90 91 class Scrollable : public TouchEventTarget { 92 DECLARE_ACE_TYPE(Scrollable, TouchEventTarget); 93 94 public: 95 Scrollable() = default; Scrollable(ScrollPositionCallback && callback,Axis axis)96 Scrollable(ScrollPositionCallback&& callback, Axis axis) : callback_(std::move(callback)), axis_(axis) {} Scrollable(const ScrollPositionCallback & callback,Axis axis)97 Scrollable(const ScrollPositionCallback& callback, Axis axis) : callback_(callback), axis_(axis) {} 98 ~Scrollable() override; 99 100 enum class AnimationState { 101 SPRING, 102 SNAP, 103 FRICTION, 104 TRANSITION, // in between two animations, i.e. from friction to spring 105 IDLE, 106 }; 107 108 static double GetVelocityScale(); 109 110 void Initialize(const RefPtr<FrameNode>& host); 111 112 void InitAxisAnimator(); 113 #ifdef SUPPORT_DIGITAL_CROWN 114 void ListenDigitalCrownEvent(const RefPtr<FrameNode>& frameNode); SetDigitalCrownSensitivity(CrownSensitivity sensitivity)115 void SetDigitalCrownSensitivity(CrownSensitivity sensitivity) 116 { 117 crownSensitivity_ = sensitivity; 118 } 119 #endif IsMotionStop()120 bool IsMotionStop() const 121 { 122 return state_ != AnimationState::SPRING && state_ != AnimationState::FRICTION && !moved_; 123 } 124 IsSpringMotionRunning()125 bool IsSpringMotionRunning() const 126 { 127 return state_ == AnimationState::SPRING; 128 } 129 IsDragging()130 bool IsDragging() const 131 { 132 return isTouching_ && state_ == AnimationState::FRICTION; 133 } 134 135 void SetAxis(Axis axis); 136 GetMainOffset(const Offset & offset)137 double GetMainOffset(const Offset& offset) const 138 { 139 return axis_ == Axis::HORIZONTAL ? offset.GetX() : offset.GetY(); 140 } 141 GetMainSize(const Size & size)142 double GetMainSize(const Size& size) const 143 { 144 return axis_ == Axis::HORIZONTAL ? size.Width() : size.Height(); 145 } 146 SetCallback(const ScrollPositionCallback & callback)147 void SetCallback(const ScrollPositionCallback& callback) 148 { 149 callback_ = callback; 150 } 151 SetCoordinateOffset(const Offset & offset)152 void SetCoordinateOffset(const Offset& offset) const 153 { 154 if (panRecognizerNG_) { 155 panRecognizerNG_->SetCoordinateOffset(offset); 156 } 157 } 158 159 void OnCollectTouchTarget(TouchTestResult& result, const RefPtr<FrameNode>& frameNode, 160 const RefPtr<TargetComponent>& targetComponent, ResponseLinkResult& responseLinkResult); 161 SetDragTouchRestrict(const TouchRestrict & touchRestrict)162 void SetDragTouchRestrict(const TouchRestrict& touchRestrict) 163 { 164 if (panRecognizerNG_) { 165 panRecognizerNG_->SetTouchRestrict(touchRestrict); 166 } 167 } 168 SetScrollEndCallback(const ScrollEventCallback & scrollEndCallback)169 void SetScrollEndCallback(const ScrollEventCallback& scrollEndCallback) 170 { 171 scrollEndCallback_ = scrollEndCallback; 172 } 173 SetUnstaticFriction(double friction)174 void SetUnstaticFriction(double friction) 175 { 176 friction_ = friction > 0.0 ? friction : -1.0; 177 } 178 GetFriction()179 double GetFriction() const 180 { 181 double friction = friction_; 182 if (friction == -1.0) { 183 double ret = SystemProperties::GetSrollableFriction(); 184 friction = !NearZero(ret) ? ret : defaultFriction_; 185 } 186 return friction; 187 } 188 GetRatio()189 float GetRatio() const 190 { 191 return ratio_; 192 } 193 SetUnstaticVelocityScale(double scale)194 void SetUnstaticVelocityScale(double scale) 195 { 196 flingVelocityScale_ = scale; 197 springVelocityScale_ = scale; 198 } 199 200 void HandleTouchDown(bool fromcrown = false); 201 void HandleTouchUp(); 202 void HandleTouchCancel(); 203 void HandleDragStart(const GestureEvent& info); 204 void HandleExtDragUpdate(); 205 void HandleDragUpdate(const GestureEvent& info); 206 void HandleDragEnd(const GestureEvent& info, bool isFromPanEnd = false); 207 void HandleScrollEnd(const std::optional<float>& velocity); 208 void HandleExtScroll(); 209 bool HandleOverScroll(double velocity); 210 ScrollResult HandleScroll(double offset, int32_t source, NestedState state); 211 void ProcessAxisUpdateEvent(float mainDelta, bool fromScrollBar = false); 212 void ProcessAxisEndEvent(); 213 void LayoutDirectionEst(double correctVelocity, double velocityScale, bool isScrollFromTouchPad); 214 void ReportToDragFRCScene(double velocity, NG::SceneStatus sceneStatus); 215 SetMoved(bool value)216 void SetMoved(bool value) 217 { 218 moved_ = value; 219 } SetCanOverScroll(bool value)220 void SetCanOverScroll(bool value) 221 { 222 canOverScroll_ = value; 223 } CanOverScroll()224 bool CanOverScroll() const 225 { 226 return canOverScroll_; 227 } SetCanStayOverScroll(bool value)228 void SetCanStayOverScroll(bool value) 229 { 230 canStayOverScroll_ = value; 231 } CanStayOverScroll()232 bool CanStayOverScroll() const 233 { 234 return canStayOverScroll_; 235 } 236 237 void ProcessScrollMotionStop(); 238 DispatchEvent(const TouchEvent & point)239 bool DispatchEvent(const TouchEvent& point) override 240 { 241 return true; 242 } HandleEvent(const TouchEvent & event)243 bool HandleEvent(const TouchEvent& event) override 244 { 245 if (!available_) { 246 return true; 247 } 248 return true; 249 } HandleEvent(const AxisEvent & event)250 bool HandleEvent(const AxisEvent& event) override 251 { 252 return false; 253 } 254 SetRemainVelocityCallback(const RemainVelocityCallback & remainVelocityCallback)255 void SetRemainVelocityCallback(const RemainVelocityCallback& remainVelocityCallback) 256 { 257 remainVelocityCallback_ = remainVelocityCallback; 258 } 259 SetScrollOverCallBack(const ScrollOverCallback & scrollOverCallback)260 void SetScrollOverCallBack(const ScrollOverCallback& scrollOverCallback) 261 { 262 scrollOverCallback_ = scrollOverCallback; 263 } 264 SetNotifyScrollOverCallBack(const ScrollOverCallback & scrollOverCallback)265 void SetNotifyScrollOverCallBack(const ScrollOverCallback& scrollOverCallback) 266 { 267 notifyScrollOverCallback_ = scrollOverCallback; 268 } 269 SetCurrentPositionCallback(const std::function<double ()> & currentPositionCallback)270 void SetCurrentPositionCallback(const std::function<double()>& currentPositionCallback) 271 { 272 currentPositionCallback_ = currentPositionCallback; 273 } 274 SetOutBoundaryCallback(const OutBoundaryCallback & outBoundaryCallback)275 void SetOutBoundaryCallback(const OutBoundaryCallback& outBoundaryCallback) 276 { 277 outBoundaryCallback_ = outBoundaryCallback; 278 } 279 SetDragEndCallback(const DragEndForRefreshCallback & dragEndCallback)280 void SetDragEndCallback(const DragEndForRefreshCallback& dragEndCallback) 281 { 282 dragEndCallback_ = dragEndCallback; 283 } 284 SetDragCancelCallback(const DragCancelRefreshCallback & dragCancelCallback)285 void SetDragCancelCallback(const DragCancelRefreshCallback& dragCancelCallback) 286 { 287 dragCancelCallback_ = dragCancelCallback; 288 } 289 GetDragEndCallback()290 const DragEndForRefreshCallback& GetDragEndCallback() const 291 { 292 return dragEndCallback_; 293 } 294 GetDragCancelCallback()295 const DragCancelRefreshCallback& GetDragCancelCallback() const 296 { 297 return dragCancelCallback_; 298 } 299 GetOnWillStopDraggingEndCallback()300 const OnWillStopDraggingCallback& GetOnWillStopDraggingEndCallback() const 301 { 302 return onWillStopDraggingCallback_; 303 } 304 SetOnWillStopDraggingCallback(const OnWillStopDraggingCallback & onWillStopDraggingCallback)305 void SetOnWillStopDraggingCallback(const OnWillStopDraggingCallback& onWillStopDraggingCallback) 306 { 307 onWillStopDraggingCallback_ = onWillStopDraggingCallback; 308 } 309 SetWatchFixCallback(const WatchFixCallback & watchFixCallback)310 void SetWatchFixCallback(const WatchFixCallback& watchFixCallback) 311 { 312 watchFixCallback_ = watchFixCallback; 313 } 314 MarkNeedCenterFix(bool needFix)315 void MarkNeedCenterFix(bool needFix) 316 { 317 needCenterFix_ = needFix; 318 } 319 GetCurrentVelocity()320 double GetCurrentVelocity() const 321 { 322 return currentVelocity_; 323 }; 324 SetIsReverseCallback(const IsReverseCallback & isReverseCallback)325 void SetIsReverseCallback(const IsReverseCallback& isReverseCallback) 326 { 327 isReverseCallback_ = isReverseCallback; 328 } 329 330 void OnAnimateStop(); 331 void ProcessScrollSnapStop(); 332 void StartSpringMotion( 333 double mainPosition, double mainVelocity, const ExtentPair& extent, const ExtentPair& initExtent); 334 void UpdateSpringMotion(double mainPosition, const ExtentPair& extent, const ExtentPair& initExtent); 335 336 void UpdateScrollSnapStartOffset(double offset); 337 void StartListSnapAnimation(float predictSnapOffset, float scrollSnapVelocity, bool fromScrollBar); 338 void UpdateScrollSnapEndWithOffset(double offset); 339 340 bool IsAnimationNotRunning() const; 341 342 bool Idle() const; 343 344 bool IsStopped() const; 345 346 bool IsSpringStopped() const; 347 348 bool IsSnapStopped() const; 349 350 void StopScrollable(); 351 Available()352 bool Available() const 353 { 354 return available_; 355 } 356 MarkAvailable(bool available)357 void MarkAvailable(bool available) 358 { 359 available_ = available; 360 } 361 GetContext()362 WeakPtr<PipelineContext> GetContext() const 363 { 364 return context_; 365 } 366 SetNodeId(int32_t nodeId)367 void SetNodeId(int32_t nodeId) 368 { 369 nodeId_ = nodeId; 370 } 371 GetNodeId()372 int32_t GetNodeId() 373 { 374 return nodeId_; 375 } 376 SetNodeTag(const std::string & nodeTag)377 void SetNodeTag(const std::string& nodeTag) 378 { 379 nodeTag_ = nodeTag; 380 } 381 GetNodeTag()382 const std::string& GetNodeTag() const 383 { 384 return nodeTag_; 385 } 386 387 void ProcessScrollOverCallback(double velocity); 388 389 void SetSlipFactor(double SlipFactor); 390 SetOnScrollBegin(const ScrollBeginCallback & scrollBeginCallback)391 void SetOnScrollBegin(const ScrollBeginCallback& scrollBeginCallback) 392 { 393 scrollBeginCallback_ = scrollBeginCallback; 394 } 395 SetOnContinuousSliding(const ContinuousSlidingCallback & continuousSlidingCallback)396 void SetOnContinuousSliding(const ContinuousSlidingCallback& continuousSlidingCallback) 397 { 398 continuousSlidingCallback_ = continuousSlidingCallback; 399 } 400 SetGetSnapTypeCallback(const GetSnapTypeCallback & getSnapTypeCallback)401 void SetGetSnapTypeCallback(const GetSnapTypeCallback& getSnapTypeCallback) 402 { 403 getSnapTypeCallback_ = getSnapTypeCallback; 404 } 405 406 std::optional<float> GetPredictSnapOffset() const; 407 SetHandleScrollCallback(NestableScrollCallback && func)408 void SetHandleScrollCallback(NestableScrollCallback&& func) 409 { 410 handleScrollCallback_ = std::move(func); 411 } SetOverScrollCallback(std::function<bool (float)> && func)412 void SetOverScrollCallback(std::function<bool(float)>&& func) 413 { 414 overScrollCallback_ = std::move(func); 415 } SetHandleExtScrollCallback(std::function<void (void)> && func)416 void SetHandleExtScrollCallback(std::function<void(void)>&& func) 417 { 418 handleExtScrollCallback_ = std::move(func); 419 } 420 void StartScrollAnimation(float mainPosition, float velocity, bool isScrollFromTouchPad = false); SetOnScrollStartRec(std::function<void (float)> && func)421 void SetOnScrollStartRec(std::function<void(float)>&& func) 422 { 423 onScrollStartRec_ = std::move(func); 424 } SetOnScrollEndRec(std::function<void (const std::optional<float> &)> && func)425 void SetOnScrollEndRec(std::function<void(const std::optional<float>&)>&& func) 426 { 427 onScrollEndRec_ = std::move(func); 428 } 429 SetEdgeEffect(EdgeEffect effect)430 void SetEdgeEffect(EdgeEffect effect) 431 { 432 edgeEffect_ = effect; 433 } 434 SetStartSnapAnimationCallback(const StartSnapAnimationCallback & startSnapAnimationCallback)435 void SetStartSnapAnimationCallback(const StartSnapAnimationCallback& startSnapAnimationCallback) 436 { 437 startSnapAnimationCallback_ = startSnapAnimationCallback; 438 } 439 SetContinuousDragStatus(bool status)440 void SetContinuousDragStatus(bool status) 441 { 442 continuousDragStatus_ = status; 443 } IncreaseContinueDragCount()444 void IncreaseContinueDragCount() 445 { 446 dragCount_++; 447 } ResetContinueDragCount()448 void ResetContinueDragCount() 449 { 450 dragCount_ = 1; 451 } SetDragStartPosition(double position)452 void SetDragStartPosition(double position) 453 { 454 dragStartPosition_ = position; 455 } SetDragEndPosition(double position)456 void SetDragEndPosition(double position) 457 { 458 dragEndPosition_ = position; 459 } GetDragOffset()460 double GetDragOffset() 461 { 462 return dragEndPosition_ - dragStartPosition_; 463 } 464 SetNeedScrollSnapToSideCallback(NeedScrollSnapToSideCallback && needScrollSnapToSideCallback)465 void SetNeedScrollSnapToSideCallback(NeedScrollSnapToSideCallback&& needScrollSnapToSideCallback) 466 { 467 needScrollSnapToSideCallback_ = std::move(needScrollSnapToSideCallback); 468 } 469 470 void StartScrollSnapAnimation(float scrollSnapDelta, float scrollSnapVelocity, bool fromScrollBar); 471 StopSnapController()472 void StopSnapController() 473 { 474 if (state_ == AnimationState::SNAP) { 475 StopSnapAnimation(); 476 } 477 } 478 IsSnapAnimationRunning()479 bool IsSnapAnimationRunning() 480 { 481 return state_ == AnimationState::SNAP; 482 } 483 IsAxisAnimationRunning()484 bool IsAxisAnimationRunning() 485 { 486 return axisAnimator_ && axisAnimator_->IsRunning(); 487 } 488 GetCurrentPos()489 double GetCurrentPos() const 490 { 491 return currentPos_; 492 } 493 SetCurrentPos(float currentPos)494 void SetCurrentPos(float currentPos) 495 { 496 currentPos_ = currentPos; 497 } 498 GetNeedScrollSnapChange()499 bool GetNeedScrollSnapChange() const 500 { 501 return needScrollSnapChange_; 502 } 503 AddPreviewMenuHandleDragEnd(GestureEventFunc && actionEnd)504 void AddPreviewMenuHandleDragEnd(GestureEventFunc&& actionEnd) 505 { 506 AddPanActionEndEvent(std::move(actionEnd)); 507 } 508 GetIsDragging()509 bool GetIsDragging() const 510 { 511 return isDragging_; 512 } 513 SetDragFRCSceneCallback(DragFRCSceneCallback && dragFRCSceneCallback)514 void SetDragFRCSceneCallback(DragFRCSceneCallback&& dragFRCSceneCallback) 515 { 516 dragFRCSceneCallback_ = std::move(dragFRCSceneCallback); 517 } 518 GetFinalPosition()519 float GetFinalPosition() 520 { 521 return finalPosition_; 522 } 523 GetSnapFinalPosition()524 float GetSnapFinalPosition() 525 { 526 return endPos_; 527 } 528 529 void SetMaxFlingVelocity(double max); 530 GetMaxFlingVelocity()531 double GetMaxFlingVelocity() const 532 { 533 return maxFlingVelocity_; 534 } 535 RegisterFixScrollParamCallback(const FixScrollParamCallback & callback)536 void RegisterFixScrollParamCallback(const FixScrollParamCallback& callback) 537 { 538 fixScrollParamCallback_ = callback; 539 } 540 541 void StopFrictionAnimation(); 542 void StopSpringAnimation(bool reachFinalPosition = false); 543 void StopSnapAnimation(); 544 void StopAxisAnimation(); 545 546 void AttachAnimatableProperty(const RefPtr<NodeAnimatablePropertyFloat>& property); 547 RefPtr<NodeAnimatablePropertyFloat> GetFrictionProperty(); 548 RefPtr<NodeAnimatablePropertyFloat> GetSpringProperty(); 549 RefPtr<NodeAnimatablePropertyFloat> GetSnapProperty(); 550 GetPanDirection()551 Axis GetPanDirection() const 552 { 553 CHECK_NULL_RETURN(panRecognizerNG_, Axis::NONE); 554 return panRecognizerNG_->GetAxisDirection(); 555 } 556 SetNestedScrolling(bool nestedScrolling)557 void SetNestedScrolling(bool nestedScrolling) 558 { 559 nestedScrolling_ = nestedScrolling; 560 } 561 GetNestedScrolling()562 bool GetNestedScrolling() const 563 { 564 return nestedScrolling_; 565 } 566 567 #ifdef SUPPORT_DIGITAL_CROWN GetCrownEventDragging()568 bool GetCrownEventDragging() const 569 { 570 return isCrownEventDragging_; 571 } 572 SetCrownEventDragging(bool draging)573 void SetCrownEventDragging(bool draging) 574 { 575 isCrownEventDragging_ = draging; 576 } 577 #endif 578 SetOverScrollOffsetCallback(std::function<double ()> overScrollOffsetCallback)579 void SetOverScrollOffsetCallback(std::function<double()> overScrollOffsetCallback) 580 { 581 overScrollOffsetCallback_ = overScrollOffsetCallback; 582 } 583 AddPanActionEndEvent(GestureEventFunc && event)584 void AddPanActionEndEvent(GestureEventFunc&& event) 585 { 586 panActionEndEvents_.emplace_back(event); 587 } 588 GetSnapType()589 SnapType GetSnapType() 590 { 591 CHECK_NULL_RETURN(getSnapTypeCallback_, SnapType::NONE_SNAP); 592 return getSnapTypeCallback_(); 593 } 594 ResetSnapDirection()595 void ResetSnapDirection() 596 { 597 snapDirection_ = SnapDirection::NONE; 598 } 599 600 /** 601 * @brief Checks if the scroll event is caused by a mouse wheel. 602 */ IsMouseWheelScroll(const GestureEvent & info)603 static inline bool IsMouseWheelScroll(const GestureEvent& info) 604 { 605 return info.GetInputEventType() == InputEventType::AXIS && info.GetSourceTool() != SourceTool::TOUCHPAD; 606 } 607 608 private: 609 void InitPanRecognizerNG(); 610 void SetOnActionStart(); 611 void SetOnActionUpdate(); 612 void SetOnActionExtUpdate(); 613 void SetOnActionEnd(); 614 void SetOnActionCancel(); 615 void SetPanEndCallback(); 616 void ProcessPanActionEndEvents(const GestureEvent& info); 617 bool UpdateScrollPosition(double offset, int32_t source) const; 618 void ProcessSpringMotion(double position); 619 void ProcessScrollMotion(double position, int32_t source = SCROLL_FROM_ANIMATION); 620 void ProcessListSnapMotion(double position); 621 void TriggerFrictionAnimation(float mainPosition, float friction, float correctVelocity); 622 void FixScrollMotion(float position, float initVelocity); 623 void ExecuteScrollBegin(double& mainDelta); 624 double ComputeCap(int dragCount); 625 double GetGain(double delta); 626 void SetDelayedTask(); 627 void MarkNeedFlushAnimationStartTime(); 628 float GetFrictionVelocityByFinalPosition( 629 float final, float position, float signum, float friction, float threshold = DEFAULT_MULTIPLIER); 630 void CalcOverScrollVelocity(); 631 double CalcNextStep(double position, double mainDelta); 632 633 #ifdef SUPPORT_DIGITAL_CROWN 634 void HandleCrownEvent(const CrownEvent& event, const OffsetF& center); 635 void HandleCrownActionBegin(const TimeStamp& timeStamp, double mainDelta, GestureEvent& info); 636 void HandleCrownActionUpdate(const TimeStamp& timeStamp, double mainDelta, GestureEvent& info); 637 void HandleCrownActionEnd(const TimeStamp& timeStamp, double mainDelta, GestureEvent& info); 638 void HandleCrownActionCancel(GestureEvent& info); 639 double GetCrownRotatePx(const CrownEvent& event) const; 640 void UpdateCrownVelocity(const TimeStamp& timeStamp, double mainDelta, bool end); 641 void StartVibrateFeedback(); 642 #endif 643 644 ScrollPositionCallback callback_; 645 ScrollEventCallback scrollEndCallback_; 646 ScrollOverCallback scrollOverCallback_; // scroll motion controller when edge set to spring 647 ScrollOverCallback notifyScrollOverCallback_; // scroll motion controller when edge set to spring 648 OutBoundaryCallback outBoundaryCallback_; // whether out of boundary check when edge set to spring 649 std::function<double()> currentPositionCallback_; 650 IsReverseCallback isReverseCallback_; 651 652 WatchFixCallback watchFixCallback_; 653 ScrollBeginCallback scrollBeginCallback_; 654 DragEndForRefreshCallback dragEndCallback_; 655 DragCancelRefreshCallback dragCancelCallback_; 656 ContinuousSlidingCallback continuousSlidingCallback_; 657 GetSnapTypeCallback getSnapTypeCallback_; 658 OnWillStopDraggingCallback onWillStopDraggingCallback_; 659 Axis axis_ = Axis::VERTICAL; 660 // used for ng structure. 661 RefPtr<NG::PanRecognizer> panRecognizerNG_; 662 663 WeakPtr<FrameNode> weakHost_; 664 WeakPtr<PipelineContext> context_; 665 double currentPos_ = 0.0; 666 double currentVelocity_ = 0.0; 667 double maxFlingVelocity_ = 0.0; 668 bool scrollPause_ = false; 669 bool moved_ = false; 670 bool isTouching_ = false; 671 bool isDragging_ = false; 672 bool available_ = true; 673 bool needCenterFix_ = false; 674 bool isDragUpdateStop_ = false; 675 bool isFadingAway_ = false; 676 bool isCrownDragging_ = false; 677 // The accessibilityId of UINode 678 int32_t nodeId_ = 0; 679 // The tag of UINode 680 std::string nodeTag_ = "Scrollable"; 681 double slipFactor_ = 0.0; 682 bool continuousDragStatus_ = false; 683 CancelableCallback<void()> task_; 684 int32_t dragCount_ = 0; 685 double lastPos_ = 0.0; 686 double dragStartPosition_ = 0.0; 687 double dragEndPosition_ = 0.0; 688 double lastGestureVelocity_ = 0.0; 689 double friction_ = -1.0; 690 double preGain_ = 1.0; 691 #ifdef OHOS_PLATFORM 692 int64_t startIncreaseTime_ = 0; 693 #endif 694 695 // ScrollablePattern::HandleScroll 696 NestableScrollCallback handleScrollCallback_; 697 // ScrollablePattern::HandleOverScroll 698 std::function<bool(float)> overScrollCallback_; 699 // ScrollablePattern::onScrollStartRecursiveInner 700 std::function<void(float)> onScrollStartRec_; 701 // ScrollablePattern::onScrollEndRecursiveInner 702 std::function<void(const std::optional<float>&)> onScrollEndRec_; 703 // ScrollablePattern::RemainVelocityToChild 704 RemainVelocityCallback remainVelocityCallback_; 705 // ScrollablePattern::HandleExtScroll 706 std::function<void(void)> handleExtScrollCallback_; 707 708 EdgeEffect edgeEffect_ = EdgeEffect::NONE; 709 bool canOverScroll_ = true; 710 bool canStayOverScroll_ = false; 711 712 // scrollSnap 713 bool needScrollSnapChange_ = false; 714 StartSnapAnimationCallback startSnapAnimationCallback_; 715 NeedScrollSnapToSideCallback needScrollSnapToSideCallback_; 716 std::list<GestureEventFunc> panActionEndEvents_; 717 718 DragFRCSceneCallback dragFRCSceneCallback_; 719 FixScrollParamCallback fixScrollParamCallback_; 720 uint64_t lastVsyncTime_ = 0; 721 uint64_t lastAxisVsyncTime_ = 0; // only used in mouse wheel scenes 722 AnimationState state_ = AnimationState::IDLE; 723 RefPtr<NodeAnimatablePropertyFloat> frictionOffsetProperty_; 724 float finalPosition_ = 0.0f; 725 float lastPosition_ = 0.0f; 726 float initVelocity_ = 0.0f; 727 float frictionVelocity_ = 0.0f; 728 double lastMainDelta_ = 0.0; 729 730 RefPtr<NodeAnimatablePropertyFloat> springOffsetProperty_; 731 bool skipRestartSpring_ = false; // set to true when need to skip repeated spring animation 732 uint32_t updateSnapAnimationCount_ = 0; 733 uint32_t springAnimationCount_ = 0; 734 double flingVelocityScale_ = 1.5; 735 double springVelocityScale_ = 1.5; 736 double defaultFriction_ = 0; 737 float ratio_ = 1.848f; 738 float springResponse_ = 0.416f; 739 float touchPadVelocityScaleRate_ = 1.0f; 740 std::function<double()> overScrollOffsetCallback_; 741 742 RefPtr<NodeAnimatablePropertyFloat> snapOffsetProperty_; 743 bool snapAnimationFromScrollBar_ = false; 744 float snapVelocity_ = 0.0f; 745 float endPos_ = 0.0; 746 bool nestedScrolling_ = false; 747 float axisSnapDistance_ = 0.f; 748 SnapDirection snapDirection_ = SnapDirection::NONE; 749 bool isSlow_ = false; 750 std::optional<float> nextStep_; 751 752 RefPtr<AxisAnimator> axisAnimator_; 753 #ifdef SUPPORT_DIGITAL_CROWN 754 CrownSensitivity crownSensitivity_ = CrownSensitivity::MEDIUM; 755 VelocityTracker crownVelocityTracker_; 756 Offset accumulativeCrownPx_; 757 bool isCrownEventDragging_ = false; 758 759 int crownEventNum_ = 0; 760 bool reachBoundary_ = false; 761 CancelableCallback<void()> crownTask_; 762 #endif 763 SlidInfo slidInfo_; 764 }; 765 766 } // namespace OHOS::Ace::NG 767 768 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLLABLE_NG_H 769