@@ -28,6 +28,10 @@ export const useCarouselTouch = ({
2828 /** 누를 때 시작 위치 저장 */
2929 const handlePointerDown = useCallback (
3030 ( e : PointerEvent < Element > ) => {
31+ if ( e . pointerType === 'touch' ) {
32+ e . preventDefault ( ) ;
33+ }
34+
3135 setIsDragging ( true ) ;
3236 setStartX ( e . clientX ) ;
3337 setDragOffset ( 0 ) ;
@@ -49,6 +53,10 @@ export const useCarouselTouch = ({
4953 return ;
5054 }
5155
56+ if ( e . pointerType === 'touch' ) {
57+ e . preventDefault ( ) ;
58+ }
59+
5260 const dragDiff = startX - e . clientX ;
5361 const diff = Math . abs ( dragDiff ) ;
5462
@@ -74,12 +82,22 @@ export const useCarouselTouch = ({
7482 return ;
7583 }
7684
77- if ( ! autoPlay ) {
78- if ( hasMoved ) {
79- const diff = startX - e . clientX ;
80- const containerWidth = e . currentTarget . clientWidth || 1 ;
81- const dragOffsetPercent = ( diff / containerWidth ) * 100 ;
85+ const diff = startX - e . clientX ;
86+ const containerWidth = e . currentTarget . clientWidth || 1 ;
87+ const dragOffsetPercent = ( diff / containerWidth ) * 100 ;
88+
89+ if ( autoPlay ) {
90+ const newState = controller . handleDragEnd (
91+ carouselState ,
92+ dragOffsetPercent ,
93+ {
94+ isAutoPlay : true ,
95+ } ,
96+ ) ;
8297
98+ onStateUpdate ( newState ) ;
99+ } else {
100+ if ( hasMoved ) {
83101 const newState = controller . handleDragEnd (
84102 carouselState ,
85103 dragOffsetPercent ,
@@ -94,20 +112,6 @@ export const useCarouselTouch = ({
94112 clickTarget . click ( ) ;
95113 }
96114 }
97- } else {
98- const diff = startX - e . clientX ;
99- const containerWidth = e . currentTarget . clientWidth || 1 ;
100- const dragOffsetPercent = ( diff / containerWidth ) * 100 ;
101-
102- const newState = controller . handleDragEnd (
103- carouselState ,
104- dragOffsetPercent ,
105- {
106- isAutoPlay : true ,
107- } ,
108- ) ;
109-
110- onStateUpdate ( newState ) ;
111115 }
112116
113117 setIsDragging ( false ) ;
0 commit comments