react-native:实现二维码的扫描
2016-10-09 本文已影响3376人
春林Zero
研究这个我一直研究了俩天,查资料,百度,头都大了:但是终于搞出来了:
1首先需要向工程中引入第三方的组件:react-native-barcodescanner
npm install react-native-barcodescanner --save
2.在你的android/settings.gradle下面加上:
include':react-native-barcodescanner',
project(':react-native-barcodescanner').projectDir=newFile(rootProject.projectDir,'../node_modules/react-native-barcodescanner/android')
3.在你的android/app/build.gradle加上这个依赖
dependencies{...
compile project(':react-native-barcodescanner')
}
4. 在你的MainApplication.java文件中加入:
开头:加上 import com.eguma.barcodescanner.BarcodeScannerPackage;
然后在这个: ListgetPackages() 方法中加上
newBarcodeScannerPackage()
5.上代码:


下面就是扫描成功调用的方法:


最后的大致显示效果:因为我改动了一些属性和组件;
