Skip to content

Commit

Permalink
Merge pull request #80 from Glazzes/dev
Browse files Browse the repository at this point in the history
Fix blurry image on load
  • Loading branch information
Glazzes authored Jan 3, 2025
2 parents f0c0b52 + 05c9056 commit 386be43
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/components/crop/CropZoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ const CropZoom: React.FC<CropZoomPropsWithRef> = (props) => {
onTap,
} = props;

const initialSize = getCropRotatedSize({
crop: cropSize,
resolution: resolution,
angle: 0,
});

const translate = useVector(0, 0);
const offset = useVector(0, 0);
const scale = useSharedValue<number>(minScale);
const scaleOffset = useSharedValue<number>(minScale);
const rotation = useSharedValue<number>(0);
const rotate = useVector(0, 0);

const container = useSizeVector(1, 1);
const detector = useSizeVector(1, 1);
const container = useSizeVector(initialSize.width, initialSize.height);
const detector = useSizeVector(initialSize.width, initialSize.height);
const sizeAngle = useSharedValue<number>(0);

const maxScale = useDerivedValue(() => {
Expand All @@ -82,19 +88,17 @@ const CropZoom: React.FC<CropZoomPropsWithRef> = (props) => {
useDerivedValue(() => {
const size = getCropRotatedSize({
crop: cropSize,
resolution: resolution,
resolution,
angle: sizeAngle.value,
});

const isFlipped = rotation.value % Math.PI !== 0;
const render1 = container.width.value === 1 && container.height.value === 1;

container.width.value = render1 ? size.width : withTiming(size.width);
container.height.value = render1 ? size.height : withTiming(size.height);
container.width.value = withTiming(size.width);
container.height.value = withTiming(size.height);

const isFlipped = rotation.value % Math.PI !== 0;
detector.width.value = isFlipped ? size.height : size.width;
detector.height.value = isFlipped ? size.width : size.height;
}, [cropSize, resolution, sizeAngle, rotation, container, detector]);
}, [cropSize, resolution, sizeAngle, rotation]);

useDerivedValue(() => {
onUpdate?.({
Expand Down Expand Up @@ -367,7 +371,9 @@ const CropZoom: React.FC<CropZoomPropsWithRef> = (props) => {
return (
<View style={[rootStyle, styles.root, styles.center]}>
<Animated.View style={childStyle}>{children}</Animated.View>
<View style={styles.absolute}>{OverlayComponent?.()}</View>
<View style={styles.absolute} pointerEvents={'none'}>
{OverlayComponent?.()}
</View>

<GestureDetector gesture={Gesture.Race(pinch, pan, tap)}>
<Animated.View style={detectorStyle} />
Expand Down

0 comments on commit 386be43

Please sign in to comment.