pushinbr / pam-native-scanner
Real-time QR and barcode scanning with native camera previews for PAM Native.
Package info
github.com/push-in/pam-native-scanner
Language:Kotlin
Type:pam-native-plugin
pkg:composer/pushinbr/pam-native-scanner
Requires
- php: ^8.5
- pushinbr/pam-native: ^1.53
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-18 04:03:25 UTC
README
Real-time QR and barcode scanning with native camera previews.
CameraX and ML Kit on Android, AVFoundation and Vision on iOS, plus offline QR decoding and generation for images.
Install · Quick example · Platforms · Permissions · Docs · Issues
Install
Inside a PAM Native project, add only this capability:
pam composer require pushinbr/pam-native-scanner pam doctor --fix
New to PAM? Create a project with pam init my-app --template native (see the PAM Native overview), then come back here. Composer owns the manifest and the lockfile; pam composer runs it on PAM's verified PHP runtime.
Quick example
<?php declare(strict_types=1); use Pam\Native\Scanner\BarcodeFormat; use Pam\Native\Scanner\ScannerView; use Pam\Native\Scanner\ScanResult; return ScannerView::make(BarcodeFormat::QrCode, BarcodeFormat::Ean13) ->duplicateInterval(1200) ->onResult(function (ScanResult $result): void { // Validate the value before navigation, network calls or payments. });
Declarative .pam components can use the same native view directly:
<QrScanner facing="1" duplicateInterval="1200" :enabled="$active" @detected="scanned" @failure="scannerFailed" />
The analyzer keeps only the latest frame, runs outside the UI thread, closes every image proxy and suppresses duplicate values for a configurable interval. Camera permission denial and native failures are typed events. Android uses the bundled ML Kit model, so first use does not depend on a model download.
Platform support
| Platform | Support | Notes |
|---|---|---|
| Android | API 24+ | CameraX 1.6.1, ML Kit barcode scanning 17.3.0 (bundled), ZXing Core 3.5.4 |
| iOS | 15.0+ | AVFoundation, Vision, ImageIO, Core Image |
| PAM Native | 0.8.0 to < 2.0.0 | From pam-native.plugin.json; PHP 8.5+ |
Permissions and requirements
| Platform | Declared by the plugin |
|---|---|
| Android | android.permission.CAMERA |
| iOS | NSCameraUsageDescription ("Scan QR codes and barcodes.") |
Camera usage metadata and Android permission merging are supplied by the plugin. Request camera permission before mounting an enabled scanner. Decoding and generating QR images (QrImages) does not need the camera permission.
QR codes in images
QrImages::decode($uri, $complete, $failure) decodes a local image (pam-file:///... from Files::pick(), granted content:// or local file://) without opening the camera; remote URLs are rejected and up to 16 distinct QR values are returned. QrImages::generate($text, $pixels, complete:, failure:) renders a QR PNG offline, and QrImages::release($uri) frees it.
QrImages::generate('https://example.test/profile', 440, complete: function (string $uri): void { // Display with Image::source($uri). Release when the image leaves the screen. QrImages::release($uri); }, failure: function (string $message): void { /* Show a text/link fallback. */ }, );
Limits, cache rules and validation status: docs/qr-images.md.
API guide
| API | Responsibility |
|---|---|
ScannerView |
Render the native preview and configure scanning. |
BarcodeFormat |
Select only the barcode symbologies the product needs. |
ScanResult |
Receive value, format, and normalized scan data. |
ScannerEventKind |
Handle typed results, permission failures, and native errors. |
CameraFacing |
Select front or back camera. |
QrImages |
Decode QR codes in selected images and generate QR images. |
All coded states, kinds, and variants are sequential integer-backed enums. Use enum cases in application code; do not depend on raw wire numbers.
Production rules
- Request camera permission before mounting an enabled scanner.
- Restrict formats to improve speed and reduce false positives.
- Validate scanned values before navigation, network calls, or payment actions.
- Run
pam doctor,pam test, and a signed release build on every supported platform. - Exercise denial, cancellation, backgrounding, process restart, and offline behavior before release.
Security vulnerabilities should be reported through the repository security policy or GitHub private vulnerability reporting, not a public issue.
Troubleshooting
- Preview is black: verify permission, lifecycle visibility, and camera availability.
- The same code fires repeatedly: increase
duplicateInterval(). - A format is never recognized: include it explicitly in
make(). - Native integration is stale: run
pam doctor --fix, rebuild the native host, and inspect the first reported diagnostic.
Platform SDKs, credentials, entitlements, physical hardware, and store configuration remain application responsibilities.
Docs
- PAM Native overview
- Plugin and native capability model
- PAM introduction
- Changelog
- Report an issue
- QR codes in selected images and QR generation
- Android development checks
Part of the PAM ecosystem
PAM runs PHP natively on servers, desktops and phones. This repository is one piece of it.
| PAM | PAM Desktop | PAM Native | Ecosystem |
|---|---|---|---|
| the runtime and CLI | native desktop apps in PHP | native Android and iOS apps in PHP | every official package and plugin |
Docs: push-in.github.io/pam-docs · Issues
Apache License 2.0 · Made in Brazil by Pushin