Skip to content

Commit

Permalink
Merge pull request #22 from Glazzes/dev
Browse files Browse the repository at this point in the history
Fix CropZoom for square aspect ratio
  • Loading branch information
Glazzes authored May 29, 2024
2 parents 2d34962 + ab9f510 commit 8ad884e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions example/src/cropzoom/common-example/CropManagedExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ const CropManagedExample = ({}) => {
resolution={resolution}
OverlayComponent={renderOverlay}
>
<Image source={{ uri: IMAGE }} style={styles.image} />
<Image
source={{ uri: IMAGE }}
style={styles.image}
resizeMethod="scale"
/>
</CropZoom>

{/*
Expand Down Expand Up @@ -70,7 +74,8 @@ const styles = StyleSheet.create({
backgroundColor: '#121212',
},
image: {
flex: 1,
width: '100%',
height: '100%',
},
});

Expand Down
1 change: 1 addition & 0 deletions example/src/resumable/ResumableZoomExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const ResumableZoomExample: React.FC = ({}) => {
ref={ref}
hitSlop={{ vertical: 50 }}
maxScale={resolution}
extendGestures={true}
onTap={onTap}
>
<Image
Expand Down
6 changes: 3 additions & 3 deletions src/commons/utils/getCropRotatedSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type { SizeVector } from '../types';
type Options = {
size: SizeVector<number>;
angle: number;
aspectRatio?: number;
aspectRatio: number;
};

export const getCropRotatedSize = (options: Options): SizeVector<number> => {
'worklet';
const { size, angle, aspectRatio = 1 } = options;
const { size, angle, aspectRatio } = options;

const sinWidth = Math.abs(size.height * Math.sin(angle));
const cosWidth = Math.abs(size.width * Math.cos(angle));
Expand All @@ -23,6 +23,6 @@ export const getCropRotatedSize = (options: Options): SizeVector<number> => {
return getAspectRatioSize({
aspectRatio: aspectRatio,
width: aspectRatio >= 1 ? undefined : maxWidth,
height: aspectRatio > 1 ? maxHeight : undefined,
height: aspectRatio >= 1 ? maxHeight : undefined,
});
};

0 comments on commit 8ad884e

Please sign in to comment.