@1ziton/react-native-scancode 中文文档教程

发布于 5年前 浏览 27 项目主页 更新于 3年前

react-native-scancode

Getting started

$ npm install react-native-scancode --save

Mostly automatic installation

$ react-native link react-native-scancode

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.xiaomo.ScancodePackage; to the imports at the top of the file
  • Add new ScancodePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
   include ':react-native-scancode'
   project(':react-native-scancode').projectDir = new File(rootProject.projectDir,     '../node_modules/react-native-scancode/android')
  1. Insert the following lines inside the dependencies block in android/app/build.gradle:
   compile project(':react-native-scancode')

Usage

// TODO: What to do with the module?
import { NativeModules } from "react-native";
const { WmsScanCode } = NativeModules;

//设置扫码选项(当PDA设备能通过广播进行设置的时候可用)
let obj={};
let list=[];
obj['key']='barcode_send_mode';
obj['value']='BROADCAST';
list.push(obj);
WmsScanCode.setBroadcastSetting('com.android.scanner.service_settings',list);

//广播和接收字段(接收的广播名和接收的字段名)
WmsScanCode.getCode('android.intent.action.SCANRESULT','value');

//接收扫描结果
import { DeviceEventEmitter } from "react-native";
componentWillMount() {
  if (this.searchListener) {
    this.searchListener.remove();
  }
  this.searchListener = DeviceEventEmitter.addListener("scannerCodeShow",e => {
    console.log(e.code)
    }
  )
}
//退出页面移除监听
componentWillUnmount() {
  if (this.searchListener) {
    DeviceEventEmitter.removeListener("scannerCodeShow");
    this.searchListener.remove();
    this.searchListener = null;
  }
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文