From 4f7158e2871d05593241707f90bd7fc7c3f01f85 Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 22 May 2025 14:18:28 +0800 Subject: [PATCH] fix(utils): streamline scroll animation logic in springScrollTo - Removed unnecessary requestAnimationFrame handling to simplify the scroll animation process. - Enhanced the stopping condition for animations to ensure smoother transitions during scrolling. These changes improve the efficiency and responsiveness of the scrolling behavior. Signed-off-by: Innei --- packages/internal/utils/src/scroller.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/internal/utils/src/scroller.ts b/packages/internal/utils/src/scroller.ts index ff4fc0267..0010f679a 100644 --- a/packages/internal/utils/src/scroller.ts +++ b/packages/internal/utils/src/scroller.ts @@ -20,7 +20,7 @@ export const springScrollTo = ( isStop = true animation.stop() } - let raf: any + const el = scrollerElement || window const animation = animateValue({ keyframes: [scrollTop + 1, y], @@ -34,18 +34,14 @@ export const springScrollTo = ( onUpdate(latest) { if (latest <= 0) { animation.stop() + return } - if (raf) { - cancelAnimationFrame(raf) + if (isStop) { + return } - raf = requestAnimationFrame(() => { - if (isStop) { - return - } - el.scrollTo(0, latest) - }) + el.scrollTo(0, latest) }, })