I am using Expo's BarCodeScanner component within a tab:
return (
<View
style={{
flex: 1,
flexDirection: "column",
justifyContent: "flex-end",
}}
>
<BarCodeScanner
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
barCodeTypes={[BarCodeScanner.Constants.BarCodeType.ean13]}
style={StyleSheet.absoluteFillObject}
/>
{scanned && (
<Button title={"Tap to Scan Again"} onPress={() => setScanned(false)} />
)}
</View>
);
After scanning, I navigate to another page like this:
const handleBarCodeScanned = ({ type, data }) => {
setScanned(true);
props.navigation.navigate("EanProduct", {
ean: data,
});
};
The function works smoothly. However, when I temporarily leave the app through the Home button and return, the camera freezes. The app remains functional, but the camera stops working.
Is there a solution to restart the camera? Or what could be causing this issue? I attempted to trigger a screen reload upon navigation changes by using didFocus for the TabBar
useEffect(() => {
const navFocusListener = props.navigation.addListener("didFocus", () => {
//console.log("reload");
});
return () => {
navFocusListener.remove();
};
}, [props.navigation]);
Unfortunately, this approach does not resolve the problem.