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

vision-camera-simple-scanner

v2.1.5

Published

High performance barcode scanner for React Native using VisionCamera, forked from vision-camera-barcode-scanner

Downloads

124

Readme

vision-camera-simple-scanner

Features

High performance barcode scanner for React Native using VisionCamera.

  • Modern and future-proof: Built on react-native-vision-camera@4 with minimal native dependencies for each platforms to minimize future build-failure risk.

  • Minimal footprint: Leverages Google's MLKit BarcodeScanner on Android and Apple's Vision VNDetectBarcodesRequest.

  • Powerful & Performant: The implementation has been tailored for advanced use cases where performance is critical. Scanning barcodes is butter smooth at 30fps, and you can customize the detection speed loop (detection fps). Template functionality can provide easy access to high-refresh rate video streams, including 60fps video input on some Android/iOS devices.

  • Hooks based: Exposes a single, easy-to-use hook useBarcodeScanner

Demo

demo

A working project can be found at vision-camera-simple-scanner/example.

Install

[!WARNING] The project is currently trying to closely track react-native-vision-camera@4, The latest 2.x releases are made to work with the latest react-native-vision-camera@4 (currently 4.0.1)

The example application provides a patch file to work around most of the preview-related orientation issues in vision-camera. Since barcode scanning doesn't involve saving photos or video, this patch is only tested to work with previewing photo/video. Use at your own risk.

If you're using JSC instead of hermes, you will need an additional patch to react-native-worklets-core. See the patch file in the example project. This patch is not required when using hermes, but as far as I can tell it doesn't cause any issues.

npm install vision-camera-simple-scanner
# or
yarn add vision-camera-simple-scanner
# or
pnpm add vision-camera-simple-scanner

Dependencies

This package relies on:

You must add them as dependencies to your project:

npm install react-native-vision-camera react-native-worklets-core
# or
yarn add react-native-vision-camera react-native-worklets-core
# or
pnpm add react-native-vision-camera react-native-worklets-core

Then you must follow their respective installation instructions:

Quickstart

The following quickstart example will dump any discovered codes to the console. For a more in-depth example, which renders the result of the scan on-screen, see the example project.

import type { FunctionComponent } from 'react';
import { StyleSheet, View } from 'react-native';
import {
  Camera,
  useCameraDevices,
  useCameraFormat,
} from 'react-native-vision-camera';
import { useBarcodeScanner, Templates } from 'vision-camera-simple-scanner';

export const App: FunctionComponent = () => {
  // @NOTE you must properly ask for camera permissions first!
  // You should use `PermissionsAndroid` for Android and `Camera.requestCameraPermission()` on iOS.

  // Here's the functionality of this library; configure it for your use case,
  // pass the props to react-native-vision-camera, and you're good to go!
  const { props: cameraProps } = useBarcodeScanner({
    fps: 30,
    barcodeTypes: ['qr', 'ean-13'], // optional
    onBarcodeScanned: (barcodes) => {
      'worklet';
      // this will get called every frame that one or more barcodes are detected
      console.log(
        `Scanned ${barcodes.length} codes with values=${JSON.stringify(
          barcodes.map(({ value }) => value),
        )} !`,
      );
    },
  });

  // Typical react-native-vision-camera setup
  const devices = useCameraDevices();
  const device = devices.find(({ position }) => position === 'back');
  if (!device) {
    return null;
  }

  return (
    <View style={{ flex: 1 }}>
      <Camera
        style={StyleSheet.absoluteFill}
        device={device}
        isActive
        {...cameraProps}
      />
    </View>
  );
};

Credits

Heavily based on code from

Authors

License

The MIT License

Copyright (c) 2024 Max Gurela <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.