How mgcrea/vision-camera-barcode-scanner works
Project Type and Purpose
• This is an open-source React Native library (“vision-camera-barcode-scanner”) that provides a high-performance barcode scanner for mobile apps.
• It leverages the React Native Vision Camera’s frame-processor plugin system and native SDKs (Google ML Kit on Android, Apple Vision on iOS) to detect barcodes at up to 30 fps.
• The project ships:
• A TypeScript/JS core (in src/) exposing hooks and components (useBarcodeScanner, CameraHighlights).
• Native modules in android/src/... and ios/ implementing the frame processor.
• An example/ React Native app demonstrating usage.
Analyzing the File Structure
• Top-level directories:
• src/: JS/TS source code (components, hooks, constants, types, utils).
• android/: Native Android plugin module (Java classes mapping barcodes, exposing R-N module).
• ios/: Native iOS plugin (Objective-C code registering VisionCameraCodeScanner).
• example/: Full React Native app illustrating integration on both platforms.
• test/, configs (.eslintrc, tsconfig.json), CI workflows, and packaging (podspec, package.json).
• Pattern: a hybrid architecture where the JS layer dispatches camera frames to a native worklet plugin, which executes heavy computation via platform SDKs, returning results to the JS/UI layer.
Key Insights from the README
• Core dependencies:
• react-native-vision-camera (camera + frame-processor API)
• react-native-worklets-core (enables JS worklets on UI thread)
• Features: hooks-based API, customizable FPS, selective barcode formats.
• Native implementations: Google ML Kit (Android) and Apple’s Vision framework (iOS).
Details to Capture
• Explicitly note the hook’s config parameters (fps, barcodeTypes) flowing into the native plugin.
• Shared CameraHighlights component consuming output.
• Separate Android/iOS paths converging to the same JS callback (onBarcodeScanned).