forked from edwincarbajal/clementine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarcodeScreen.js
40 lines (35 loc) · 1.1 KB
/
BarcodeScreen.js
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
38
39
40
import React, { Component, useState, useEffect } from 'react';
import { Text, View, StyleSheet, Button, Dimensions } from 'react-native';
import { Camera } from 'expo-camera';
import { BarCodeScanner } from 'expo-barcode-scanner';
const { width: winWidth, height: winHeight } = Dimensions.get('window');
class BarcodeScreen extends Component {
state = {
hasPermission: null,
setHasPermission: null,
scanned: false,
setScanned: false
}
async componentDidMount() {
const barcode = await BarCodeScanner.requestPermissionsAsync();
const hasPermission = (barcode.status == 'granted')
this.setState({ hasPermission });
}
handleBarCodeScanned = ({ type, data }) => {
this.setState({setScanned: true})
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
};
render() {
return (
<BarCodeScanner
onBarCodeScanned = { this.state.scanned ? undefined : this.handleBarCodeScanned }
style = {{
height: winHeight,
width: winWidth,
}}
>
</BarCodeScanner>
);
}
}
export default BarcodeScreen;