Skip to content

Commit

Permalink
Merge pull request #198 from FormidableLabs/v6-starting-edges-at-zero
Browse files Browse the repository at this point in the history
V6 starting edges at zero
  • Loading branch information
urmit committed Aug 27, 2020
2 parents 572708e + 18f2e25 commit cb87958
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lib
dist
examples/static
coverage
package-lock.json
17 changes: 17 additions & 0 deletions __tests__/useSwipeable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ describe("useSwipeable", () => {
defaultPrevented = 0;
});

it("handles touch events that start at clientX or clientY 0", () => {
const swipeFuncs = getMockedSwipeFunctions();
const { getByText } = render(<SwipeableUsingHook {...swipeFuncs} />);

const touchArea = getByText(TESTING_TEXT);

fireEvent[TS](touchArea, cte({ x: 0, y: 100 }));
fireEvent[TM](touchArea, cte({ x: 0, y: 125 }));
fireEvent[TE](touchArea, cte({}));
fireEvent[TS](touchArea, cte({ x: 100, y: 0 }));
fireEvent[TM](touchArea, cte({ x: 125, y: 0 }));
fireEvent[TE](touchArea, cte({}));

expect(swipeFuncs.onSwiping).toHaveBeenCalledTimes(2);
expect(swipeFuncs.onSwiped).toHaveBeenCalledTimes(2);
});

it("handles touch events and fires correct props", () => {
const swipeFuncs = getMockedSwipeFunctions();
const { getByText } = render(<SwipeableUsingHook {...swipeFuncs} />);
Expand Down
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,9 @@ function getHandlers(

const onMove = (event: HandledEvents) => {
set((state, props) => {
if (
!state.xy[0] ||
!state.xy[1] ||
("touches" in event && event.touches.length > 1)
) {
// Discount a swipe if additional touches are present after
// a swipe has started.
if ("touches" in event && event.touches.length > 1) {
return state;
}
const { clientX, clientY } =
Expand Down

0 comments on commit cb87958

Please sign in to comment.