New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@amrshbib/react-native-barcode-laser

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amrshbib/react-native-barcode-laser

React Native bridge for Android handheld laser/infrared barcode scanners (Sunmi L2s Pro, L3, Zebra, Honeywell, Chainway, Urovo, Generic). Broadcast Intent + Keyboard Wedge support, no camera.

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

React Native Barcode Laser

npm downloads npm downloads License: MIT React Native

A high-performance React Native bridge for Android handheld laser/infrared barcode scanners. This package integrates directly with physical scan engines (not cameras) for enterprise PDA devices like Sunmi, Zebra, Honeywell, Chainway, and Urovo.

✨ Features

  • 🚀 Hardware Native: Zero-latency capture via native Android Broadcast Intents.
  • 📡 OEM Support: Pre-configured for Sunmi, Zebra (DataWedge), Honeywell, Newland, Chainway, and more.
  • 🏗️ Dual Mode: Supports both Broadcast Intent (API) and Keyboard Wedge modes.
  • 🎣 Power Hook: useBarcodeLaser hook with state management and promise-based one-shot scanning.
  • 🔔 Feedback Control: Native support for hardware beeps and vibrations.
  • 🛠️ Developer Friendly: Inject fake scans for testing, debounce, length filtering, and device info.
  • 📝 TypeScript First: Complete type definitions for a better development experience.

📦 Installation

npm install @amrshbib/react-native-barcode-laser
# or
yarn add @amrshbib/react-native-barcode-laser

Android Configuration

Android autolinking handles the setup. After installation, rebuild your project:

cd android && ./gradlew clean && cd ..
npx react-native run-android

Note: This package is Android-only as it targets handheld hardware scanners. iOS calls will return safe defaults (e.g., isAvailable() -> false).

🚀 Quick Start

import { useBarcodeLaser } from "@amrshbib/react-native-barcode-laser";

const ScannerScreen = () => {
  const { lastScan, started, available, scan } = useBarcodeLaser({
    autoStart: true,
    onScan: (event) => {
      console.log("Scanned:", event.data);
    }
  });

  // Example of capturing a single scan programmatically
  const scanOne = async () => {
    const result = await scan();
    alert(`Captured: ${result.data}`);
  };

  if (available === false) return <Text>Hardware scanner not found</Text>;

  return (
    <View>
      <Text>Status: {started ? "Active" : "Stopped"}</Text>
      <Text>Last Barcode: {lastScan?.data}</Text>
      <Button title="One-shot Scan" onPress={scanOne} />
    </View>
  );
};

2. Imperative API

import BarcodeLaser from "@amrshbib/react-native-barcode-laser";

// Start the listener
const initScanner = async () => {
  await BarcodeLaser.configure({ 
    mode: 'broadcast',
    beepOnSuccess: true 
  });
  await BarcodeLaser.start();
  
  const sub = BarcodeLaser.addListener((event) => {
    console.log(`Scanned: ${event.data} via ${event.source}`);
  });
};

📖 API Reference

BarcodeLaser.configure(options)

Sets global configuration for the scanner hardware.

PropertyTypeDefaultDescription
modestring'broadcast''broadcast', 'wedge', or 'auto'
beepOnSuccessbooleantruePlay system beep on successful scan
vibrateOnSuccessbooleanfalseVibrate on successful scan
vibrateDurationMsnumber60Duration of the success vibration
debounceMsnumber50Prevents rapid-fire duplicate scans
minLengthnumber1Ignore barcodes shorter than this
maxLengthnumber0Ignore barcodes longer than this (0 = no limit)
stripWhitespacebooleantrueTrims results automatically
actionsstring[](Defaults)Custom intent actions to listen for
extrasstring[](Defaults)Custom intent extra keys for data

BarcodeLaser.start() / stop()

Enables or disables the hardware listener. Returns Promise<boolean>.

BarcodeLaser.trigger() / stopTrigger()

Programmatically toggles the physical laser beam (on supported hardware).

BarcodeLaser.beep() / vibrate(ms)

Manually trigger the handheld's feedback systems.

BarcodeLaser.injectScan(data, type)

Inject a mock scan event into the listener. Great for development on emulators.

BarcodeLaser.getDeviceInfo()

Returns Promise<{ manufacturer: string, model: string, isSunmi: boolean, ... }> with detailed OEM info.

🎣 useBarcodeLaser Hook

Exposes the full power of the scanner as a React state.

Return KeyTypeDescription
availableboolean | nullnull while detecting, then true if hardware found
startedbooleanCurrent status of the listener
lastScanScanEventThe most recently captured barcode object
errorScanErrorLast error event
scan()() => PromiseTriggers laser and resolves with the next scan
trigger()FunctionFire the laser manually
beep()FunctionPlay system beep

🔧 Platform Setup & OEM Config

Sunmi Devices (L2s Pro, L3, etc.)

  • Open Scanner Settings on the device.
  • Output Mode: Output via API (or Broadcast).
  • Intent Action: com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED.
  • Intent Extra: data.

Zebra (DataWedge)

  • Open DataWedge app.
  • Select your profile (e.g., Profile0).
  • Intent Output: Enabled.
  • Intent Action: com.symbol.datawedge.api.RESULT_ACTION.
  • Intent Delivery: Broadcast Intent.

🤝 Contributing & Support

If you have a specific handheld device that requires a new default intent action, please submit a PR or open an issue!

📄 License

The MIT License - Copyright (c) 2024 Amr Shbib

Keywords

react-native

FAQs

Package last updated on 27 Apr 2026

Related posts