Giter VIP home page Giter VIP logo

react-barcode-reader's Introduction

npm version

Introduction

A React component for reading barcode and QR codes from devices that are represent as keyboard to the system.

Demo

kybarg.github.io/react-barcode-reader/

Install

npm install --save react-barcode-reader

Example

import React, { Component } from 'react'
import BarcodeReader from 'react-barcode-reader'

class Test extends Component {
  constructor(props){
    super(props)
    this.state = {
      result: 'No result',
    }

    this.handleScan = this.handleScan.bind(this)
  }
  handleScan(data){
    this.setState({
      result: data,
    })
  }
  handleError(err){
    console.error(err)
  }
  render(){

    return(
      <div>
        <BarcodeReader
          onError={this.handleError}
          onScan={this.handleScan}
          />
        <p>{this.state.result}</p>
      </div>
    )
  }
}

Props

Prop Type Default Value Description
onScan func Callback after detection of a successfull scanning (scanned string in parameter)
onError func Callback after detection of a unsuccessfull scanning (scanned string in parameter)
HonReceive func Callback after receiving and processing a char (scanned char in parameter)
onKeyDetect func Callback after detecting a keyDown (key char in parameter) - in contrast to onReceive, this fires for non-character keys like tab, arrows, etc. too!
timeBeforeScanTest number 100 Wait duration (ms) after keypress event to check if scanning is finished
avgTimeByChar number 30 Average time (ms) between 2 chars. Used to do difference between keyboard typing and scanning
minLength number 6 Minimum length for a scanning
endChar [number] [9, 13] Chars to remove and means end of scanning
startChar [number] [] Chars to remove and means start of scanning
scanButtonKeyCode number Key code of the scanner hardware button (if the scanner button a acts as a key itself)
scanButtonLongPressThreshold number 3 How many times the hardware button should issue a pressed event before a barcode is read to detect a longpress
onScanButtonLongPressed func Callback after detection of a successfull scan while the scan button was pressed and held down
stopPropagation bool false Stop immediate propagation on keypress event
preventDefault bool false Prevent default action on keypress event
testCode string Test string for simulating

Dev

Install dependencies

npm install

Build

npm run build

Demo

npm run storybook

Test

npm test

Linting

npm run lint

License

The MIT License (MIT)

Copyright (c) 2017 Thomas Billiet

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.

react-barcode-reader's People

Contributors

dependabot[bot] avatar kybarg avatar lol123a10-bebug avatar ramizqazi avatar tiendn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-barcode-reader's Issues

Different barcode reader mode

Hi, i have 2 barcode reader, one of them scan the barcode and send the input as a string into the react app, but the other scan the barcode and send the input as a single key event. How should i handle this? i notice this library has onScan and onReceive props, with onReceive i can get the key event, but i'm still confused on how to detect the barcode mode. because sometimes both onScan and onReceive run at the same scan. Is there any workaround for this?

BarcodeReader not rendering

I'm having problem showing the camera with the example code, does it need something else, bellow the code. also the demo is no working...

import React, {Component} from 'react'
import BarcodeReader from 'react-barcode-reader'

class Barcode extends Component {
  constructor(props) {
    super(props);
    this.state = {
      result: 'No result',
    };
    this.handleScan = this.handleScan.bind(this);
  }

  handleScan(data) {
    this.setState({
      result: data,
    })
  }

  handleError(err) {
    console.error(err)
  }

  render() {
    return (
      <div>
        <BarcodeReader
          onError={this.handleError}
          onScan={this.handleScan}
        />
        <p>{this.state.result}</p>
      </div>
    )
  }
}

export default Barcode;

issue with babel

Hello,

There is an issue with babel
Capture d’écran du 2020-04-06 21-26-01

I already did indicated steps in this error message but it's still not working.

I even added .env file and in the project i have this error:

Capture d’écran du 2020-04-06 21-28-23

Thanks for help !

Keyboard or keypress event is triggering the onScan method

I want to prevent the onScan method call of any kind of keypress event from keyboard because it is altering my barcode scan input data.

I tried "preventDefault" prop but did not get any success, please suggest me something on it.

Always Active

Hello, I would like the component to always be active, for example, it works if I am not in an input, but if I am active in a form, does it stop working, any suggestions?

(..me tarzan)

Not rendering

The component is not rendering anything. No errors in console either.

Also, Storybook is blank.

edit: This doesn't seem to even try to open the camera. No permissions get asked.

Module for TypeScript

module declaration for react-barcode-reader is missing. To be able to use in TYPESCRIPT

Babel-loader pls move dependency to devdependency

Hi,

tl;dr can you pls move babel-loader from dependency to devDependency? Thank you!

When Im trying to run my project with you library and react-scripts 3.4.0 (we dont use 3.4.1 because there is a bug not fixed for test coverage), we are getting this error:

`To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  1. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
    This may help because npm has known issues with package hoisting which may get resolved in future versions.

  2. Check if /home/mkubacki/workspace/team-cat/backstage/packages/app/node_modules/babel-loader is outside your project directory.
    For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls babel-loader in your project folder.
    This will tell you which other package (apart from the expected react-scripts) installed babel-loader.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
`

I tried this steps but didnt work. If we move babel to devdependency, it will work as far as I know. I would love to get your support.

Gives Security Error on Hosting

When I am deploying the app on heroku and Calling my React Client URL this show a Security Error:
Blocked a frame with origin "https://2f5bd16b.ngrok.io" from accessing a cross-origin frame.

This Error Occurs in SHOPIFY

`←→1 of 2 errors on the page
SecurityError: Blocked a frame with origin "https://662bdced.ngrok.io" from accessing a cross-origin frame.
▶ 18 stack frames were collapsed.
Module../src/index.js
src/index.js:7
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |

7 | ReactDOM.render(, document.getElementById('root'));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
View compiled
webpack_require
/home/osama/Documents/dev/scanandship/scan-and-ship/webpack/bootstrap:785
782 | };
783 |
784 | // Execute the module function
785 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 786 |
787 | // Flag the module as loaded
788 | module.l = true;
View compiled
fn
/home/osama/Documents/dev/scanandship/scan-and-ship/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
150 | return webpack_require(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
0
https://662bdced.ngrok.io/static/js/main.chunk.js:2545:18
webpack_require
/home/osama/Documents/dev/scanandship/scan-and-ship/webpack/bootstrap:785
782 | };
783 |
784 | // Execute the module function
785 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 786 |
787 | // Flag the module as loaded
788 | module.l = true;
View compiled
checkDeferredModules
/home/osama/Documents/dev/scanandship/scan-and-ship/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
45 | result = webpack_require(webpack_require.s = deferredModule[0]);
| ^ 46 | }
47 | }
48 |
View compiled
Array.webpackJsonpCallback [as push]
/home/osama/Documents/dev/scanandship/scan-and-ship/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
32 | return checkDeferredModules();
| ^ 33 | };
34 | function checkDeferredModules() {
35 | var result;
View compiled
(anonymous function)
https://662bdced.ngrok.io/static/js/main.chunk.js:1:79`

Does it work with mobile camera as reading barcode image ?

i tried it this library to scan barcode from camera , but it seems not working, not sure does it work with camera or not with mobile phone or it needs external reader/scanner device to provide data. please help to answer does this library work with mobile phone camera as barcode read or not

Example of barcode scanner model

Hi. can you tell me what model would behave as a keyboard for this lib to work with the reader? I can't find any info on that.

Vite.js incompatibility

Hello,

I can not use your package with Vite.js since it expects package.json's "module" field to be a path to an es module.

It should be "type": "commonjs" instead I think.

[vite] Pre-transform error: Failed to resolve entry for package "react-barcode-reader". The package may have incorrect main/module/exports specified in its package.json.

This link could be usefull.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.