free-transform icon indicating copy to clipboard operation
free-transform copied to clipboard

Aspect Ratio

Open SamirElkhatib opened this issue 6 years ago • 2 comments

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?

SamirElkhatib avatar Feb 28 '19 14:02 SamirElkhatib

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

skmail avatar Apr 08 '19 16:04 skmail

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!

LeoMsky avatar May 19 '21 01:05 LeoMsky