npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-qrcode-scanner

v1.0.6

Published

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

Downloads

223

Readme

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 expo-qrcode-scanner
# or
yarn add expo-qrcode-scanner

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';
import {BarCodeScanner} from 'expo-barcode-scanner';

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

    useEffect(() => {
        (async () => {
            const { status } = await BarCodeScanner.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:

| Prop | Type | Default | Required | Description | |-----------------|----------|---------|----------|--------------------------------------------------------------| | style | Object | - | No | A custom style object to apply to the scanner component. | | onScanSuccess | Function | - | No | A callback function invoked when a QR code is successfully scanned. | | onScanFail | Function | - | No | A callback function invoked when a scan attempt fails. | | toleranceFactor | Number | 0.5 | No | A number representing the tolerance factor for QR code centering. | | minSize | Number | 140 | Yes | The minimum size for a QR code to be considered valid. | | maxSize | Number | 220 | Yes | The maximum size for a QR code to be considered valid. | | scanningInfinitely | boolean | false | Yes | Scan QR code continously |

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.