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

scanner-box

v1.0.6

Published

renders a bounding box around the qr code

Downloads

4

Readme

Installation

Install library from npm:

npm install scanner-box

Props

  1. cornerLength - set the length for the bounding corners
  2. color - set the colour of the bounding box
  3. borderSize - set the width of the box border
  4. radius - set the radius of the border
  5. shape - set the shape to either a square or 4 corners
  6. origin - set the x,y coordinates for the origin for the bounding box
  7. size - set the height and width for the bounding box
  8. borderOffSet - set an offset between the bounding box and the QR code

Usage

The following code uses expo-barcode-scanner for the barcode scanner

import * as React from "react";
import { StyleSheet, View, Text, Button, Dimensions } from "react-native";
import { useState, useEffect } from "react";
import QrCodeScanner from "./QrCodeScanner";
import { BarCodeScanner, BarCodeScannerResult } from "expo-barcode-scanner";

export default function App() {
  const [boundOrigin, setBoundOrigin] = useState({ x: 0, y: 0 });
  const [boundSize, setBoundSize] = useState({ x: 0, y: 0 });
  const [hasPermission, setHasPermission] = useState(false);
  const [scanned, setScanned] = useState(false);

  useEffect(() => {
    askForCameraPermission();
  });

  const askForCameraPermission = () => {
    (async () => {
      const { status } = await BarCodeScanner.requestPermissionsAsync();
      setHasPermission(status == "granted");
    })();
  };

  const handleBarCodeScanned = (scanningResult: BarCodeScannerResult) => {
    if (!scanned) {
      const { type, data, bounds } = scanningResult;

      if (bounds) {
        setBoundOrigin({ x: bounds.origin.x, y: bounds.origin.y });
        setBoundSize({ width: bounds.size.width, height: bounds.size.height });
      }

      setScanned(true);

      setTimeout(() => {
        setScanned(false);
      }, 1000);
    }
  };

  if (hasPermission === null) {
    return (
      <View style={styles.container}>
        <Text>Requesting for camera permission</Text>
      </View>
    );
  }

  if (hasPermission === false) {
    return (
      <View style={styles.container}>
        <Text style={{ margin: 10 }}>No access to camera</Text>
        <Button onPress={() => askForCameraPermission()} title="Test">
          Allow Camera
        </Button>
      </View>
    );
  }

  return (
    <View style={styles.container}>
      <BarCodeScanner
        barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}
        onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
        style={[StyleSheet.absoluteFill, styles.scan]}
      ></BarCodeScanner>

      <QrCodeScanner
        cornerLength={20}
        color="blue"
        borderSize={10}
        radius={30}
        shape="corners"
        origin={boundOrigin}
        size={boundSize}
        borderOffSet={5}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

The following scanner-box component usage renders this bounding box with blue corners

<QrCodeScanner
  cornerLength={30}
  color="blue"
  borderSize={5}
  radius={30}
  shape="corners"
  origin={boundOrigin}
  size={boundSize}
  borderOffSet={10}
/>

The The following scanner-box component usage renders this red bounding box

      <QrCodeScanner
        color="red"
        borderSize={5}
        radius={10}
        shape="square"
        origin={boundOrigin}
        size={boundSize}
      />
      

Others

  1. cornerLength only needed to be defined if user is going for a 'corners' bounding box, this is because cornerLength is use to set the legth and width of the corners and is not needed if the bounding box is a 'square'

  2. borderOffset is used so the borders rendered does not land directly on top of the qr code.