Skip to content

Commit 0cb2dc0

Browse files
authored
Merge pull request #42174 from samilabud/receipt_image_resize_fix_40788
Receipts are displayed in the full size of canvas when not needed
2 parents d3e5071 + c19a2f3 commit 0cb2dc0

File tree

1 file changed

+9
-10
lines changed
  • src/components/MultiGestureCanvas

1 file changed

+9
-10
lines changed

src/components/MultiGestureCanvas/utils.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ import type {CanvasSize, ContentSize} from './types';
22

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

5-
const getCanvasFitScale: GetCanvasFitScale = ({canvasSize, contentSize}) => {
6-
const scaleX = canvasSize.width / contentSize.width;
7-
const scaleY = canvasSize.height / contentSize.height;
8-
9-
const minScale = Math.min(scaleX, scaleY);
10-
const maxScale = Math.max(scaleX, scaleY);
11-
12-
return {scaleX, scaleY, minScale, maxScale};
13-
};
14-
155
/** Clamps a value between a lower and upper bound */
166
function clamp(value: number, lowerBound: number, upperBound: number) {
177
'worklet';
188

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

12+
const getCanvasFitScale: GetCanvasFitScale = ({canvasSize, contentSize}) => {
13+
const scaleX = clamp(canvasSize.width / contentSize.width, 0, 1);
14+
const scaleY = clamp(canvasSize.height / contentSize.height, 0, 1);
15+
const minScale = Math.min(scaleX, scaleY);
16+
const maxScale = Math.max(scaleX, scaleY);
17+
18+
return {scaleX, scaleY, minScale, maxScale};
19+
};
20+
2221
export {getCanvasFitScale, clamp};

0 commit comments

Comments
 (0)