@@ -42,6 +42,7 @@ function useDraggableElement({
42
42
} : DraggableElementProps ) {
43
43
const [ clientYPosition , setClientYPosition ] = useState < number | null > ( null ) ;
44
44
const [ initialClickAdjustment , setInitialClickAdjustment ] = useState ( 0 ) ;
45
+ const [ scrollEdgeSize , setScrollEdgeSize ] = useState < number > ( ) ;
45
46
const [ segments , setSegments ] = useState < HTMLDivElement [ ] > ( [ ] ) ;
46
47
const { alignStartDateToTimeline, getCumulativeScrollTop } = useTimelineUtils (
47
48
{
@@ -52,23 +53,24 @@ function useDraggableElement({
52
53
) ;
53
54
54
55
const draggingAtTopEdge = useMemo ( ( ) => {
55
- if ( clientYPosition && timelineRef . current ) {
56
+ if ( clientYPosition && timelineRef . current && scrollEdgeSize ) {
56
57
return (
57
- clientYPosition - timelineRef . current . offsetTop <
58
- timelineRef . current . clientHeight * 0.03 && isDragging
58
+ clientYPosition - timelineRef . current . offsetTop < scrollEdgeSize &&
59
+ isDragging
59
60
) ;
60
61
}
61
- } , [ clientYPosition , timelineRef , isDragging ] ) ;
62
+ } , [ clientYPosition , timelineRef , isDragging , scrollEdgeSize ] ) ;
62
63
63
64
const draggingAtBottomEdge = useMemo ( ( ) => {
64
- if ( clientYPosition && timelineRef . current ) {
65
+ if ( clientYPosition && timelineRef . current && scrollEdgeSize ) {
65
66
return (
66
67
clientYPosition >
67
- ( timelineRef . current . clientHeight + timelineRef . current . offsetTop ) *
68
- 0.97 && isDragging
68
+ timelineRef . current . clientHeight +
69
+ timelineRef . current . offsetTop -
70
+ scrollEdgeSize && isDragging
69
71
) ;
70
72
}
71
- } , [ clientYPosition , timelineRef , isDragging ] ) ;
73
+ } , [ clientYPosition , timelineRef , isDragging , scrollEdgeSize ] ) ;
72
74
73
75
const getClientYPosition = useCallback (
74
76
( e : MouseEvent | TouchEvent ) => {
@@ -290,17 +292,26 @@ function useDraggableElement({
290
292
}
291
293
} ) ;
292
294
293
- if ( draggingAtTopEdge || draggingAtBottomEdge ) {
294
- let newPosition = clientYPosition ;
295
-
295
+ if ( ( draggingAtTopEdge || draggingAtBottomEdge ) && scrollEdgeSize ) {
296
296
if ( draggingAtTopEdge ) {
297
- newPosition = scrolled - segmentHeight ;
298
- timelineRef . current . scrollTop = newPosition ;
297
+ const intensity = Math . max (
298
+ 0 ,
299
+ ( scrollEdgeSize - ( clientYPosition - timelineTopAbsolute ) ) /
300
+ scrollEdgeSize ,
301
+ ) ;
302
+ timelineRef . current . scrollTop -= segmentHeight * intensity ;
299
303
}
300
304
301
305
if ( draggingAtBottomEdge ) {
302
- newPosition = scrolled + segmentHeight ;
303
- timelineRef . current . scrollTop = newPosition ;
306
+ const intensity = Math . max (
307
+ 0 ,
308
+ ( clientYPosition -
309
+ timelineTopAbsolute -
310
+ ( timelineRef . current . getBoundingClientRect ( ) . height -
311
+ scrollEdgeSize ) ) /
312
+ scrollEdgeSize ,
313
+ ) ;
314
+ timelineRef . current . scrollTop += segmentHeight * intensity ;
304
315
}
305
316
}
306
317
@@ -436,6 +447,12 @@ function useDraggableElement({
436
447
// eslint-disable-next-line react-hooks/exhaustive-deps
437
448
} , [ timelineCollapsed ] ) ;
438
449
450
+ useEffect ( ( ) => {
451
+ if ( timelineRef . current ) {
452
+ setScrollEdgeSize ( timelineRef . current . clientHeight * 0.03 ) ;
453
+ }
454
+ } , [ timelineRef ] ) ;
455
+
439
456
return { handleMouseDown, handleMouseUp, handleMouseMove } ;
440
457
}
441
458
0 commit comments