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

Aspect Ratio #2

Open
SamirElkhatib opened this issue Feb 28, 2019 · 2 comments
Open

Aspect Ratio #2

SamirElkhatib opened this issue Feb 28, 2019 · 2 comments

Comments

@SamirElkhatib
Copy link

Hello,
I'm trying to use this library to make a free-transform controlled component that preserves aspect ratio only when scaled from the corners (tr, tl, br, bl)...

My settings for the scale function look like this:

scale(
    scaleType,
    { startX, startY, x, y, scaleX, scaleY, width, height, angle, scaleLimit,
      scaleFromCenter: event.altKey,
      aspectRatio: true,
      enableAspectRatio: preserveAspectRatio,
    },
    onUpdate
);

preseveAspectRatio is sent true if scaleType is any of the corners

Issue:
Scaling still doesn't preserve aspect ratio except if shift key is pressed
the aspectRatio field seems to have no effect at all on the outcome. Also, after reviewing the source of scale.js I can't seem to understand this:

 if(!event.shiftKey && aspectRatio ){
      aspectRatio = false
} else if(event.shiftKey && !aspectRatio ){
      aspectRatio = true
}

The value of aspectRatio seems to be tied to event.shiftKey which makes it kind of neglected?

@skmail
Copy link
Owner

skmail commented Apr 8, 2019

Can you please put your code on https://codesandbox.io/

@LeoMsky
Copy link

LeoMsky commented May 19, 2021

Yes, I have the same problem! When "aspect" is set to true, it does not work.I try to modify the source code.
There is a logic error in line 97 of the scale. js file:

if(!event.shiftKey && aspectRatio ){
      aspectRatio = false
} else if(event.shiftKey && !aspectRatio ){
      aspectRatio = true
}

Modify to:

if(!event.shiftKey && !aspectRatio ){
      aspectRatio = false
} else if(event.shiftKey && !aspectRatio ){
      aspectRatio = true
}

And it can work well.
I think the better logic:
aspectRatio = aspectRatio || event.shiftKey
Please fix it as soon as possible, thank you!

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