Fix qr code scanner not working

This commit is contained in:
Arnaud Vergnet 2020-10-07 09:39:02 +02:00
parent 6e7b3d02cd
commit 25a12dad94

View file

@ -20,7 +20,7 @@
import * as React from 'react'; import * as React from 'react';
import {Linking, Platform, StyleSheet, View} from 'react-native'; import {Linking, Platform, StyleSheet, View} from 'react-native';
import {Button, Text} from 'react-native-paper'; import {Button, Text} from 'react-native-paper';
import {RNCamera} from 'react-native-camera'; import {BarCodeReadEvent, RNCamera} from 'react-native-camera';
import {BarcodeMask} from '@nartc/react-native-barcode-mask'; import {BarcodeMask} from '@nartc/react-native-barcode-mask';
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import {PERMISSIONS, request, RESULTS} from 'react-native-permissions'; import {PERMISSIONS, request, RESULTS} from 'react-native-permissions';
@ -107,7 +107,7 @@ class ScannerScreen extends React.Component<{}, StateType> {
<RNCamera <RNCamera
onBarCodeRead={state.scanned ? undefined : this.onCodeScanned} onBarCodeRead={state.scanned ? undefined : this.onCodeScanned}
type={RNCamera.Constants.Type.back} type={RNCamera.Constants.Type.back}
barCodeTypes={['qr']} barCodeTypes={[RNCamera.Constants.BarCodeType.qr]}
style={StyleSheet.absoluteFill} style={StyleSheet.absoluteFill}
captureAudio={false}> captureAudio={false}>
<BarcodeMask <BarcodeMask
@ -194,15 +194,14 @@ class ScannerScreen extends React.Component<{}, StateType> {
/** /**
* Opens scanned link if it is a valid app link or shows and error dialog * Opens scanned link if it is a valid app link or shows and error dialog
* *
* @param type The barcode type * @param event
* @param data The scanned value
*/ */
onCodeScanned = ({data}: {data: string}) => { onCodeScanned = (event: BarCodeReadEvent) => {
if (!URLHandler.isUrlValid(data)) { if (!URLHandler.isUrlValid(event.data)) {
this.showErrorDialog(); this.showErrorDialog();
} else { } else {
this.showOpeningDialog(); this.showOpeningDialog();
Linking.openURL(data); Linking.openURL(event.data);
} }
}; };