There is a separate page in the app where I have posted expo-barcode-scanner. The bottom line is that when you open this particular page, on which the camera is located, the application immediately crashes. No errors are printed to the console. The code of the scanner itself was taken from off. documentation.
Wherein:
const AdminScreen = ({navigation}) => {
const [hasPermission, setHasPermission] = useState(null);
const [scanned, setScanned] = useState(true);
const [cameraReady, setCameraReady] = useState(false);
useEffect(() => {
(async () => {
const { status } = await BarCodeScanner.requestPermissionsAsync();
setHasPermission(status === 'granted');
})();
}, []);
const onCameraReady = () => {
setCameraReady(true)
console.warn("Camera ready")
}
const handleBarCodeScanned = ({ type, data }) => {
if (cameraReady){
setScanned(true);
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
}
};
if (hasPermission === null) {
return <Text>Requesting for camera permission</Text>;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
return (
<View
style={{
flex: 1,
resizeMode: 'cover',
}}>
<Camera
onCameraReady={onCameraReady}
barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
style={{
flex:1
}}
/>
{scanned && <Button title={'Tap to Scan Again'} onPress={() => setScanned(false)} />}
</View>
);
}
P.S: I do not exclude that the error is as obvious and stupid as possible, I started learning react and js just a week ago, I can easily miss something