expo: [SDK44][bare-code-scanner][Android] QR Code not working after using "back" button

Summary

When using “bare-code-scanner”, after scanning a QR Code then navigate to a result page if I hit “back” button no more QR is scanned. On iOS QR code is well scanned in this case.

Behavior:

Case 1 (Bug):

  1. Scanning a QR & display my result screen
  2. Click back button
  3. Trying scanning another QR = Not detected

Case 2:

  1. Scanning a QR & display my result screen
  2. Click back button (so back to my “camera screen”) then back again to my main screen
  3. Click on “Scan QR” button
  4. Scanning a QR = Detected then display my result screen

This issue is opened following this thread: https://github.com/expo/expo/pull/15393

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

44

Environment

Expo CLI 5.0.3 environment info: System: OS: Windows 10 10.0.19044 Binaries: Node: 14.17.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6626763 npmPackages: expo: ~44.0.0 => 44.0.1 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 react-navigation: ^4.4.4 => 4.4.4 Expo Workflow: managed

Reproducible demo

You can find a reproducible demo here:

https://snack.expo.dev/@fabzien/bare-code-scanner-report-issue

To reproduce (Android only):

  1. Click “Go to QRCodeScanner”
  2. Scan any QR Code
  3. Click “Back” on next screen
  4. Click “Tap to Scan Again”
  5. Try to scan another QR code = Failed

SDK 44 isn’t supported on Snack so it’s using SDK 33 but you can import it then upgrade to SDK 44.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 20 (2 by maintainers)

Most upvoted comments

A workaround would be to give the Camera component a key prop. onBarCodeScanned triggers a key value modification which rerenders the Camera. The Camera is reset and able to scan again.

Hope it helps

I am on expo 44.0.3 and expo-barcode-scanner 1.2.0 and I confirm that after pressing back button the scanner does not work anymore.

I am on expo 44.0.4 and"expo-barcode-scanner": “~11.2.0” and I have the same problem when I change of screen the scanner does not work I think its something in onBarCodeScanned prop

@Fabzien thank you

I just want to clarify for everyone that this workaround doesn’t actually fix the behavior where an instance will only scan one barcode.

If you restart the component by going back / reloading etc, then yes it will scan a 2nd one. But the BarCodeScanner works perfectly - just not the camera.

I am on expo 44.0.4 and"expo-barcode-scanner": “~11.2.0” and I have the same problem when I change of screen the scanner does not work I think its something in onBarCodeScanned prop

This Solved “between screens” problem. import { useIsFocused } from '@react-navigation/native'; const isFocused = useIsFocused(); return( {isFocused && <Camera /> } )

I’m having the same issue, I’m on expo: 44.0.0 expo-camera: 12.1.2 expo-barcode-scanner: 11.2.0

I’m having the same issue, I’m on expo: 44.0.6 expo-camera: 12.1.2 expo-barcode-scanner: 11.2.1