最近要用到扫描,一开始用的react-native-camera,但是没有后置摄像头光源捕捉,不能做到和微信支付宝一样的手电筒逻辑,那就自己写一个
Install
yarn add react-native-scan-code-cn
或者
npm install react-native-scan-code-cn --save
Configuration
- android
- run
npx jetify
- In
android/app/src/main/AndroidManifest.xml
add:
<uses-permission android:name="android.permission.CAMERA" />
- ios
- run
npx pod-install
Usage
Make sure permissions are turned on before using
import { RNScanCode } from 'react-native-scan-code-cn'
<RNScanCode
onBarCodeRead={res => {
console.log('扫码结果 = ', res)
}}
onLightBright={light => {
console.log('当前的光源= ', light)
}}
>
{/* 其他UI */}
</RNScanCode>