LeCodesdocs

QRScanner

The host's camera QR scanner as a Presentable: open it fullscreen, Router.push it, or embed it among a screen's children as a live preview node. Host-optional — always guard with QRScanner.isSupported before offering the feature.

At a glance

TypeScript
if (QRScanner.isSupported) {
  const scanner = QRScanner().onScan(data => {
    if (data === null) return          // a camera frame with no readable code
    console.log('scanned:', data)
    scanner.close()
  })
  await scanner.open()                 // asks for camera permission, then presents the scanner
}

API

TypeScript
QRScanner.isSupported: boolean                        // static — can this host scan at all?

QRScanner(): QRScanner                                // create a scanner view
scanner.onScan(cb: (data: string | null) => void): this   // fires per decoded frame
scanner.open(opts?: { transition }): Promise<void>   // request camera access, present the scanner
scanner.close(): void                                 // dismiss, release the camera
  • onScan fires for every frame the scanner decodes; null means a frame with no readable code, so expect it repeatedly while the user is aiming. The same code can be reported more than once — debounce/close() yourself when you've got what you need.
  • open() follows the prepare-then-present contract (same as ARScene): the current destination stays visible while camera permission is requested; the swap — and the transition, if you pass one — happens once the scanner is ready. It rejects if the camera is denied, the host can't scan, or another navigation happened while it was preparing.
  • A scanner is a full NativeView over the host-registered "qrScanner" view: Router.push(scanner) works (the back gesture pops it), and it embeds as a layout node — place it among a screen's children, sized by its styles. isSupported is exactly "did this host register the view".
Note

unlike physics (which silently no-ops when absent), open() throws an Error on hosts without a scanner. isSupported is the guard — check it before showing a "Scan" button at all. See host gating.

Note

lifecycle — the scanner holds the camera until close() (or until the router pops it). If you open it from a screen flow, close it after a successful scan or the camera stays captured.

See also