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

Fix blurry image on load #80

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"favicon": "./assets/favicon.png",
"bundler": "metro"
},
"plugins": ["expo-router", "expo-video"]
"plugins": ["expo-router"]
}
}
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
Loading