GithubHelp home page GithubHelp logo

s-rajaraman / react-native-barcodescanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ideacreation/react-native-barcodescanner

0.0 1.0 0.0 127 KB

A barcode scanner component for react native

License: MIT License

JavaScript 11.20% Java 88.80%

react-native-barcodescanner's Introduction

react-native-barcodescanner

A barcode scanner component for React Native Android. For iOS you can use https://github.com/lwansbrough/react-native-camera. The library depends on https://github.com/dm77/barcodescanner and https://github.com/zxing/zxing.

Breaking change

React native 0.19 changed the ReactProps class which led to problems with updating native view properties (see facebook/react-native#5649). These errors are corrected in react-native-barcodescanner version 1.0.0. Use version 1.0.0 and larger for react native >=0.19 and for earlier react native versions use version 0.1.4.

Installation

npm i --save react-native-barcodescanner

Add it to your android project

  • In android/settings.gradle

    ...
    include ':ReactNativeBarcodescanner', ':app'
    project(':ReactNativeBarcodescanner').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-barcodescanner/android')
  • In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':ReactNativeBarcodescanner')
    }
  • register module (in MainActivity.java)

    Add the following import statement:

    import com.eguma.barcodescanner.BarcodeScanner;

    ...and then add BarcodeScanner to exported package list (MainActivity.java#getPackages):

    public class MainActivity extends ReactActivity {
        // (...)
    
        @Override
        protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new BarcodeScanner()
          );
        }
    }

Example

import React, {
  AppRegistry,
  Component,
} from 'react-native';
import BarcodeScanner from 'react-native-barcodescanner';

class BarcodeScannerExampleApp extends Component {
  constructor(props) {
    super(props);

    this.state = {
      torchMode: 'off',
      cameraType: 'back',
    };
  }

  barcodeReceived(e) {
    console.log('Barcode: ' + e.data);
    console.log('Type: ' + e.type);
  }

  render() {
    return (
      <BarcodeScanner
        onBarCodeRead={this.barcodeReceived}
        style={{ flex: 1 }}
        torchMode={this.state.torchMode}
        cameraType={this.state.cameraType}
      />
    );
  }
}

AppRegistry.registerComponent('BarcodeScannerExampleApp', () => BarcodeScannerExampleApp);

Properties

onBarCodeRead

Will call the specified method when a barcode is detected in the camera's view. Event contains data (barcode value) and type (barcode type). The following barcode types can be recognised:

BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417

torchMode

Values: on, off (default)

Use the torchMode property to specify the camera torch mode.

cameraType

Values: back (default), front

Use the cameraType property to specify the camera to use. If you specify the front camera, but the device has no front camera the back camera is used.

Viewfinder properties

The following properties can be used to style the viewfinder:

viewFinderBackgroundColor, viewFinderBorderColor, viewFinderBorderWidth, viewFinderBorderLength, viewFinderDrawLaser, viewFinderLaserColor

All color values are strings and must be specified as #AARRGGBB (alpha, red, green, blue). viewFinderBorderWidth and viewFinderBorderLength are numbers, viewFinderDrawLaser is either true or false (default).

For a better overview of the viewfinder see

Portrait.

react-native-barcodescanner's People

Contributors

andreyvital avatar andreaskeller avatar cpunion avatar skyfarliu avatar

Watchers

 avatar

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.