Skip to content

Commit

Permalink
Don't change direction if the new scroll position is the same as current
Browse files Browse the repository at this point in the history
This avoids a case where we'd switch to previous when returning to 0 where
0 was also the starting point.
  • Loading branch information
sebmarkbage committed Feb 19, 2025
1 parent 9551248 commit f40fe8d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,10 @@ export function subscribeToGestureDirection(
const scrollCallback = () => {
const newTime = provider.currentTime;
if (newTime !== null) {
directionCallback(
typeof newTime === 'number'
? newTime > currentOffset
: newTime.value > currentOffset,
);
const newValue = typeof newTime === 'number' ? newTime : newTime.value;
if (newValue !== currentOffset) {
directionCallback(newValue > currentOffset);
}
}
};
element.addEventListener('scroll', scrollCallback, false);
Expand All @@ -1521,11 +1520,10 @@ export function subscribeToGestureDirection(
const rafCallback = () => {
const newTime = provider.currentTime;
if (newTime !== null) {
directionCallback(
typeof newTime === 'number'
? newTime > currentOffset
: newTime.value > currentOffset,
);
const newValue = typeof newTime === 'number' ? newTime : newTime.value;
if (newValue !== currentOffset) {
directionCallback(newValue > currentOffset);
}
}
callbackID = requestAnimationFrame(rafCallback);
};
Expand Down

0 comments on commit f40fe8d

Please sign in to comment.