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

Receipts are displayed in the full size of canvas when not needed #42174

Merged
merged 8 commits into from
May 31, 2024
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};
Loading