Glazzes / react-native-zoom-toolkit

Zoom anything you want! Most complete pinch to zoom utilities for React Native
https://glazzes.github.io/react-native-zoom-toolkit/
MIT License
193 stars 11 forks source link

feat: add for choosing rotation direction #32

Closed iqorlobanov closed 4 months ago

iqorlobanov commented 4 months ago

When using this package, I noticed that it does not have the option to rotate the image counterclockwise. In my case, I just needed to rotate the image counterclockwise and I decided to add a new function rotateWithDirection

What's been added

rotateWithDirection

Rotate the component 90 degrees (or -90 degrees) clockwise or counterclockwise in a range from 0 to 360 degrees (or 0 to -360 degrees).

Name Type Default Description
animate boolean \| undefined true Whether to animate the transition or not.
clockwise boolean \| undefined true Whether to rotate clockwise (90 degrees) or counterclockwise (-90 degrees)
cb function \| undefined undefined Callback to trigger at the beginning of the transition, as its only argument receives the angle your component will transition to, this angle ranges from 0 to 360 degrees (or -360 degrees) (at 360 or -360 degrees it's clamped to 0).

How it works

const clockwiseRotation = true; // Use `false` for counterclockwise rotation
cropZoomRef.current?.rotateWithDirection(true, clockwiseRotation, (radians) => {
    // Convert the rotation angle from radians to degrees
    const rotationAngle = radians * (180 / Math.PI);

    console.log(rotationAngle);
});
Glazzes commented 4 months ago

Hi there, excuse me for the late response, I have been considering whether this could make a good addittion to the library or not, I think it may good for the library at least for now until the next major both rotate methods get collapsed into a single one.

Did you manually test whether the direction produced accurate crops? By accurate I mean what you see on screen it's what you get as a result.

iqorlobanov commented 4 months ago

Did you manually test whether the direction produced accurate crops? By accurate I mean what you see on screen it's what you get as a result.

Yes, everything has been tested on both platforms

Glazzes commented 4 months ago

Alright then, everything is looking good to me.