{ const [hasPermission, setHasPermission] = useState(false); const [scanned, setScanned] = useState(false); useEffect(() => { (async () => { const { status } = await BarCodeScanner.requestPermissionsAsync(); setHasPermission(status === "granted"); })(); }, []); const onBarCodeScanned = ({ type, data }: { type: string; data: string }) => { if (!scanned) { setScanned(true); alert(`Bar code with type ${type} and data ${data} has been scanned!`); } }; if (hasPermission === false) { return 카메라 권한을 풀어주세요!; } return ( {scanned && ( { const [hasPermission, setHasPermission] = useState(false); const [scanned, setScanned] = useState(false); useEffect(() => { (async () => { const { status } = await BarCodeScanner.requestPermissionsAsync(); setHasPermission(status === "granted"); })(); }, []); const onBarCodeScanned = ({ type, data }: { type: string; data: string }) => { if (!scanned) { setScanned(true); alert(`Bar code with type ${type} and data ${data} has been scanned!`); } }; if (hasPermission === false) { return 카메라 권한을 풀어주세요!; } return ( {scanned && ( { const [hasPermission, setHasPermission] = useState(false); const [scanned, setScanned] = useState(false); useEffect(() => { (async () => { const { status } = await BarCodeScanner.requestPermissionsAsync(); setHasPermission(status === "granted"); })(); }, []); const onBarCodeScanned = ({ type, data }: { type: string; data: string }) => { if (!scanned) { setScanned(true); alert(`Bar code with type ${type} and data ${data} has been scanned!`); } }; if (hasPermission === false) { return 카메라 권한을 풀어주세요!; } return ( {scanned && ( BarCodeScanner - Expo Documentation import React, { useState, useEffect } from "react"; import { Text, View, StyleSheet, Button } from "react-native"; import { BarCodeScanner } from "expo-barcode-scanner"; const QRScanner = () => { const [hasPermission, setHasPermission] = useState<boolean>(false); const [scanned, setScanned] = useState(false); useEffect(() => { (async () => { const { status } = await BarCodeScanner.requestPermissionsAsync(); setHasPermission(status === "granted"); })(); }, []); const onBarCodeScanned = ({ type, data }: { type: string; data: string }) => { if (!scanned) { setScanned(true); alert(`Bar code with type ${type} and data ${data} has been scanned!`); } }; if (hasPermission === false) { return <Text>카메라 권한을 풀어주세요!</Text>; } return ( <View style={styles.container}> <BarCodeScanner onBarCodeScanned={onBarCodeScanned} style={StyleSheet.absoluteFillObject} /> {scanned && ( <Button title={"Tap to Scan Again"} onPress={() => setScanned(false)} /> )} </View> ); }; export default QRScanner; const styles = StyleSheet.create({ container: { flex: 1, flexDirection: "column", justifyContent: "center", }, });
BarCodeScanner - Expo Documentation
import React, { useState, useEffect } from "react"; import { Text, View, StyleSheet, Button } from "react-native"; import { BarCodeScanner } from "expo-barcode-scanner"; const QRScanner = () => { const [hasPermission, setHasPermission] = useState<boolean>(false); const [scanned, setScanned] = useState(false); useEffect(() => { (async () => { const { status } = await BarCodeScanner.requestPermissionsAsync(); setHasPermission(status === "granted"); })(); }, []); const onBarCodeScanned = ({ type, data }: { type: string; data: string }) => { if (!scanned) { setScanned(true); alert(`Bar code with type ${type} and data ${data} has been scanned!`); } }; if (hasPermission === false) { return <Text>카메라 권한을 풀어주세요!</Text>; } return ( <View style={styles.container}> <BarCodeScanner onBarCodeScanned={onBarCodeScanned} style={StyleSheet.absoluteFillObject} /> {scanned && ( <Button title={"Tap to Scan Again"} onPress={() => setScanned(false)} /> )} </View> ); }; export default QRScanner; const styles = StyleSheet.create({ container: { flex: 1, flexDirection: "column", justifyContent: "center", }, });