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(feedback): Reduce force layout in screenshots #11181

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions packages/feedback/src/screenshot/components/ScreenshotEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ const constructRect = (box: Box): Rect => {
};

const getContainedSize = (img: HTMLCanvasElement): Box => {
const imgClientHeight = img.clientHeight;
const imgClientWidth = img.clientWidth;
const ratio = img.width / img.height;
let width = img.clientHeight * ratio;
let height = img.clientHeight;
if (width > img.clientWidth) {
width = img.clientWidth;
height = img.clientWidth / ratio;
let width = imgClientHeight * ratio;
let height = imgClientHeight;
if (width > imgClientWidth) {
width = imgClientWidth;
height = imgClientWidth / ratio;
}
const x = (img.clientWidth - width) / 2;
const y = (img.clientHeight - height) / 2;
const x = (imgClientWidth - width) / 2;
const y = (imgClientHeight - height) / 2;
return { startX: x, startY: y, endX: width + x, endY: height + y };
};

Expand Down Expand Up @@ -215,9 +217,11 @@ export function makeScreenshotEditorComponent({ h, imageBuffer, dialog }: Factor
if (!context) {
throw new Error('Could not get canvas context');
}
imageBuffer.width = imageSource.videoWidth;
imageBuffer.height = imageSource.videoHeight;
context.drawImage(imageSource, 0, 0, imageSource.videoWidth, imageSource.videoHeight);
const sourceWidth = imageSource.videoWidth;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not mentioned in the doc, but done as a precaution

const sourceHeight = imageSource.videoHeight;
imageBuffer.width = sourceWidth;
imageBuffer.height = sourceHeight;
context.drawImage(imageSource, 0, 0, sourceWidth, sourceHeight);
},
[imageBuffer],
),
Expand Down