Skip to content
This repository was archived by the owner on Aug 25, 2019. It is now read-only.

underwindfall/RNScanCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-scanview-barcode

A barcode scanner component for React Native built from scratch.

This component has been created for a simple use of barcode scanner with some customizations.

Get Started

Supported OS versions

  • iOS : 10.0+
  • Android : SDK 23+

Installation

npm install --save react-native-scanview-barcode

Requirements

iOS

You need to add in your Info.plist the NSCameraUsageDescription.

Example

<key>NSCameraUsageDescription</key>
<string>Camera used for barcode scanner</string>
Android
<uses-permission android:name="android.permission.CAMERA"/>

Usage

You need to import ScanView from react-native-scanview-barcode then you can use it as <ScanView/> tag.

import { ScanView } from 'react-native-scanview-barcode';

Props

Native callbacks props

onScanCode

Function to be called when native code emit onScanCode, when barcode is detected.

onScanCode = (event) => {
    // Type
    console.log(event.type);
    
    // Data
    console.log(event.value);
};

Properties

codeTypes

All types are supported by default.

BarCode Type iOS Android
Barcode.code39
Barcode.code93
Barcode.code128
Barcode.dataMatrix
Barcode.ean8
Barcode.ean13
Barcode.itf14
Barcode.pdf417
Barcode.qr
Barcode.upce
Barcode.aztec
Barcode.code39Mod43
Barcode.interleaved2of5
Barcode.coda_bar
Barcode.upca
Barcode.rss14

camera

The back facing camera is used by default.

Values : ScanView.Const.Camera.back or ScanView.Const.Camera.front

flash

The flash is turned off by default.

Values : ScanView.Const.Flash.on or ScanView.Const.Flash.off

Example

import React, {Component} from 'react';
import {
    StyleSheet,
    View
} from 'react-native';
import { ScanView } from 'react-native-scanview-barcode';

type Props = {};
export default class App extends Component<Props> {

    constructor(props) {
        super(props);

        this.state = {
            codeString: ''
        }
    }

    onScanCode = (event) => {
        this.setState({codeString: event.value})
    };

    render() {
        let {Flash, Barcode} = ScanView.Const;

        return (
            <View style={styles.container}>
                <ScanView
                    onScanCode={this.onScanCode}
                    flash={Flash.on}
                    codeTypes={[Barcode.qr, Barcode.ean8, Barcode.code39]}
                />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        flexDirection: 'column',
        backgroundColor: '#ff4300',
    }
});

About

A ReactNative component to scan barcode.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published