-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraView.js
More file actions
81 lines (72 loc) · 2.29 KB
/
CameraView.js
File metadata and controls
81 lines (72 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { useState, useEffect } from 'react';
import { Text, View, TouchableOpacity, StyleSheet } from 'react-native';
import { Camera } from 'expo-camera';
import {BarCodeScanner} from 'expo-barcode-scanner'
import { Ionicons } from '@expo/vector-icons';
import api from './api';
/**
*
* @param {{barcodeScanned: function, closeCameraView: function}} props
*/
export default function CameraView(props) {
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setHasPermission(status === 'granted');
})();
}, []);
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
const handleBarcodeScanned = async (e) => {
props.closeCameraView();
props.barcodeScanned(e.data);
}
return (
<View style={{ flex: 1 }}>
<Camera style={{ flex: 1 }} type={type} barCodeScannerSettings={{
barCodeTypes: [BarCodeScanner.Constants.BarCodeType.qr],
}} onBarCodeScanned={handleBarcodeScanned}>
<View
style={{
flex: 2,
backgroundColor: 'transparent',
flexDirection: 'row',
}}>
<TouchableOpacity
style={{...styles.cameraButton, marginRight: 15}}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}>
<Ionicons name="ios-reverse-camera" size={40} color="white" />
</TouchableOpacity>
<TouchableOpacity
style={styles.cameraButton}
onPress={() => props.closeCameraView() }>
<Ionicons name="ios-close" size={40} color="white" />
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
const styles = StyleSheet.create({
cameraButton: {
//backgroundColor: "rgba(255,255,255,0.25)",
//borderRadius: 5,
marginHorizontal: 15,
alignSelf: 'flex-end',
alignItems: 'center',
marginBottom: 10,
},
cameraButtonText: { fontSize: 18, color: 'white' }
})