From 8b62ee3dfe489fc1890f099cc26c527d94f4ddbd Mon Sep 17 00:00:00 2001
From: "wangtianli.y" <wangtianli.y@bytedance.com>
Date: Mon, 5 Aug 2024 16:10:13 +0800
Subject: [PATCH] fix: fix carousel scrolling bug when trigger click

---
 .../arcodesign/components/carousel/index.tsx  | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/packages/arcodesign/components/carousel/index.tsx b/packages/arcodesign/components/carousel/index.tsx
index c6e9c9da..2560d9a9 100644
--- a/packages/arcodesign/components/carousel/index.tsx
+++ b/packages/arcodesign/components/carousel/index.tsx
@@ -563,6 +563,11 @@ const Carousel = forwardRef((props: CarouselProps, ref: Ref<CarouselRef>) => {
             if (posAdjustingRef.current) {
                 return;
             }
+            // touchMove触发时,阻止handleTouchStart多次执行(如点击事件)
+            // @en When touchMove is triggered, prevent handleTouchStart from executing multiple times (such as click events)
+            if (touchStartedRef.current && touchMovedRef.current) {
+                return;
+            }
             touchStartedRef.current = true;
             touchMovedRef.current = false;
             clear();
@@ -1034,16 +1039,18 @@ const Carousel = forwardRef((props: CarouselProps, ref: Ref<CarouselRef>) => {
             jumpTo(index, false);
             return;
         }
-        if (
-            !touchStartedRef.current ||
-            !touchMovedRef.current ||
-            posAdjustingRef.current ||
-            touchStoppedRef.current
-        ) {
+        if (!touchStartedRef.current) {
             return;
         }
         touchStartedRef.current = false;
+        if (!touchMovedRef.current) {
+            setPlayIntervalRef.current();
+            return;
+        }
         touchMovedRef.current = false;
+        if (posAdjustingRef.current || touchStoppedRef.current) {
+            return;
+        }
         const touchEndTime = new Date().getTime();
         const dis = Math.abs(distance);
         const speed = (dis / (touchEndTime - touchStartTimeRef.current)) * 1000;