Skip to content

Two finger touch gesture events #39

@tim-soft

Description

@tim-soft

I modified a local version of react-with-gesture to return a simple distance between two fingers

const initialState = {
  // [Distance, Scale]
  pinch: [0, 1],
}

handleDown() {
  const newProps {
     {...}
     pinch: [0, state.pinch[1]],
  }
}

handleMove() {
  // Get the current pinch distance from touch event
  const pinchDistance = (() => {
    if (event.touches && event.touches.length === 2) {
      const [finger1, finger2] = event.touches;
        return Math.hypot(
          finger1.pageX - finger2.pageX,
          finger1.pageY - finger2.pageY
        );
      }
    return 0;
  })();

  // Compare to previous pinch distance, find delta
  const pinchDelta = pinchDistance - state.pinch[0];
  {...}

  return {
    {...},
    pinch: [pinchDistance, pinchScale]
  }
}

I'm using this for calculating a pinch/zoom scale(x) factor. While I'd like to see this lib support two finger events, what I've got feels really specific to my usecase.

What would/should the api look like if it had handlers/events specific to two finger gestures?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions