Я просто хочу сделать пример React Native Scan QR Code, поэтому я сначала запускаю эту команду: «npm install response-native-camera-kit --save».
Но я получил ошибку: 'requireNativeComponent: "CameraView" не был найден в UIManager "
Я использую Expo для запуска приложения на устройстве Android версии 5.1
Это мой компонент:
class QrCodeScreenextends Component {
constructor() {
super();
this.state = {
qrvalue: '',
opneScanner: false,
};
}
onOpenlink() {
//Function to open URL, If scanned
Linking.openURL(this.state.qrvalue);
//Linking used to open the URL in any browser that you have installed
}
onBarcodeScan(qrvalue) {
//called after te successful scanning of QRCode/Barcode
this.setState({ qrvalue: qrvalue });
this.setState({ opneScanner: false });
}
onOpneScanner() {
var that =this;
if(Platform.OS === 'android'){
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,{
'title': 'CameraExample App Camera Permission',
'message': 'CameraExample App needs access to your camera '
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
that.setState({ qrvalue: '' });
that.setState({ opneScanner: true });
} else {
alert("CAMERA permission denied");
}
} catch (err) {
alert("Camera permission err",err);
console.warn(err);
}
}
//Calling the camera permission function
requestCameraPermission();
}else{
that.setState({ qrvalue: '' });
that.setState({ opneScanner: true });
}
}
render() {
let displayModal;
if (!this.state.opneScanner) {
return (
<View style={styles.container}>
<Text style={styles.heading}>React Native QR Code Example</Text>
<Text style={styles.simpleText}>{this.state.qrvalue ? 'Scanned QR Code: '+this.state.qrvalue : ''}</Text>
{this.state.qrvalue.includes("http") ?
<TouchableHighlight
onPress={() => this.onOpenlink()}
style={styles.button}>
<Text style={{ color: '#FFFFFF', fontSize: 12 }}>Open Link</Text>
</TouchableHighlight>
: null
}
<TouchableHighlight
onPress={() => this.onOpneScanner()}
style={styles.button}>
<Text style={{ color: '#FFFFFF', fontSize: 12 }}>
Open QR Scanner
</Text>
</TouchableHighlight>
</View>
);
}
return (
<View style={{ flex: 1 }}>
<CameraKitCameraScreen
showFrame={false}
scanBarcode={true}
laserColor={'blue'}
frameColor={'yellow'}
colorForScannerFrame={'black'}
onReadCode={event =>
this.onBarcodeScan(event.nativeEvent.codeStringValue)
}
/>
</View>
);
}
}
export default QrCodeScreen;
Я что-то упустил!?