react-native-scanner icon indicating copy to clipboard operation
react-native-scanner copied to clipboard

Not Getting All QRCodes on screen

Open ravindraguptacapgemini opened this issue 5 months ago • 5 comments

Before submitting a new issue

  • [x] I tested using the latest version of the library, as the bug might be already fixed.
  • [x] I tested using a supported version of react native.
  • [x] I checked for possible duplicate issues, with possible answers.

Bug summary

With latest release, we only get one QRCode, even if there are multiple QRCode in front of camera. Ideally we should either trigger multiple events for each qrcode or send all of them in one callback. Root cause:

guard let results = request.results as? [VNBarcodeObservation],
                       let firstBarcode = results.first,
                       let payloadString = firstBarcode.payloadStringValue
                   else {
                       return
                   }

we only use first from result and discard others, @pushpender-singh-ap can you please update the code accordingly. Thanks

Library version

2.0.1

Environment info

System:
  OS: macOS 15.7.2
  CPU: (12) arm64 Apple M2 Pro
  Memory: 2.63 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.19.4
    path: /usr/local/bin/node
  Yarn:
    version: 3.6.4
    path: ~/node_modules/.bin/yarn
  npm:
    version: 10.8.2
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.11.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/ravindragupta/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK:
    API Levels:
      - "24"
      - "28"
      - "31"
      - "33"
      - "34"
      - "35"
      - "36"
    Build Tools:
      - 27.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 36.0.0
    System Images:
      - android-23 | Google APIs Intel x86 Atom
      - android-24 | Google APIs Intel x86 Atom
      - android-26 | ARM 64 v8a
      - android-26 | Google APIs ARM 64 v8a
      - android-26 | Google APIs Intel x86 Atom
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-30 | Google APIs ARM 64 v8a
      - android-30 | Google Play ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-35 | Google Play Tablet ARM 64 v8a
      - android-36 | Google APIs ARM 64 v8a
      - android-36 | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
      - android-36 | Pre-Release 16 KB Page Size Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2513.14007798
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.1
    path: /usr/bin/javac
  Ruby:
    version: 3.1.4
    path: /Users/ravindragupta/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.4
    wanted: 0.81.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Steps to reproduce

  1. Place multiple QRCode on screen
  2. See if you can receive all of the QRCodes in response in callback for startScanning

Reproducible example repository

https://github.com/pushpender-singh-ap/react-native-scanner/issues

ravindraguptacapgemini avatar Nov 18 '25 17:11 ravindraguptacapgemini

@ravindraguptacapgemini can you please give me the sample repo.

pushpender-singh-ap avatar Nov 18 '25 18:11 pushpender-singh-ap

@pushpender-singh-ap You can check with the example project with placing multiple QRCodes in front of camera. Also the code I have already highlighted will never pass all the QR code found during a scan session. I would recommend instead of using first object only, use all the result objects

ravindraguptacapgemini avatar Nov 19 '25 04:11 ravindraguptacapgemini

@ravindraguptacapgemini, could you create a PR for this? Did this happen on both iOS and Android?

pushpender-singh-ap avatar Nov 19 '25 05:11 pushpender-singh-ap

yes, this is happening for iOS and android both. If you remember in order version 1.x, I provided PR to trigger the Barcode event multiple times for each barcode on single scan result

https://github.com/pushpender-singh-ap/react-native-scanner/pull/8/files

we iterated through the array and trigger the event, which is missing here.

ravindraguptacapgemini avatar Nov 19 '25 08:11 ravindraguptacapgemini

for iOS, may be use this code -

` guard let results = request.results as? [VNBarcodeObservation] else { return }

for result in results { guard let firstBarcode = results.first, let payloadString = firstBarcode.payloadStringValue else { continue; }

// Create result dictionary
let result = self.createBarcodeResult(
    barcode: firstBarcode, payloadString: payloadString)

// Invoke callback through the actor for thread safety
await self.callbackActor.invokeCallback(with: result)
print("📤 Callback invoked with barcode data")

} `

ravindraguptacapgemini avatar Nov 19 '25 09:11 ravindraguptacapgemini