Commit b0d40d64 authored by cyqresig's avatar cyqresig
Browse files

finished first version

parent bf823673
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+12 −0
Original line number Diff line number Diff line
*.[aod]
*.DS_Store
.DS_Store
*Thumbs.db
*.iml
.gradle
.idea
node_modules
npm-debug.log
/android/build
/ios/**/*xcuserdata*
/ios/**/*xcshareddata*
 No newline at end of file

.npmignore

0 → 100644
+12 −0
Original line number Diff line number Diff line
*.[aod]
*.DS_Store
.DS_Store
*Thumbs.db
*.iml
.gradle
.idea
node_modules
npm-debug.log
/android/build
/ios/**/*xcuserdata*
/ios/**/*xcshareddata*
 No newline at end of file

Barcode.js

0 → 100644
+74 −0
Original line number Diff line number Diff line

import React, {
    PropTypes,
    Component,
} from 'react'
import {
    View,
    requireNativeComponent,
    NativeModules,
    AppState,
    Platform,
} from 'react-native'

const BarcodeManager = Platform.OS == 'ios' ? NativeModules.Barcode : NativeModules.CaptureModule;


export default class Barcode extends Component {

    static defaultProps = {
        barCodeTypes: Object.values(BarcodeManager.barCodeTypes),
        scannerRectWidth: 255,
        scannerRectHeight: 255,
        scannerRectTop: 0,
        scannerRectLeft: 0,
        scannerLineInterval: 3000,
        scannerRectCornerColor: `#09BB0D`,
    }

    static propTypes = {
        ...View.propTypes,
        onBarCodeRead: PropTypes.func.isRequired,
        barCodeTypes: PropTypes.array,
        scannerRectWidth: PropTypes.number,
        scannerRectHeight: PropTypes.number,
        scannerRectTop: PropTypes.number,
        scannerRectLeft: PropTypes.number,
        scannerLineInterval: PropTypes.number,
        scannerRectCornerColor: PropTypes.string,
    }

    render() {
        return (
            <NativeBarCode
                {...this.props}
            />
        )
    }

    componentDidMount() {
        AppState.addEventListener('change', this._handleAppStateChange);
    }
    componentWillUnmount() {
        AppState.removeEventListener('change', this._handleAppStateChange);
    }

    startScan() {
        BarcodeManager.startSession()
    }

    stopScan() {
        BarcodeManager.stopSession()
    }

    _handleAppStateChange = (currentAppState) => {
        if(currentAppState !== 'active' ) {
            this.stopScan()
        }
        else {
            this.startScan()
        }
    }
}

const NativeBarCode = requireNativeComponent(Platform.OS == 'ios' ? 'RCTBarcode' : 'CaptureView', Barcode)
+7 −1
Original line number Diff line number Diff line
# react-native-smart-barcode

A smart barcode scanner component for React Native app.
The library uses [https://github.com/zxing/zxing][1] to decode the barcodes for android.

[0]: https://github.com/cyqresig/ReactNativeComponentDemos
[1]: https://github.com/zxing/zxing
 No newline at end of file

android/build.gradle

0 → 100644
+26 −0
Original line number Diff line number Diff line
apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.facebook.react:react-native:+'
    compile 'com.google.zxing:core:3.2.1'
}
Loading