Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export {
Vector2,
};

const defaultProps: ConfigurationOptions = {
const defaultProps = {
delta: 10,
preventScrollOnSwipe: false,
rotationAngle: 0,
trackMouse: false,
trackTouch: true,
swipeDuration: Infinity,
touchEventOptions: { passive: true },
};
} satisfies ConfigurationOptions;
const initialState: SwipeableState = {
first: true,
initial: [0, 0],
Expand Down Expand Up @@ -278,9 +278,13 @@ function getHandlers(
],
[touchEnd, onEnd, baseOptions],
];
tls.forEach(([e, h, o]) => el.addEventListener(e, h, o));
tls.forEach(([e, h, o]) => {
el.addEventListener(e, h, o)
});
// return properly scoped cleanup method for removing listeners, options not required
cleanup = () => tls.forEach(([e, h]) => el.removeEventListener(e, h));
cleanup = () => tls.forEach(([e, h]) => {
el.removeEventListener(e, h)
});
}
return cleanup;
};
Expand Down Expand Up @@ -395,11 +399,12 @@ export function useSwipeable(options: SwipeableProps): SwipeableHandlers {
const [handlers, attachTouch] = React.useMemo(
() =>
getHandlers(
(stateSetter) =>
(transientState.current = stateSetter(
(stateSetter) => {
transientState.current = stateSetter(
transientState.current,
transientProps.current
)),
);
},
{ trackMouse }
),
[trackMouse]
Expand Down