MCPcopy Create free account
hub / github.com/dariyd/react-native-document-scanner / handleScan

Function handleScan

example/App.tsx:36–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34 const [status, setStatus] = useState<string>('');
35
36 const handleScan = async () => {
37 try {
38 setStatus('Launching scanner...');
39
40 // ML Kit Document Scanner handles permissions internally on Android
41 // iOS VisionKit also handles its own permissions
42 const result = await launchScanner({quality: 0.8});
43
44 if (result.didCancel) {
45 setStatus('Scan cancelled');
46 } else if (result.error) {
47 setStatus(`Error: ${result.errorMessage || 'Unknown error'}`);
48 Alert.alert('Error', result.errorMessage || 'Failed to scan');
49 } else if (result.images && result.images.length > 0) {
50 setImages(result.images);
51 setStatus(`Scanned ${result.images.length} page(s) successfully!`);
52 Alert.alert('Success', `Scanned ${result.images.length} page(s)`);
53 } else {
54 setStatus('No images scanned');
55 }
56 } catch (error: any) {
57 console.error('Scan error:', error);
58 setStatus(`Error: ${error.message}`);
59 Alert.alert('Error', error.message || 'Failed to scan document');
60 }
61 };
62
63 return (
64 <SafeAreaView style={styles.container}>

Callers

nothing calls this directly

Calls 2

launchScannerFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected