FIX: Permission fixes.

This commit is contained in:
Marcos Rodriguez 2019-09-21 19:39:42 -04:00
parent 3c82b0ec72
commit e61cdb540a

View File

@ -13,18 +13,13 @@ export default class ScanQRCode extends React.Component {
header: null, header: null,
}; };
state = { cameraRef = null;
isLoading: false,
};
onBarCodeRead = ret => { onBarCodeRead = ret => {
if (this.state.isLoading) return; if (RNCamera.Constants.CameraStatus === RNCamera.Constants.CameraStatus.READY) this.cameraRef.pausePreview();
this.cameraRef.pausePreview(); const onBarScannedProp = this.props.navigation.getParam('onBarScanned');
this.setState({ isLoading: true }, () => { this.props.navigation.goBack();
const onBarScannedProp = this.props.navigation.getParam('onBarScanned'); onBarScannedProp(ret.data);
this.props.navigation.goBack();
onBarScannedProp(ret.data);
});
}; // end }; // end
render() { render() {
@ -70,7 +65,7 @@ export default class ScanQRCode extends React.Component {
bottom: 48, bottom: 48,
}} }}
onPress={() => { onPress={() => {
this.cameraRef.pausePreview(); if (RNCamera.Constants.CameraStatus === RNCamera.Constants.CameraStatus.READY) this.cameraRef.pausePreview();
ImagePicker.launchImageLibrary( ImagePicker.launchImageLibrary(
{ {
title: null, title: null,
@ -78,15 +73,19 @@ export default class ScanQRCode extends React.Component {
takePhotoButtonTitle: null, takePhotoButtonTitle: null,
}, },
response => { response => {
const uri = response.uri.toString().replace('file://', ''); if (response.uri) {
LocalQRCode.decode(uri, (error, result) => { const uri = response.uri.toString().replace('file://', '');
if (!error) { LocalQRCode.decode(uri, (error, result) => {
this.onBarCodeRead({ data: result }); if (!error) {
} else { this.onBarCodeRead({ data: result });
this.cameraRef.resumePreview(); } else {
alert('The selected image does not contain a QR Code.'); if (RNCamera.Constants.CameraStatus === RNCamera.Constants.CameraStatus.READY) this.cameraRef.resumePreview();
} alert('The selected image does not contain a QR Code.');
}); }
});
} else {
if (RNCamera.Constants.CameraStatus === RNCamera.Constants.CameraStatus.READY) this.cameraRef.resumePreview();
}
}, },
); );
}} }}