Skip to content

Commit

Permalink
fix: rubberband scrolling for uikit vanilla by using milliseconds as …
Browse files Browse the repository at this point in the history
…delta time
  • Loading branch information
bbohlender committed Oct 17, 2024
1 parent a1df879 commit cec351a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/react/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export const Root: (
useFrame((_, delta) => {
whileOnFrameRef.current = true
for (const onFrame of onFrameSet) {
onFrame(delta)
//delta must be provided in milliseconds, therefore multiply by 1000
onFrame(delta * 1000)
}
whileOnFrameRef.current = false
})
Expand Down
8 changes: 4 additions & 4 deletions packages/uikit/src/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ export function computedScrollHandlers(

scrollVelocity.multiplyScalar(0.9) //damping scroll factor

if (Math.abs(scrollVelocity.x) < 10 /** px per second */) {
if (Math.abs(scrollVelocity.x) < 0.01 /** 10 px per second */) {
scrollVelocity.x = 0
} else {
root.requestFrame()
}

if (Math.abs(scrollVelocity.y) < 10 /** px per second */) {
if (Math.abs(scrollVelocity.y) < 0.01 /** 10 px per second */) {
scrollVelocity.y = 0
} else {
root.requestFrame()
Expand Down Expand Up @@ -234,7 +234,7 @@ export function computedScrollHandlers(

downPointerMap.set(pointerId, {
type: 'scroll-panel',
timestamp: performance.now() / 1000,
timestamp: performance.now(),
localPoint,
})
},
Expand Down Expand Up @@ -271,7 +271,7 @@ export function computedScrollHandlers(
scroll(event, distanceHelper.x, -distanceHelper.y, undefined, false)
return
}
const timestamp = performance.now() / 1000
const timestamp = performance.now()
const deltaTime = timestamp - prevInteraction.timestamp
scroll(event, -distanceHelper.x, distanceHelper.y, deltaTime, true)
prevInteraction.timestamp = timestamp
Expand Down

0 comments on commit cec351a

Please sign in to comment.