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

When dragging corner lockAspectRatio is true, use width to compute height #798

Open
yf-yang opened this issue Jan 29, 2024 · 1 comment
Open

Comments

@yf-yang
Copy link

yf-yang commented Jan 29, 2024

Overview of the problem

This is a behavioral change. Not sure if another new option should be added, or just change the behavior.

When lockAspectRatio is true and corner is dragged, currently, the new height is kept while width is computed based on the aspect ratio. It makes more sense to compute height based on width, because usually the width is constrained (by window width) and height is infinite when overflow the screen.

The code is here:

re-resizable/src/index.tsx

Lines 582 to 616 in 0f6b2dd

calculateNewSizeFromDirection(clientX: number, clientY: number) {
const scale = this.props.scale || 1;
const resizeRatio = this.props.resizeRatio || 1;
const { direction, original } = this.state;
const { lockAspectRatio, lockAspectRatioExtraHeight, lockAspectRatioExtraWidth } = this.props;
let newWidth = original.width;
let newHeight = original.height;
const extraHeight = lockAspectRatioExtraHeight || 0;
const extraWidth = lockAspectRatioExtraWidth || 0;
if (hasDirection('right', direction)) {
newWidth = original.width + ((clientX - original.x) * resizeRatio) / scale;
if (lockAspectRatio) {
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
}
}
if (hasDirection('left', direction)) {
newWidth = original.width - ((clientX - original.x) * resizeRatio) / scale;
if (lockAspectRatio) {
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
}
}
if (hasDirection('bottom', direction)) {
newHeight = original.height + ((clientY - original.y) * resizeRatio) / scale;
if (lockAspectRatio) {
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
}
}
if (hasDirection('top', direction)) {
newHeight = original.height - ((clientY - original.y) * resizeRatio) / scale;
if (lockAspectRatio) {
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
}
}
return { newWidth, newHeight };
}

Execute top/bottom if first, then right/left if will change the behavior.

@yf-yang
Copy link
Author

yf-yang commented Jan 29, 2024

I can submit a PR.

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

1 participant