Skip to content
Open
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
32 changes: 24 additions & 8 deletions src/PhotoRecognizer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { NativeModules, Platform } from 'react-native';
import { NativeModules, Platform, ToastAndroid } from 'react-native';
import type { PhotoOptions, Text } from './types';

export async function PhotoRecognizer(options: PhotoOptions): Promise<Text> {
const { PhotoRecognizerModule } = NativeModules;
const { uri, orientation } = options;

if (!uri) {
throw Error("Can't resolve img uri");
}
if (Platform.OS === 'ios') {
return await PhotoRecognizerModule.process(
uri.replace('file://', ''),
orientation || 'portrait'
);
} else {
return await PhotoRecognizerModule.process(uri);

try {
let result;
if (Platform.OS === 'ios') {
result = await PhotoRecognizerModule.process(
uri.replace('file://', ''),
orientation || 'portrait'
);
} else {
result = await PhotoRecognizerModule.process(uri);
}


if (Object.keys(result).length === 0) {
ToastAndroid.show("No text recognized", ToastAndroid.SHORT);
console.log('No text detected');
} else {
return result;
}
}
catch (error) {
console.error('Error during photo recognition: ', error);
}
}