/
CameraScreen.tsx
37 lines (34 loc) · 962 Bytes
/
CameraScreen.tsx
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
import { CameraPreview, requestCameraPermissionsAsync } from "expo-zxing";
import { useEffect, useState } from "react";
import { View, StyleSheet, Text } from "react-native";
export function CameraScreen() {
const [permissionGranted, setPermissionGranted] = useState(false);
useEffect(() => {
(async () => {
const { status } = await requestCameraPermissionsAsync();
setPermissionGranted(status === "granted");
})();
}, []);
return (
<View style={styles.container}>
{permissionGranted ? (
<CameraPreview
style={{ flex: 1 }}
onScanned={(event) => {
console.log(event.nativeEvent.result);
}}
/>
) : (
<Text style={{ color: "white" }}>
Camera permissions are required to use the QR Code scanner
</Text>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#000000",
},
});