import { CameraView, CameraType, useCameraPermissions } from "expo-camera";
import { useState } from "react";
import { Button, StyleSheet, Text, TouchableOpacity, View } from "react-native";
export default function QRScan() {
const [facing, setFacing] = useState<CameraType>("back");
const [permission, requestPermission] = useCameraPermissions();
if (!permission) {
// Camera permissions are still loading.
return <View />;
}
if (!permission.granted) {
// Camera permissions are not granted yet.
return (
<View style={styles.container}>
<Text style={styles.message}>
We need your permission to show the camera
</Text>
<Button onPress={requestPermission} title="grant permission" />
</View>
);
}
function toggleCameraFacing() {
setFacing((current) => (current === "back" ? "front" : "back"));
}
return (
<View style={styles.container}>
<CameraView style={styles.camera} facing={facing}>
<View style={styles.buttonContainer}>
<TouchableOpacity style={styles.button} onPress={toggleCameraFacing}>
<Text style={styles.text}>Flip Camera</Text>
</TouchableOpacity>
</View>
</CameraView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
},
message: {
textAlign: "center",
paddingBottom: 10,
},
camera: {
flex: 1,
},
buttonContainer: {
flex: 1,
flexDirection: "row",
backgroundColor: "transparent",
margin: 64,
},
button: {
flex: 1,
alignSelf: "flex-end",
alignItems: "center",
},
text: {
fontSize: 24,
fontWeight: "bold",
color: "white",
},
});
大家好!我在我的应用程序中使用
expo-camera
库来扫描二维码,但我面临的问题是应用程序扫描二维码并在 Expo Go
应用程序中正常工作,但当我构建像 .apk
这样的应用程序或开发构建时,它就会出现问题不起作用,我的屏幕变成全黑上面的代码来自官方expo docs
。
下面是我打开应用程序时的图像 在我的应用程序图像中使用expo-camera
我也遇到了同样的问题。您使用 EAS 来构建吗?