Skip to content

Commit cf2dd42

Browse files
authored
Fix(bds): 캐러셀 컴포넌트 IOS, And 대응 (team-bofit#477)
2 parents 697e0a2 + d1c4c86 commit cf2dd42

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

apps/client/src/widgets/home/components/info-section/info-section.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const InfoSection = () => {
3434
</div>
3535
<Carousel slidesPerView={4.5} autoPlay className={styles.homeCardList}>
3636
{homeCardConfig.map((card, index) => (
37-
<Carousel.Item key={index} style={{ width: 'auto' }}>
37+
<Carousel.Item key={index}>
3838
<HomeCard
3939
icon={
4040
<img

packages/bds-ui/src/components/carousel/carousel.css.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const container = style({
99
height: '100%',
1010
overflowX: 'scroll',
1111
userSelect: 'none',
12+
WebkitOverflowScrolling: 'touch',
13+
touchAction: 'pan-x',
1214
});
1315

1416
export const slideContainer = style({
@@ -20,6 +22,7 @@ export const slideContainer = style({
2022
gap: '1rem',
2123
userSelect: 'none',
2224
WebkitUserSelect: 'none',
25+
touchAction: 'pan-x',
2326
});
2427

2528
export const slide = style({

packages/bds-ui/src/components/carousel/carousel.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const Carousel = ({
134134
if (autoSlideWidth > 0 && containerWidth > 0) {
135135
const config: CarouselControllerConfig = {
136136
totalItems,
137-
slidesPerView: 1, // 항상 1개씩 이동
137+
slidesPerView: 1,
138138
slideWidth: (autoSlideWidth / containerWidth) * 100,
139139
infinite: effectiveInfinite,
140140
};
@@ -370,8 +370,10 @@ const Carousel = ({
370370
transform: getTransform(),
371371
transition: isDragging
372372
? 'none'
373-
: 'transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94)',
374-
cursor: isDragging ? 'grabbing' : 'pointer',
373+
: autoPlay
374+
? 'none'
375+
: 'transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94)',
376+
cursor: isDragging ? 'grabbing' : 'grab',
375377
height: maxSlideHeight ? `${maxSlideHeight}px` : 'auto',
376378
width: isAutoMode ? 'max-content' : '100%',
377379
}}

packages/bds-ui/src/components/carousel/hooks/use-carousel-touch.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)