Skip to content

Commit

Permalink
Merge pull request #42174 from samilabud/receipt_image_resize_fix_40788
Browse files Browse the repository at this point in the history
Receipts are displayed in the full size of canvas when not needed
  • Loading branch information
arosiclair authored May 31, 2024
2 parents d3e5071 + c19a2f3 commit 0cb2dc0
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/components/MultiGestureCanvas/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import type {CanvasSize, ContentSize} from './types';

type GetCanvasFitScale = (props: {canvasSize: CanvasSize; contentSize: ContentSize}) => {scaleX: number; scaleY: number; minScale: number; maxScale: number};

const getCanvasFitScale: GetCanvasFitScale = ({canvasSize, contentSize}) => {
const scaleX = canvasSize.width / contentSize.width;
const scaleY = canvasSize.height / contentSize.height;

const minScale = Math.min(scaleX, scaleY);
const maxScale = Math.max(scaleX, scaleY);

return {scaleX, scaleY, minScale, maxScale};
};

/** Clamps a value between a lower and upper bound */
function clamp(value: number, lowerBound: number, upperBound: number) {
'worklet';

return Math.min(Math.max(lowerBound, value), upperBound);
}

const getCanvasFitScale: GetCanvasFitScale = ({canvasSize, contentSize}) => {
const scaleX = clamp(canvasSize.width / contentSize.width, 0, 1);
const scaleY = clamp(canvasSize.height / contentSize.height, 0, 1);
const minScale = Math.min(scaleX, scaleY);
const maxScale = Math.max(scaleX, scaleY);

return {scaleX, scaleY, minScale, maxScale};
};

export {getCanvasFitScale, clamp};

0 comments on commit 0cb2dc0

Please sign in to comment.