@@ -63,8 +63,11 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
63
63
//#endregion
64
64
65
65
const dataRef = useRef < {
66
+ startDragTime : number ;
66
67
clearTid ?: ( ) => void ;
67
- } > ( { } ) ;
68
+ } > ( {
69
+ startDragTime : 0 ,
70
+ } ) ;
68
71
69
72
const async = useAsync ( ) ;
70
73
@@ -214,7 +217,13 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
214
217
break ;
215
218
}
216
219
}
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
+ }
218
227
} else {
219
228
let newIndex = activeIndex ;
220
229
let size = 0 ;
@@ -226,7 +235,13 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
226
235
break ;
227
236
}
228
237
}
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
+ }
230
245
}
231
246
}
232
247
setDragStartPosition ( undefined ) ;
@@ -302,10 +317,12 @@ export function DSlides<ID extends DId, T extends DSlideItem<ID>>(props: DSlides
302
317
303
318
if ( e . button === 0 ) {
304
319
setDragStartPosition ( e [ dVertical ? 'clientY' : 'clientX' ] ) ;
320
+ dataRef . current . startDragTime = performance . now ( ) ;
305
321
}
306
322
} }
307
323
onTouchStart = { ( e ) => {
308
324
setDragStartPosition ( e . touches [ 0 ] [ dVertical ? 'clientY' : 'clientX' ] ) ;
325
+ dataRef . current . startDragTime = performance . now ( ) ;
309
326
} }
310
327
onTouchEnd = { ( ) => {
311
328
handleDragEnd ( ) ;
0 commit comments