2020-08-29 03:40:55 +00:00
|
|
|
import {BarCodeScanner} from 'expo-barcode-scanner';
|
2020-09-01 19:55:23 +00:00
|
|
|
import React, {ReactElement, useState} from 'react';
|
|
|
|
import {View, Text} from 'react-native';
|
2020-09-01 02:12:32 +00:00
|
|
|
import {Button} from 'react-native-paper';
|
2020-08-29 03:40:55 +00:00
|
|
|
import {ButtonProps, ScannerProps} from '../models/ElementProps';
|
2020-09-01 02:12:32 +00:00
|
|
|
import {colors, styles} from './Styles';
|
2020-08-29 03:40:55 +00:00
|
|
|
|
2020-09-01 19:55:23 +00:00
|
|
|
declare type CameraType = number | 'front' | 'back' | undefined;
|
|
|
|
|
2020-08-29 03:40:55 +00:00
|
|
|
export const Scanner = (props: ScannerProps): ReactElement => {
|
2020-09-01 19:55:23 +00:00
|
|
|
const [componentKey, setComponentKey] = useState<number>(0);
|
|
|
|
const [cameraType, setCameraType] = useState<CameraType>('back');
|
|
|
|
|
|
|
|
const _toggleCameraType = () => {
|
|
|
|
setCameraType(cameraType === 'front' ? 'back' : 'front');
|
|
|
|
setComponentKey(componentKey + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ScanCamera = (): ReactElement => {
|
|
|
|
return <View style={styles.container}>
|
|
|
|
<View style={styles.container}>
|
|
|
|
<BarCodeScanner
|
|
|
|
type={cameraType}
|
|
|
|
onBarCodeScanned={props.onScanned}
|
|
|
|
style={styles.fullScreen}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.centerMiddle}>
|
|
|
|
<View style={styles.captureBox} />
|
|
|
|
</View>
|
|
|
|
<Text style={styles.subtitle}>
|
|
|
|
Hold your ID card up, with the barcode facing the camera. Keep the card in the green box.
|
|
|
|
</Text>
|
|
|
|
<View style={styles.centerMiddle}>
|
|
|
|
<Button
|
|
|
|
mode="contained"
|
|
|
|
color={colors.primary}
|
|
|
|
icon="camera-switch"
|
|
|
|
onPress={_toggleCameraType}
|
|
|
|
style={{marginVertical: 10}}
|
|
|
|
>Switch Camera</Button>
|
|
|
|
<Button
|
|
|
|
mode="text"
|
|
|
|
color={colors.primary}
|
|
|
|
icon="cancel"
|
|
|
|
onPress={props.onCancel}
|
|
|
|
style={styles.btnWhite}
|
|
|
|
>Cancel</Button>
|
|
|
|
</View>
|
|
|
|
</View>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <ScanCamera key={componentKey} />;
|
2020-08-29 03:40:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const ScanButton = (props: ButtonProps): ReactElement => {
|
|
|
|
return <Button
|
2020-09-01 02:12:32 +00:00
|
|
|
icon="camera"
|
|
|
|
mode="contained"
|
|
|
|
color={colors.accent}
|
2020-08-29 03:40:55 +00:00
|
|
|
onPress={props.onClicked}
|
2020-09-01 02:12:32 +00:00
|
|
|
style={styles.btnLg}
|
|
|
|
labelStyle={styles.btnLg}
|
|
|
|
>Scan Barcode</Button>;
|
2020-08-29 03:40:55 +00:00
|
|
|
};
|