Skip to content

Commit 0743401

Browse files
committed
feat(ui): slides support swipe gesture
1 parent c71e227 commit 0743401

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/site/src/styles/routes/layout.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
width: 28px;
8181
height: 2px;
8282
background-color: var(--#{$rd-prefix}text-color);
83-
border-radius: 50%;
83+
/* stylelint-disable-next-line declaration-property-value-allowed-list */
84+
border-radius: 1px;
8485
/* stylelint-disable-next-line declaration-property-value-disallowed-list */
8586
transition: all 300ms linear;
8687
transform-origin: center;

packages/ui/src/components/slides/Slides.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
6363
//#endregion
6464

6565
const dataRef = useRef<{
66+
startDragTime: number;
6667
clearTid?: () => void;
67-
}>({});
68+
}>({
69+
startDragTime: 0,
70+
});
6871

6972
const async = useAsync();
7073

@@ -214,7 +217,13 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
214217
break;
215218
}
216219
}
217-
changeActiveId(dList[newIndex].id);
220+
if (newIndex === activeIndex) {
221+
if (performance.now() - dataRef.current.startDragTime < 300 && Math.abs(dragDistance) > 40) {
222+
changeActiveId(dList[Math.max(newIndex - 1, 0)].id);
223+
}
224+
} else {
225+
changeActiveId(dList[newIndex].id);
226+
}
218227
} else {
219228
let newIndex = activeIndex;
220229
let size = 0;
@@ -226,7 +235,13 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
226235
break;
227236
}
228237
}
229-
changeActiveId(dList[newIndex].id);
238+
if (newIndex === activeIndex) {
239+
if (performance.now() - dataRef.current.startDragTime < 300 && Math.abs(dragDistance) > 40) {
240+
changeActiveId(dList[Math.min(newIndex + 1, dList.length - 1)].id);
241+
}
242+
} else {
243+
changeActiveId(dList[newIndex].id);
244+
}
230245
}
231246
}
232247
setDragStartPosition(undefined);
@@ -302,10 +317,12 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
302317

303318
if (e.button === 0) {
304319
setDragStartPosition(e[dVertical ? 'clientY' : 'clientX']);
320+
dataRef.current.startDragTime = performance.now();
305321
}
306322
}}
307323
onTouchStart={(e) => {
308324
setDragStartPosition(e.touches[0][dVertical ? 'clientY' : 'clientX']);
325+
dataRef.current.startDragTime = performance.now();
309326
}}
310327
onTouchEnd={() => {
311328
handleDragEnd();

0 commit comments

Comments
 (0)