Skip to content

Commit f5918c2

Browse files
committed
Make autoscroll more accurate
1 parent 3c7e5b0 commit f5918c2

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/SortableList.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,23 +333,39 @@ export default class SortableList extends Component {
333333
this._startAutoScroll({
334334
direction: -1,
335335
shouldScroll: () => this._contentOffset.y > 0,
336+
getScrollStep: (stepIndex) => {
337+
const nextStep = this._getScrollStep(stepIndex);
338+
339+
return this._contentOffset.y - nextStep < 0
340+
? this._contentOffset.y
341+
: nextStep;
342+
},
336343
});
337344
} else if (inAutoScrollDownArea) {
338345
this._startAutoScroll({
339346
direction: 1,
340347
shouldScroll: () => {
341-
const {
342-
contentHeight,
343-
containerLayout,
344-
} = this.state;
348+
const {contentHeight, containerLayout} = this.state;
345349

346350
return this._contentOffset.y < contentHeight - containerLayout.height;
347351
},
352+
getScrollStep: (stepIndex) => {
353+
const nextStep = this._getScrollStep(stepIndex);
354+
const {contentHeight, containerLayout} = this.state;
355+
356+
return this._contentOffset.y + nextStep > contentHeight - containerLayout.height
357+
? contentHeight - containerLayout.height - this._contentOffset.y
358+
: nextStep;
359+
},
348360
});
349361
}
350362
}
351363

352-
_startAutoScroll({direction, shouldScroll}) {
364+
_getScrollStep(stepIndex) {
365+
return stepIndex > 3 ? 60 : 30;
366+
}
367+
368+
_startAutoScroll({direction, shouldScroll, getScrollStep}) {
353369
if (!shouldScroll()) {
354370
return;
355371
}
@@ -358,15 +374,8 @@ export default class SortableList extends Component {
358374
let counter = 0;
359375

360376
this._autoScrollInterval = setInterval(() => {
361-
counter++;
362377
if (shouldScroll()) {
363-
let dy;
364-
if (counter > 3) {
365-
dy = 60;
366-
} else {
367-
dy = 30;
368-
}
369-
dy = direction * dy;
378+
const dy = direction * getScrollStep(counter++);
370379
this.scrollBy({dy});
371380
this._rows[activeRowKey].moveBy({dy});
372381
} else {

0 commit comments

Comments
 (0)