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

Is there any way to do rotate in this library? #458

Open
Tamagouuu opened this issue Mar 4, 2024 · 2 comments
Open

Is there any way to do rotate in this library? #458

Tamagouuu opened this issue Mar 4, 2024 · 2 comments

Comments

@Tamagouuu
Copy link

It will be good if the viewer have ability to rotate, isn't it?

@hadarhubara10
Copy link

It is also necessary for me

@guyzmo
Copy link

guyzmo commented May 30, 2024

I implemented rotation outside of the lib by doing something like this:

given the ref to an image:

  const imageRef = useRef<HTMLImageElement>(null)

I implemented and exposed the following API (through a custom context):

    const rotateClockwise = useCallback(() => {
      if (!imageRef?.current) return
      setRotation((rotation) => {
        const newRotation = (rotation + 90) % 360
        imageRef.current!.style.transform = `rotate(${newRotation}deg)`
        return newRotation
      })
    }, [setRotation, imageRef]);
    const rotateCounterClockwise = useCallback(() => {
      if (!imageRef?.current) return
      setRotation((rotation) => {
        const newRotation = (rotation - 90) % 360
        imageRef.current!.style.transform = `rotate(${newRotation}deg)`
        return newRotation
      })
    }, [setRotation, imageRef]);

Then I implemented it on the image itself:

  return (
      <TransformWrapper>
        <ImageControls />
        <TransformComponent>
          <img ref={imageRef} id="img" src={uri} />
        </TransformComponent>
      </TransformWrapper>
   )

then the ImageControls is just a custom version of the default Controls that implements both useControls() for the lib and my own context.

TBH, if I got little time, I believe it can be easy to add to the API

HTH

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

No branches or pull requests

3 participants