Fix additional lifecycle bugs: countdown timer leak, PreviewScreen unmount state updates, CameraView ready loops
This commit is contained in:
@@ -72,6 +72,14 @@ export default function PreviewScreen({
|
||||
|
||||
// Sticker state
|
||||
const [stickers, setStickers] = useState<StickerData[]>([]);
|
||||
const [selectedImageIndex, setSelectedImageIndex] = useState<number | null>(null);
|
||||
|
||||
const mountedRef = useRef(true);
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
mountedRef.current = false;
|
||||
};
|
||||
}, []);
|
||||
const [selectedStickerId, setSelectedStickerId] = useState<string | null>(null);
|
||||
const [showStickerTray, setShowStickerTray] = useState<boolean>(false);
|
||||
|
||||
@@ -214,6 +222,7 @@ export default function PreviewScreen({
|
||||
try {
|
||||
setStatusMessage('Bild wird generiert...');
|
||||
const printUri = await captureComposite(currentPhoto);
|
||||
if (!mountedRef.current) return;
|
||||
|
||||
setStatusMessage('Druckauftrag wird an Drucker gesendet...');
|
||||
await printImageLocal(printUri, {
|
||||
@@ -223,13 +232,16 @@ export default function PreviewScreen({
|
||||
|
||||
setStatusMessage('Wird in Galerie gespeichert...');
|
||||
await saveToGallery(printUri);
|
||||
if (!mountedRef.current) return;
|
||||
|
||||
setStatusMessage('Druck erfolgreich! Viel Spaß! 🎉');
|
||||
setTimeout(() => {
|
||||
if (!mountedRef.current) return;
|
||||
setIsProcessing(false);
|
||||
onReset();
|
||||
}, 2000);
|
||||
} catch (error: any) {
|
||||
if (!mountedRef.current) return;
|
||||
console.error('Printing failed:', error);
|
||||
alert('Fehler: ' + error.message);
|
||||
setIsProcessing(false);
|
||||
@@ -243,16 +255,20 @@ export default function PreviewScreen({
|
||||
setStatusMessage('Bild wird generiert...');
|
||||
try {
|
||||
const saveUri = await captureComposite(currentPhoto);
|
||||
if (!mountedRef.current) return;
|
||||
|
||||
setStatusMessage('Wird in Galerie gespeichert...');
|
||||
await saveToGallery(saveUri);
|
||||
if (!mountedRef.current) return;
|
||||
|
||||
setStatusMessage('Erfolgreich gespeichert!');
|
||||
setTimeout(() => {
|
||||
if (!mountedRef.current) return;
|
||||
setIsProcessing(false);
|
||||
onReset();
|
||||
}, 1500);
|
||||
} catch (error: any) {
|
||||
if (!mountedRef.current) return;
|
||||
console.error('Saving failed:', error);
|
||||
alert('Fehler: ' + error.message);
|
||||
setIsProcessing(false);
|
||||
@@ -272,13 +288,17 @@ export default function PreviewScreen({
|
||||
setStatusMessage('Wird gespeichert...');
|
||||
try {
|
||||
const capturedUri = await captureComposite(state.currentPhoto);
|
||||
if (!mountedRef.current) return;
|
||||
await saveToGallery(capturedUri);
|
||||
if (!mountedRef.current) return;
|
||||
setStatusMessage('Erfolgreich gespeichert!');
|
||||
setTimeout(() => {
|
||||
if (!mountedRef.current) return;
|
||||
setIsProcessing(false);
|
||||
state.onReset();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
if (!mountedRef.current) return;
|
||||
console.error('Auto-saving on exit failed:', error);
|
||||
setIsProcessing(false);
|
||||
state.onReset();
|
||||
@@ -307,9 +327,12 @@ export default function PreviewScreen({
|
||||
setStatusMessage('Wird vor dem Wiederholen gespeichert...');
|
||||
try {
|
||||
const capturedUri = await captureComposite(currentPhoto);
|
||||
if (!mountedRef.current) return;
|
||||
await saveToGallery(capturedUri);
|
||||
} catch (error) {
|
||||
console.error('Auto-saving before retake failed:', error);
|
||||
if (!mountedRef.current) return;
|
||||
} catch (e) {
|
||||
if (!mountedRef.current) return;
|
||||
console.error('Failed to auto-save before retake:', e);
|
||||
}
|
||||
setIsProcessing(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user