├── .expo-shared └── assets.json ├── .gitignore ├── App.js ├── app.json ├── assets ├── adaptive-icon.png ├── favicon.png ├── icon.png └── splash.png ├── babel.config.js ├── package.json └── yarn.lock /.expo-shared/assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true, 3 | "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true 4 | } 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | npm-debug.* 4 | *.jks 5 | *.p8 6 | *.p12 7 | *.key 8 | *.mobileprovision 9 | *.orig.* 10 | web-build/ 11 | 12 | # macOS 13 | .DS_Store 14 | -------------------------------------------------------------------------------- /App.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import { Text, View, StyleSheet, Button } from 'react-native'; 3 | import { BarCodeScanner } from 'expo-barcode-scanner'; 4 | 5 | export default function App() { 6 | const [hasPermission, setHasPermission] = useState(null); 7 | const [scanned, setScanned] = useState(false); 8 | const [text, setText] = useState('Not yet scanned') 9 | 10 | const askForCameraPermission = () => { 11 | (async () => { 12 | const { status } = await BarCodeScanner.requestPermissionsAsync(); 13 | setHasPermission(status === 'granted'); 14 | })() 15 | } 16 | 17 | // Request Camera Permission 18 | useEffect(() => { 19 | askForCameraPermission(); 20 | }, []); 21 | 22 | // What happens when we scan the bar code 23 | const handleBarCodeScanned = ({ type, data }) => { 24 | setScanned(true); 25 | setText(data) 26 | console.log('Type: ' + type + '\nData: ' + data) 27 | }; 28 | 29 | // Check permissions and return the screens 30 | if (hasPermission === null) { 31 | return ( 32 | 33 | Requesting for camera permission 34 | ) 35 | } 36 | if (hasPermission === false) { 37 | return ( 38 | 39 | No access to camera 40 |