@@ -24,6 +24,7 @@ const MainBanner = () => {
2424 const [ isAnimate , setIsAnimate ] = useState ( true ) ;
2525 const [ isDragging , setIsDragging ] = useState ( false ) ;
2626 const [ startX , setStartX ] = useState ( 0 ) ;
27+ const [ startY , setStartY ] = useState ( 0 ) ;
2728 const [ currentX , setCurrentX ] = useState ( 0 ) ;
2829
2930 const timerRef = useRef < NodeJS . Timeout | null > ( null ) ;
@@ -120,6 +121,55 @@ const MainBanner = () => {
120121 }
121122 } ;
122123
124+ const handleTouchStart = ( e : React . TouchEvent ) => {
125+ stopAutoSlide ( ) ;
126+ setIsDragging ( true ) ;
127+ const touchX = e . touches [ 0 ] . clientX ;
128+ const touchY = e . touches [ 0 ] . clientY ;
129+ setStartX ( touchX ) ;
130+ setStartY ( touchY ) ;
131+ setCurrentX ( touchX ) ;
132+ setIsAnimate ( false ) ;
133+ } ;
134+
135+ const handleTouchMove = ( e : React . TouchEvent ) => {
136+ if ( ! isDragging ) return ;
137+ const touchX = e . touches [ 0 ] . clientX ;
138+ const touchY = e . touches [ 0 ] . clientY ;
139+
140+ const diffX = Math . abs ( touchX - startX ) ;
141+ const diffY = Math . abs ( touchY - startY ) ;
142+
143+ // ์คํฌ๋กค ์๋ ํ์
144+ if ( diffY > diffX && diffY > 10 ) {
145+ setIsDragging ( false ) ;
146+ return ;
147+ }
148+
149+ setCurrentX ( touchX ) ;
150+ } ;
151+
152+ const handleTouchEnd = ( ) => {
153+ if ( ! isDragging ) {
154+ startAutoSlide ( ) ;
155+ return ;
156+ }
157+
158+ setIsDragging ( false ) ;
159+ startAutoSlide ( ) ;
160+
161+ const diff = currentX - startX ;
162+ const threshold = 50 ;
163+
164+ if ( diff < - threshold ) {
165+ moveNext ( ) ;
166+ } else if ( diff > threshold ) {
167+ movePrev ( ) ;
168+ } else {
169+ setIsAnimate ( true ) ;
170+ }
171+ } ;
172+
123173 let displayIndex = currentIndex ;
124174 if ( currentIndex === 0 ) displayIndex = totalOriginalSlides ;
125175 else if ( currentIndex === slides . length - 1 ) displayIndex = 1 ;
@@ -134,12 +184,16 @@ const MainBanner = () => {
134184 style = { {
135185 transform : `translateX(calc(-${ currentIndex * 100 } % + ${ dragOffset } px))` ,
136186 transition : isAnimate ? 'transform 0.5s ease-in-out' : 'none' ,
187+ touchAction : 'pan-y' ,
137188 } }
138189 onTransitionEnd = { handleTransitionEnd }
139190 onMouseDown = { handleMouseDown }
140191 onMouseMove = { handleMouseMove }
141192 onMouseUp = { handleMouseUp }
142- onMouseLeave = { handleMouseLeave } >
193+ onMouseLeave = { handleMouseLeave }
194+ onTouchStart = { handleTouchStart }
195+ onTouchMove = { handleTouchMove }
196+ onTouchEnd = { handleTouchEnd } >
143197 { slides . map ( ( banner ) => (
144198 < div
145199 key = { banner . uniqueKey }
0 commit comments