Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expo-qrcode-scanner

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-qrcode-scanner

QR Code Scanner component for Expo apps with scan limit in center

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
94
increased by40.3%
Maintainers
1
Weekly downloads
 
Created
Source

QR Code Scanner Module for Expo 📸

This module provides a React Native component for scanning QR codes, specifically designed for use with Expo. It offers a customizable QR code scanning experience, allowing users to specify various parameters and styles.

Installation 📦

To use this module in your Expo project, install it via npm or yarn:

npm install your-module-name
# or
yarn add your-module-name

Usage 🚀

First, import the QRCodeScanner into your React Native component:

import QRCodeScanner from 'expo-qrcode-scanner';

Then, you can use the QRCodeScanner in your component's render method:

import React from 'react';
import { View } from 'react-native';
import QRCodeScanner from 'expo-qrcode-scanner';

const YourComponent = () => {
    const handleScanSuccess = (scanData) => {
        // Handle successful scan
        console.log('QR Code Scanned:', scanData);
    };

    const handleScanFail = () => {
        // Handle scan failure
        console.log('Failed to scan QR Code.');
    };

    return (
        <View style={{ flex: 1 }}>
            <QRCodeScanner
                onScanSuccess={handleScanSuccess}
                onScanFail={handleScanFail}
                // Additional props
            />
        </View>
    );
};

export default YourComponent;

Requesting Camera Permissions 🎥

Before scanning QR codes, your app must ask the user for permission to access the camera. You can do this using Expo's Permissions API:

import { useState, useEffect } from 'react';
import { Text, View } from 'react-native';
import QRCodeScanner from 'expo-qrcode-scanner';

const CameraScreen = () => {
    const [hasPermission, setHasPermission] = useState(null);

    useEffect(() => {
        (async () => {
            const { status } = await Camera.requestPermissionsAsync();
            setHasPermission(status === 'granted');
        })();
    }, []);

    if (hasPermission === null) {
        return <View />;
    }
    if (hasPermission === false) {
        return <Text>No access to camera</Text>;
    }

    return (
        <View style={{ flex: 1 }}>
            <QRCodeScanner
                onScanSuccess={(scanData) => console.log(scanData)}
                onScanFail={() => console.log('Failed to scan')}
                // Additional props
            />
        </View>
    );
};

Props 📐

The QRCodeScannerComponent accepts the following props:

PropTypeDefaultRequiredDescription
styleObject-NoA custom style object to apply to the scanner component.
onScanSuccessFunction-NoA callback function invoked when a QR code is successfully scanned.
onScanFailFunction-NoA callback function invoked when a scan attempt fails.
toleranceFactorNumber0.5NoA number representing the tolerance factor for QR code centering.
minSizeNumber-YesThe minimum size for a QR code to be considered valid.
maxSizeNumber-YesThe maximum size for a QR code to be considered valid.

Contributing 🤝

Contributions to this module are welcome. Please ensure that your code adheres to the existing style and functionality.

License 📄

This module is licensed under the MIT License.

Keywords

FAQs

Package last updated on 08 Jan 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc