Hardening fixes: Camera cancellation, Android memory optimization, action button throttling

This commit is contained in:
2026-05-31 20:28:02 +02:00
parent cb453bf200
commit faa584ae0f
2 changed files with 24 additions and 6 deletions
+12 -1
View File
@@ -92,6 +92,7 @@ export default function CameraScreen({
const usbCameraRef = useRef<UsbCameraRef>(null);
const expoCameraRef = useRef<any>(null);
const burstTimerRef = useRef<any>(null);
const isCancelledRef = useRef<boolean>(false);
// Reanimated countdown pulse animation
const scale = useSharedValue(1);
@@ -195,6 +196,7 @@ export default function CameraScreen({
// Cancel capture process
const handleLocalCancel = async () => {
isCancelledRef.current = true;
if (burstTimerRef.current) clearTimeout(burstTimerRef.current);
// Clean up any temp files from a partially completed burst
@@ -208,6 +210,8 @@ export default function CameraScreen({
setCountdown(countdownDuration);
setIsCapturing(false);
setIsBurstWaiting(false);
setHasStarted(false);
setBurstIndex(0);
setBurstUris([]);
setShowBurstIndicator('');
@@ -229,6 +233,7 @@ export default function CameraScreen({
}, [countdownDuration, isIdle]);
const startCountdown = () => {
isCancelledRef.current = false;
let timer: any;
let count = countdownDuration;
@@ -281,7 +286,7 @@ export default function CameraScreen({
if (expoCameraRef.current) {
const photo = await expoCameraRef.current.takePictureAsync({
quality: 0.7, // Lower quality slightly to reduce file size
skipProcessing: false, // Ensure correct orientation
skipProcessing: Platform.OS === 'android', // Prevent memory crash on Android
});
capturedUri = photo.uri;
} else {
@@ -289,6 +294,12 @@ export default function CameraScreen({
}
}
// If user cancelled while the camera promise was processing, abort before side-effects
if (isCancelledRef.current) {
console.log('Capture cancelled by user during processing.');
return;
}
// Instead of manipulating the image and risking an OOM or BitmapFactory crash,
// we directly use the captured photo and rely on React Native's Image component
// to safely downsample it during rendering via resizeMethod="resize".