Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable two finger scroll and drag in react? #63

Open
okanji opened this issue Sep 6, 2023 · 1 comment
Open

How to enable two finger scroll and drag in react? #63

okanji opened this issue Sep 6, 2023 · 1 comment
Labels
question Further information is requested

Comments

@okanji
Copy link

okanji commented Sep 6, 2023

I am having trouble getting two finger pan and drag to work like it does in the demo. I seem to have pinch working but I would prefer it to zoom to the mouse position like it does in the demo. Is this all supposed to work out of the box or does one need to implement this?

"use client";

import React, { useEffect, useState, useRef } from "react";
import InfiniteViewer from "react-infinite-viewer";

export default function Gestures({ children }: { children: React.ReactNode }) {
  const [zoom, setZoom] = useState(1);

  return (
    <InfiniteViewer
      className="viewer"
      usePinch={true}
      useMouseDrag={true}
      useWheelScroll={true}
      useAutoZoom={true}
      zoomRange={[0.1, 10]}
      maxPinchWheel={10}
      zoom={zoom}
      margin={0}
      threshold={0}
      rangeX={[0, 0]}
      rangeY={[0, 0]}
      onDragStart={(e) => {
        const target = e.inputEvent.target;
        console.log(target);
        if (target.nodeName === "A") {
          e.stop();
        }
      }}
      onScroll={(e) => {
        console.log(e);
      }}
      onPinch={(e) => {
        const newZoom = Math.max(0.1, e.zoom);
        setZoom(newZoom);
        console.log("Pinch", newZoom);
      }}
    >
      {children}
    </InfiniteViewer>
  );
}

Would really appreciate some help. This could be a helpful react example it someone could assists.

Note that in my example, children is an svg

Thanks!

@daybrush daybrush added the question Further information is requested label Sep 11, 2023
@daybrush
Copy link
Owner

@okanji

Because rangeX and rangeY are 0,0, the position according to the mouse may not be displayed properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants