Please provide the following:
- SDK Version: 43.0.0
- Platforms: Android/iOS
- Add the appropriate “Tag” based on what Expo library you have a question on: BarCodeScanner - Expo Documentation
Hi,
I have an issue with the BarCodeScanner on Android. On first use of the Bar Code Scanner, the scanner works as expected and reads qr codes. Once I navigate way from the BarCodeScanner, then try to navigate back, the camera still works. However, the qr codes are no longer detected (callback onBarCodeScanned is not being invoked). The issue only appears on Android devices iOS works as expect.
I followed the documentations advice to ensure that the BarCodeScanner component is unmount when I navigate away from the BarCodeScanner screen.
My use Effect method, and snippet of the return method. I added the mounted.current in vain to try and solve the issue
/* Demounting camera to save batter power
* and to allow us to use the camera in other components,
* two instances can't be mounted at once
*/
useEffect(() => {
mounted.current = true;
return () => {
setHasPermission(false)
mounted.current = false;
};
}, [isFocused]);
.....
return (
<SafeAreaView>
{hasPermission && (
<BarCodeScanner
accessibilityLabel={t('register.cameraAccessibility')}
accessibilityHint={t('register.cameraAccessibilityHint')}
type={BarCodeScanner.Constants.Type.back}
barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}
onBarCodeScanned={handleBarCodeScanned}
style={{
height: '100%',
width: '100%'
}}
/>
)}
</SafeAreaView>