Handle flex "column-reverse" for mouse drag scrolling inertia

This commit is contained in:
schroda
2025-01-20 02:37:06 +01:00
parent 18a46c0a28
commit eeb811bf2d

View File

@@ -56,6 +56,15 @@ export const useMouseDragScroll = (
return isRTLDirection || (!isRTLDirection && isFlexDirectionReversed); return isRTLDirection || (!isRTLDirection && isFlexDirectionReversed);
}; };
const isTopReversed = () => {
if (!elementStyle.current) {
elementStyle.current = getComputedStyle(element);
}
return elementStyle.current.flexDirection === 'column-reverse';
};
const handleScrollX = scrollDirection !== ScrollDirection.Y; const handleScrollX = scrollDirection !== ScrollDirection.Y;
const handleScrollY = scrollDirection !== ScrollDirection.X; const handleScrollY = scrollDirection !== ScrollDirection.X;
@@ -116,7 +125,7 @@ export const useMouseDragScroll = (
]; ];
const newScrollPos = [ const newScrollPos = [
coerceIn(scrollAtT0.current[X] - delta[X], isRTL() ? -maxScrollPos[X] : 0, maxScrollPos[X]), coerceIn(scrollAtT0.current[X] - delta[X], isRTL() ? -maxScrollPos[X] : 0, maxScrollPos[X]),
coerceIn(scrollAtT0.current[Y] - delta[Y], 0, maxScrollPos[Y]), coerceIn(scrollAtT0.current[Y] - delta[Y], isTopReversed() ? -maxScrollPos[Y] : 0, maxScrollPos[Y]),
]; ];
const isScrollXPossible = newScrollPos[X] !== 0 || newScrollPos[X] !== maxScrollPos[X]; const isScrollXPossible = newScrollPos[X] !== 0 || newScrollPos[X] !== maxScrollPos[X];