You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

80 lines
2.2 KiB

import React, { useState, useEffect } from "react";
import {
View,
Text,
TouchableOpacity,
Dimensions,
ImageBackground,
StatusBar
} from "react-native";
import { useNavigation } from "@react-navigation/native";
import tw from "tailwind-rn";
import { BarCodeScanner } from "expo-barcode-scanner";
import Colors from "../../../constants/Colors";
const { width, height } = Dimensions.get("window");
//assets
import laptopImage from "../assets/laptop.png";
export default function Scan({}) {
const navigation = useNavigation();
const [hasPermission, setHasPermission] = useState(null);
const [scanned, setScanned] = useState(false);
useEffect(() => {
(async () => {
const { status } = await BarCodeScanner.requestPermissionsAsync();
setHasPermission(status === "granted");
})();
}, []);
const handleBarCodeScanned = ({ type, data }) => {
setScanned(true);
navigation.navigate("QRContent", {data});
};
if (hasPermission === null) {
return <Text>Requesting for camera permission</Text>;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
return (
<ImageBackground
source={laptopImage}
resizeMode="cover"
style={[tw("w-full"), { height: height - StatusBar.currentHeight }]}
>
<View
style={tw(
"flex-1 flex flex-col justify-evenly items-center bg-gray-800 bg-opacity-80"
)}
>
<View style={{ width: height / 2.5, height: height / 2.5 }}>
<BarCodeScanner
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
style={{ width: "100%", height: "100%" }}
/>
</View>
{/* {scanned && ( */}
<TouchableOpacity
onPress={() => navigation.goBack()}
style={[
tw("py-2.5 rounded-full flex justify-center flex-row"),
{
width: height / 3.5,
borderWidth: 1,
borderColor: Colors.theme1.light.blue8,
},
]}
>
<Text style={{ color: "white", fontSize: width / 27 }}>بازگشت</Text>
</TouchableOpacity>
</View>
{/* )} */}
</ImageBackground>
);
}