Socket
Book a DemoInstallSign in
Socket

@masumdev/rn-qrcode-scanner

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@masumdev/rn-qrcode-scanner

A powerful and easy-to-use QR code scanning and generation library for React Native applications.

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
26
100%
Maintainers
1
Weekly downloads
 
Created
Source

@masumdev/rn-qrcode-scanner

A powerful and easy-to-use QR code scanning and generation library for React Native applications.

Note: Currently, this library only supports Android platform. iOS support is under development and will be available in future releases.

Sponsor

npm version npm downloads platform expo compatible

Demo

QR Scanner Android

Youtube Tutorial

React Native Toast Demo

Features

  • 📱 Advanced QR Code scanning with camera support
  • 🔍 Multiple format support (URL, text, contact info, etc.)
  • 💫 Real-time scanning with high performance
  • 🎯 Customizable scanning area and frame
  • 🛡️ Built-in camera permission handling
  • 📳 Haptic feedback on successful scans
  • 🎨 Customizable UI elements (corners, overlay, controls)
  • 🔦 Torch/flashlight control support
  • ⏱️ Cooldown timer between scans
  • ✅ Custom validation support
  • 🌓 Theme support (light/dark mode)
  • ⚡ Optimized for Android platform

Installation

Prerequisites

Make sure you have these peer dependencies installed in your React Native project:

{
  "react": ">=18.3.1",
  "react-native": ">=0.76.9",
  "react-native-svg": ">=15.8.0",
  "expo": ">=50.0.0",
  "expo-camera": ">=14.0.0",
  "expo-haptics": ">=12.8.0",
  "expo-router": ">=3.4.0",
  "@expo/vector-icons": ">=14.0.0"
}

Add in app.json

{
  // existing confoguration
  {
  "plugins": [
    "expo-router",
    [
      "expo-camera",
      {
        "cameraPermission": "Allow $(PRODUCT_NAME) to access your camera",
        "microphonePermission": "Allow $(PRODUCT_NAME) to access your microphone",
        "recordAudioAndroid": true
      }
    ]
  ]
}

}

Installing peer dependencies

npm install expo-camera expo-haptics expo-router @expo/vector-icons

or

yarn add expo-camera expo-haptics expo-router @expo/vector-icons

or

bun add expo-camera expo-haptics expo-router @expo/vector-icons

or

pnpm add expo-camera expo-haptics expo-router @expo/vector-icons

Installing @masumdev/rn-qrcode-scanner

npm install @masumdev/rn-qrcode-scanner

or

yarn add @masumdev/rn-qrcode-scanner

or

bun add @masumdev/rn-qrcode-scanner

or

pnpm add @masumdev/rn-qrcode-scanner

Usage

Basic Usage

import { QRCodeScanner } from '@masumdev/rn-qrcode-scanner';

const ScannerComponent = () => {
  const handleScan = (data: string) => {
    console.log('Scanned QR Code:', data);
  };

  return (
    <QRCodeScanner
        core={{
          onSuccessfulScan: handleSuccessfulScan,
        }}
    />
  );
};

export default ScannerComponent;

Advanced Usage

import {
  OnSuccessfulScanProps,
  QRCodeScanner,
  QRCodeValidator,
} from '@masumdev/rn-qrcode-scanner';
import { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';

const QRCodeScannerScreen = () => {
  const [scannedMember, setScannedMember] = useState<string | null>(null);

  const handleSuccessfulScan = (data: OnSuccessfulScanProps) => {
    if (data.code) {
      setScannedMember(data.code);
    }
    console.log(data);
  };

  const validateQRCode: QRCodeValidator = (code: string) => {
    // Example: Only accept URLs starting with https://
    // if (code.startsWith('https://')) {
    //   return { valid: true, code };
    // }

    // // Example: Accept product codes with specific format
    // if (/^PROD-\d{6}$/.test(code)) {
    //   return { valid: true, code };
    // }

    if (code) {
      return { valid: true, code, message: 'Success' };
    }

    return {
      valid: false,
      message:
        'Invalid QR code format. Expected HTTPS URL or product code (PROD-XXXXXX).',
    };
  };

  return (
    <View style={StyleSheet.absoluteFill}>
      <QRCodeScanner
        // Core functionality
        core={{
          onSuccessfulScan: handleSuccessfulScan,
          validate: validateQRCode,
        }}
        // Scanning behavior
        scanning={{
          cooldownDuration: 3000,
          scanningArea: {
            // tolerance: 80,∂
          },
        }}
        // UI Controls
        uiControls={{
          showControls: true,
          showStatus: true,
          showTorchButton: false, // We're using custom controls
        }}
        // Appearance
        appearance={{
          theme: 'light',
          overlayStyle: {
            backgroundColor: 'rgba(0, 0, 0, 0.8)',
            opacity: 0.9,
          },
          frameStyle: {
            width: 280,
            height: 280,
            borderRadius: 20,
          },
          cornerStyle: {
            color: '#00AAFF',
            width: 4,
            length: 30,
          },
          statusStyle: {
            backgroundColor: 'rgba(0, 0, 0, 0.7)',
            textColor: '#FFFFFF',
            borderRadius: 12,
            padding: 10,
            fontWeight: '600',
          },
        }}
      />

      {scannedMember && (
        <View style={styles.bottomContainer}>
          <View style={styles.infoContainer}>
            <Text style={styles.memberText}>{scannedMember}</Text>
          </View>
        </View>
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  bottomContainer: {
    position: 'absolute',
    bottom: 0,
    left: 0,
    right: 0,
  },
  infoContainer: {
    backgroundColor: 'white',
    borderTopLeftRadius: 24,
    borderTopRightRadius: 24,
    padding: 24,
  },
  memberText: {
    fontSize: 24,
    fontWeight: 'bold',
    marginBottom: 8,
  },
});

export default QRCodeScannerScreen;

API Reference

QRCodeScanner Props

QRCodeScanner component accepts several prop groups that control different aspects of its functionality:

Core Props

PropTypeRequiredDescription
onSuccessfulScan(state: OnSuccessfulScanProps) => voidYesCallback function called when QR code is successfully scanned
validateQRCodeValidatorNoCustom validation function for scanned QR codes

Scanning Props

PropTypeDefaultDescription
cooldownDurationnumber2000Time in milliseconds between scans
scanningAreaScanningAreaProps-Configure the scanning target area
ScanningAreaProps
PropTypeDefaultDescription
targetXnumber-X coordinate of scanning target
targetYnumber-Y coordinate of scanning target
tolerancenumber-Tolerance area around target coordinates

UI Controls Props

PropTypeDefaultDescription
showControlsbooleantrueShow/hide control buttons
showStatusbooleantrueShow/hide status information
showTorchButtonbooleantrueShow/hide torch control button

Appearance Props

PropTypeDefaultDescription
theme'light' | 'dark''light'UI theme selection
overlayStyleOverlayStyle-Customize scanner overlay
frameStyleFrameStyle-Customize scanner frame
cornerStyleCornerStyle-Customize corner markers
controlButtonStyleControlButtonStyle-Customize control buttons
statusStyleStatusStyle-Customize status display
OverlayStyle
PropTypeDescription
backgroundColorstringBackground color of overlay
opacitynumberOpacity level of overlay
FrameStyle
PropTypeDescription
widthnumberWidth of scanning frame
heightnumberHeight of scanning frame
borderRadiusnumberBorder radius of frame corners
CornerStyle
PropTypeDescription
colorstringColor of corner markers
widthnumberWidth of corner lines
lengthnumberLength of corner lines
StatusStyle
PropTypeDescription
backgroundColorstringBackground color of status box
textColorstringColor of status text
borderRadiusnumberBorder radius of status box
paddingnumberPadding inside status box
fontWeightstringFont weight of status text

Callbacks Props

PropTypeDescription
onTorchChange(isOn: boolean) => voidCalled when torch state changes
onScanStart() => voidCalled when scanning starts
onScanEnd() => voidCalled when scanning ends
onCooldownStart(duration: number) => voidCalled when cooldown period starts
onCooldownEnd() => voidCalled when cooldown period ends

Haptics Props

PropTypeDefaultDescription
enableHapticFeedbackbooleantrueEnable/disable haptic feedback
customHapticFeedback{ success?: NotificationFeedbackType; error?: NotificationFeedbackType }-Custom haptic feedback settings

Navigation Props

PropTypeDescription
onBackPress() => voidCustom back button handler
showBackButtonbooleanShow/hide back button
backButtonIconstringIcon name for back button

Custom Components Props

PropTypeDescription
renderCustomStatus(statusInfo: StatusInfo) => React.ReactNodeCustom status component renderer
renderCustomControls(controls: ControlsInfo) => React.ReactNodeCustom controls component renderer

Custom Styles Props

PropTypeDescription
containerStyleViewStyleCustom styles for container
statusBoxStyleViewStyleCustom styles for status box
statusTextStyleTextStyleCustom styles for status text

License

MIT

Keywords

react-native

FAQs

Package last updated on 16 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.