react-native-zoom-toolkit
Version:
Most complete set of pinch to zoom utilites for React Native
50 lines (48 loc) • 1.32 kB
JavaScript
import { getVisibleRect } from './getVisibleRect';
export const crop = options => {
'worklet';
const {
cropSize,
itemSize,
resolution,
translation,
scale,
isRotated,
fixedWidth
} = options;
const rect = getVisibleRect({
scale,
containerSize: cropSize,
itemSize: {
width: isRotated ? itemSize.height : itemSize.width,
height: isRotated ? itemSize.width : itemSize.height
},
translation
});
const relativeScale = resolution.width / itemSize.width;
const x = rect.x * relativeScale;
const y = rect.y * relativeScale;
const width = rect.width * relativeScale;
const height = rect.height * relativeScale;
// Make a normal crop, if the fixedWidth is defined just resize everything to meet the ratio
// between fixedWidth and the width of the crop.
let sizeModifier = 1;
let resize;
if (fixedWidth !== undefined) {
sizeModifier = fixedWidth / width;
resize = {
width: Math.ceil(resolution.width * sizeModifier),
height: Math.ceil(resolution.height * sizeModifier)
};
}
return {
crop: {
originX: x * sizeModifier,
originY: y * sizeModifier,
width: Math.floor(width * sizeModifier),
height: Math.floor(height * sizeModifier)
},
resize
};
};
//# sourceMappingURL=crop.js.map