【发布时间】:2019-04-08 00:39:17
【问题描述】:
这是我的 App.js 文件
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { BarCodeScanner, Permissions } from 'expo';
export default class BarcodeScannerExample extends React.Component {
state = {
hasCameraPermission: null,
}
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({hasCameraPermission: status === 'granted'});
}
render() {
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <Text>Requesting for camera permission</Text>;
}
if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
}
return (
<View style={{width: 500 , height:500}}>
<BarCodeScanner
onBarCodeScanned={this.handleBarCodeScanned}
style={StyleSheet.absoluteFill}
/>
</View>
);
}
handleBarCodeScanned = ({ type, data }) => {
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
}
}
它只是提醒扫描代码的读取类型和数据。我想将此类型和数据写入文本框或文本输入。
道具
type (string) -- 相机朝向。使用 BarCodeScanner.Constants.Type 之一。使用 Type.front 或 Type.back。与 Camera.Constants.Type 相同。默认值:Type.back。
barCodeTypes (Array) -- 条码类型数组。用法:BarCodeScanner.Constants.BarCodeType。其中 codeType 是上面列出的之一。默认值:所有支持的条码类型。例如:barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}
onBarCodeScanned (function) -- 成功扫描条形码时调用的回调。回调提供了一个形状为 { type: BarCodeScanner.Constants.BarCodeType, data: string } 的对象,其中 type 是指被扫描的条码类型,data 是条码中编码的信息(在此如果是二维码,这通常是一个 URL)。
【问题讨论】:
标签: javascript node.js reactjs react-native react-redux