BarCodeScanner won't open if Permissions are required

I am struggling to use the Expo BarCodeScanner component with a format differing from the one given in the Expo docs.

I have created an example repo of my project that can be found on github, here. My goal is to have the Location fetcher and Barcode Scanner use the same permissions method to lower the amount of code repetition. Tracker.js already does this via LocationPermission.js.

The problem is that I can’t get the bar code scanner permissions to work using the same logic. Whenever I load up the App (without approved camera permissions) and select my attempt, Scanner1 (Scanner-broken-perm.js) no code runs i.e. permissions access isn’t requested and the Scanner doesn’t startup. The only workaround is to select the functioning Scanner (Scanner.js) which uses the Expo example code, to grant permissions and start the camera, then switch to Scanner1 which then functions properly. Scanner1 also works when I reload the app with permissions still granted by default

Can anyone tell me why my Scanner-broken-perm.js function isn’t initialising when permissions have not already been granted?

I tried using the useEffect Hook in Scanner2 (Scanner-broken-hook.js), similarly to the Expo BarCodeScanner docs to try and get the component to update upon opening but I don’t think I have done it correctly as it causes the scan success alert to fire straight away then crashes when I actually scan something.

Any help would be hugely appreciated. Also sorry if I have been unclear or haven’t given enough info.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.