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

fix: Fixed the issue of abnormal scaling behavior of the Image compon… #2407

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions packages/semi-foundation/image/previewImageFoundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,28 @@ export default class PreviewImageFoundation<P = Record<string, any>, S = Record<
};

if (e && imageDOM && e.target === imageDOM) {
const { x: offsetX, y: offsetY } = this.calcBoundingRectMouseOffset({
width,
height,
offset: {
x: e.offsetX,
y: e.offsetY
},
rotation
});

const imageNewCenterX = e.clientX + (imageBound.width / 2 - offsetX) * changeScale;
const imageNewCenterY = e.clientY + (imageBound.height / 2 - offsetY) * changeScale;
const containerCenterX = this.containerWidth / 2;
const containerCenterY = this.containerHeight / 2;

newTranslateX = imageNewCenterX - containerCenterX;
newTranslateY = imageNewCenterY - containerCenterY;
let angle = rotation % 360;
angle < 0 && (angle = 360 + angle);
DaiQiangReal marked this conversation as resolved.
Show resolved Hide resolved
switch (angle) {
case 0:
newTranslateX = (e.offsetX - 0.5 * width) * (1 - newZoom / currZoom) + translate.x;
newTranslateY = (e.offsetY - 0.5 * height) * (1 - newZoom / currZoom) + translate.y;
break;
case 90:
newTranslateX = (0.5 * height - e.offsetY) * (1 - newZoom / currZoom) + translate.x;
newTranslateY = (e.offsetX - 0.5 * width) * (1 - newZoom / currZoom) + translate.y;
break;
case 180:
newTranslateX = (0.5 * width - e.offsetX) * (1 - newZoom / currZoom) + translate.x;
newTranslateY = (0.5 * height - e.offsetY) * (1 - newZoom / currZoom) + translate.y;
break;
case 270:
newTranslateX = (e.offsetY - 0.5 * height) * (1 - newZoom / currZoom) + translate.x;
newTranslateY = (0.5 * width - e.offsetX ) * (1 - newZoom / currZoom) + translate.y;
break;
default:
break;
}
}

const newTranslate = this.getSafeTranslate(newImageBound.width, newImageBound.height, newTranslateX, newTranslateY);
Expand Down
1 change: 1 addition & 0 deletions packages/semi-ui/image/_story/image.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ export const CustomContainer = () => {
style={{
height: 400,
position: "relative",
margin: '100px 200px',
}}
>
<ImagePreview
Expand Down
Loading