I have been trying to create an OCR app using React Native and Expo. However, I have encountered an issue where I cannot use the OCR package when using the Expo development client. I am utilizing react-native-vision-camera along with vision-camera-ocr to detect text.
import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, ActivityIndicator, SafeAreaView } from 'react-native';
import { useCameraDevices, useFrameProcessor, Camera } from 'react-native-vision-camera';
import 'react-native-reanimated';
import { scanOCR } from 'vision-camera-ocr';
import { runOnJS } from 'react-native-reanimated';
const TextScanner = () => {
const [text, setText] = useState(null)
const devices = useCameraDevices();
const cameraDevice = devices.back;
const frameProcessor = useFrameProcessor((frame) => {
'worklet'
const scannedOcr = scanOCR(frame);
runOnJS(setText)(scannedOcr.result.text)
}, []);
if (cameraDevice == null) {
return <ActivityIndicator size="large" color="green" />;
} else {
return (
<View>
<Camera
style={styles.camera}
device={cameraDevice}
isActive={true}
frameProcessor={frameProcessor}
/>
<View styles={styles.textContainer}>
<Text style={styles.text}>{text}</Text>
</View>
</View>
);
}
};
export default TextScanner;
const styles = StyleSheet.create({
textContainer: {
position: 'absolute',
bottom: 100,
height: 100,
width: 400,
backgroundColor: 'white',
zIndex: 1
},
text: {
fontSize: 50
},
camera: {
height: '80%',
width: '100%',
zIndex: 0
}
})
Everything works fine when I build a standalone APK using EAS, but I face an error when attempting to run the app using the development client. I suspect this issue is related to the configuration of babel.config.js. I researched the problem, and it seems that some people forgot to include the following configuration in their babel.config.js:
module.exports = {
plugins: [
[
'react-native-reanimated/plugin',
{
globals: ['__scanOCR'],
},
],
]
}
However, I have already included this configuration correctly in my babel.config.js. My question is whether there is a solution to make __scanOCR work in the Expo development client. Alternatively, is there another OCR plugin available for React Native using Expo that doesn’t require an internet connection? I’m aiming to implement a popup that displays the recognized text with specific functionality, and having the ability to update the code quickly without using EAS would be very beneficial.
I am using a managed workflow, my eas-cli verion is 3.17.1. I have tried a bunch of things including reformating the babel.config.js to use commonJs, clearing my cache (multiple times) and using a standalone build to no avail. Any and all help would be appreciated, have been trying to fix this for days now and none of the solutions I found online worked.