Skip to content

Commit

Permalink
finished first version
Browse files Browse the repository at this point in the history
  • Loading branch information
cyqresig committed Oct 26, 2016
1 parent bf82367 commit b0d40d6
Show file tree
Hide file tree
Showing 65 changed files with 6,680 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.[aod]
*.DS_Store
.DS_Store
*Thumbs.db
*.iml
.gradle
.idea
node_modules
npm-debug.log
/android/build
/ios/**/*xcuserdata*
/ios/**/*xcshareddata*
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.[aod]
*.DS_Store
.DS_Store
*Thumbs.db
*.iml
.gradle
.idea
node_modules
npm-debug.log
/android/build
/ios/**/*xcuserdata*
/ios/**/*xcshareddata*
74 changes: 74 additions & 0 deletions Barcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

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)
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# react-native-smart-barcode
# 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
26 changes: 26 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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'
}
17 changes: 17 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/cyqresig/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnativecomponent.barcode">
</manifest>
Loading

0 comments on commit b0d40d6

Please sign in to comment.