react-native-zoom-toolkit
Version:
Most complete set of pinch to zoom utilites for React Native
45 lines (43 loc) • 1.56 kB
JavaScript
export const getRatioSize = (aspectRatio, container) => {
'worklet';
if (container.width !== undefined) {
return {
width: container.width,
height: container.width / aspectRatio
};
}
return {
width: container.height * aspectRatio,
height: container.height
};
};
export const getCropRotatedSize = options => {
'worklet';
const {
crop,
angle,
resolution
} = options;
const cropAspectRatio = crop.width / crop.height;
let base = crop;
const flipped = angle % Math.PI === 0;
const aspectRatio = resolution.width / resolution.height;
const inverseAspectRatio = resolution.height / resolution.width;
const currentAspectRatio = flipped ? aspectRatio : inverseAspectRatio;
base = getRatioSize(currentAspectRatio, {
width: cropAspectRatio >= 1 ? undefined : crop.width,
height: cropAspectRatio >= 1 ? crop.height : undefined
});
let sizeModifier = 1;
if (base.height < crop.height) sizeModifier = crop.height / base.height;
if (base.width < crop.width) sizeModifier = crop.width / base.width;
base.width = base.width * sizeModifier;
base.height = base.height * sizeModifier;
const maxWidth = Math.abs(base.height * Math.sin(angle)) + Math.abs(base.width * Math.cos(angle));
const maxHeight = Math.abs(base.height * Math.cos(angle)) + Math.abs(base.width * Math.sin(angle));
return getRatioSize(aspectRatio, {
width: aspectRatio >= 1 ? undefined : maxWidth,
height: aspectRatio >= 1 ? maxHeight : undefined
});
};
//# sourceMappingURL=getCropRotatedSize.js.map