我想知道如何保存在React Native中使用的qrcode扫描器的值,并将该值自动显示到另一个页面。因此,一旦qrcode被扫描,它将被自动重定向到另一个页面。
可以使用React导航吗?
发布于 2019-02-14 18:44:26
您可以使用react-native-qrcode-scanner库来创建这种类型的功能。
react-native-camera是此包的依赖项,您需要将其添加到项目中。要安装,请运行以下命令:
npm install react-native-camera --save
react-native link react-native-camera之后,通过以下命令安装并链接react-native-qrcode-scanner:
npm install react-native-qrcode-scanner --save
react-native link react-native-qrcode-scanner
react-native link react-native-permissions以下是QR扫描仪的示例代码
import React, {Component} from 'react';
import {StyleSheet, Text, View, AppRegistry, TouchableOpacity, Linking} from 'react-native';
import QRCodeScanner from 'react-native-qrcode-scanner';
export default class App extends Component {
onSuccess(e) {
//here you can do whatever you want to do on a successful scan
alert(e.data);
}
render() {
return (
<View style={{flex:1, justifyContent: 'center',}}>
<QRCodeScanner
showMarker={true}
onRead={this.onSuccess.bind(this)}
/>
</View>
);
}
}如果您在安装过程中遇到任何困难,可以访问以下链接:https://www.npmjs.com/package/react-native-qrcode-scanner
https://stackoverflow.com/questions/54687470
复制相似问题