Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add thresholdOffset for infinite scrolling #1616

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ type ScrollControlsProps = {
/** Infinite scroll, default false (experimental!) */
infinite?: boolean
/** Defines the length of the scroll area, each page is height:100%, default 1 */
thresholdOffset?: number
/** Offset the reset threshold, at the end of the scroll bar on infinite scroll */
pages?: number
/** A factor that increases scroll bar travel, default 1 */
distance?: number
Expand Down
5 changes: 4 additions & 1 deletion src/web/ScrollControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type ScrollControlsProps = {
* going between, say, page 1 and 2, but not for pages far apart as it'll move very rapid,
* then a maxSpeed of e.g. 3 which will clamp the speed to 3 units per second, it may now
* take much longer than damping to reach the target if it is far away. Default: Infinity */
thresholdOffset?: number
/** Offset the reset threshold, at the end of the scroll bar on infinite scroll */
maxSpeed?: number
enabled?: boolean
style?: React.CSSProperties
Expand Down Expand Up @@ -54,6 +56,7 @@ export function ScrollControls({
eps = 0.00001,
enabled = true,
infinite,
thresholdOffset = 0,
horizontal,
pages = 1,
distance = 1,
Expand Down Expand Up @@ -171,7 +174,7 @@ export function ScrollControls({

if (infinite) {
if (!disableScroll) {
if (current >= scrollThreshold) {
if (current >= scrollThreshold - thresholdOffset) {
const damp = 1 - state.offset
el[horizontal ? 'scrollLeft' : 'scrollTop'] = 1
scroll.current = state.offset = -damp
Expand Down